CancellableConnection () { return new NewBaseRepositoryImpl.HttpTestConnection(new HttpGet()) { @Override protected void test() throws Exception { // Strangely, Redmine doesn't return 401 or 403 error codes, if client sent wrong credentials, and instead // merely returns empty array of issues with status code of 200. This means that we should attempt to fetch // something more specific than issues to test proper configuration, e.g. current user information at // /users/current.json. Unfortunately this endpoint may be unavailable on some old servers (see IDEA-122845) // and in this case we have to come back to requesting issues in this case to test anything at all. URIBuilder uriBuilder = createUriBuilderWithApiKey("users", "current.json"); myCurrentRequest.setURI(uriBuilder.build()); HttpClient client = getHttpClient(); HttpResponse httpResponse = client.execute(myCurrentRequest); StatusLine statusLine = httpResponse.getStatusLine(); if (statusLine != null && statusLine.getStatusCode() == HttpStatus.SC_NOT_FOUND) { // Check that projects can be downloaded via given URL and the latter is not project-specific myCurrentRequest = new HttpGet(getProjectsUrl(0, 1)); statusLine = client.execute(myCurrentRequest).getStatusLine(); if (statusLine != null && statusLine.getStatusCode() == HttpStatus.SC_OK) { myCurrentRequest = new HttpGet(getIssuesUrl(0, 1, true)); statusLine = client.execute(myCurrentRequest).getStatusLine(); } } if (statusLine != null && statusLine.getStatusCode() != HttpStatus.SC_OK) { throw RequestFailedException.forStatusCode(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } } }; }