Skip to content

Commit

Permalink
add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MCMicS committed Oct 3, 2023
1 parent 7bca9af commit 25589fd
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.intellij.util.net.IdeHttpClientHelpers;
import com.intellij.util.net.ssl.CertificateManager;
import org.apache.commons.lang.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
Expand Down Expand Up @@ -127,6 +128,7 @@ public String connect(URL jenkinsUrl) {
runMethod(urlStr, data, responseCollector);

if (isRedirection(responseCollector.statusCode)) {
LOG.trace(String.format("Handle redirect to: %s", responseCollector.data));
runMethod(responseCollector.data, data, responseCollector);
}

Expand Down Expand Up @@ -178,10 +180,12 @@ protected final void addAuthenticationPreemptive(HttpHost host, UsernamePassword

protected final HttpHost getLastRedirectionHost(HttpHost host) {
final var httpHead = new HttpHead(host.toURI());
LOG.trace(String.format("Sending HEAD request to: %s", host.toURI()));
try {
final var context = getHttpClientContext();
final var response = executeHttp(httpHead);
final var statusCode = response.getStatusLine().getStatusCode();
LOG.trace(String.format("HEAD response for [%s] with status [%s]", host.toURI(), statusCode));

var targetHost = host;
if (HttpURLConnection.HTTP_OK == statusCode) {
Expand Down Expand Up @@ -211,11 +215,14 @@ private void runMethod(String url, @NotNull Collection<RequestData> data, Respon
final var post = createPost(url, data);

try {
LOG.trace(String.format("Executing POST to: %s", post.getURI()));
final var response = executeHttp(post);
final var statusCode = response.getStatusLine().getStatusCode();
final var responseBody = EntityUtils.toString(response.getEntity());
final var errorHeader = response.getFirstHeader("X-Error");
checkResponse(statusCode, responseBody);
LOG.trace(String.format("POST response for [%s] with status [%s]: %s", post.getURI(), statusCode,
responseBody));

if (HttpURLConnection.HTTP_OK == statusCode) {
responseCollector.collect(statusCode, responseBody);
Expand All @@ -227,7 +234,9 @@ private void runMethod(String url, @NotNull Collection<RequestData> data, Respon
}
// if redirect handling not works or we still get a redirect header we handle it manually
if (isRedirection(statusCode)) {
responseCollector.collect(statusCode, response.getLastHeader("Location").getValue());
final Header location = response.getLastHeader("Location");
LOG.trace(String.format("Handle redirect manually to: %s", location));
responseCollector.collect(statusCode, location.getValue());
}
} catch (UnknownHostException uhEx) {
throw new ConfigurationException(String.format("Unknown server: %s", uhEx.getMessage()), uhEx);
Expand Down

0 comments on commit 25589fd

Please sign in to comment.