Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging http responses #376

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


/**
Expand All @@ -27,6 +30,7 @@ public class HttpConnection {
private HttpClient httpClient;
private int connectionRetries;
private int connectionTimeout;
Logger logger = LogManager.getLogger(getClass().getName());

/**
* Constructor with explicit indication of retries and timeout
Expand Down Expand Up @@ -69,7 +73,11 @@ public String getURLContentAsString(String url, String headerName, String header
if (get.getStatusCode() >= STATUS_OK_START && get.getStatusCode() <= STATUS_OK_END) {
return get.getResponseBodyAsString();
} else {
return null;
if(logger.isWarnEnabled()) {
logger.warn("Received Status Code: {}, and Response Body: {}, for the url: {}",
get.getStatusCode(), get.getResponseBodyAsString(), url);
}
return null;
}
}

Expand All @@ -88,7 +96,11 @@ public InputStream getURLContentAsStream(String url) throws IOException {
if (get.getStatusCode() >= STATUS_OK_START && get.getStatusCode() <= STATUS_OK_END) {
return get.getResponseBodyAsStream();
} else {
return null;
if(logger.isWarnEnabled()) {
logger.warn("Received Status Code: {}, and Response Body: {}, for the url: {}",
get.getStatusCode(), get.getResponseBodyAsString(), url);
}
return null;
}
}

Expand All @@ -111,7 +123,11 @@ public InputStream postRequest(String url, String body) throws IOException {
if (post.getStatusCode() >= STATUS_OK_START && post.getStatusCode() <= STATUS_OK_END) {
return post.getResponseBodyAsStream();
} else {
return null;
if(logger.isWarnEnabled()) {
logger.warn("Received Status Code: {}, and Response Body: {}, for the url: {}",
post.getStatusCode(), post.getResponseBodyAsString(), url);
}
return null;
}
}

Expand Down
Loading