diff --git a/httpclient/pom.xml b/httpclient/pom.xml index f98735d876..8047d56cd4 100644 --- a/httpclient/pom.xml +++ b/httpclient/pom.xml @@ -30,7 +30,32 @@ httpclient ${httpclient.version} + + + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + + org.slf4j + jcl-over-slf4j + ${org.slf4j.version} + + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + diff --git a/httpclient/src/main/resources/logback.xml b/httpclient/src/main/resources/logback.xml index 1146dade63..aa1e9cd522 100644 --- a/httpclient/src/main/resources/logback.xml +++ b/httpclient/src/main/resources/logback.xml @@ -1,20 +1,17 @@ - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - + + - - - - - - + + + \ No newline at end of file diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientLiveTest.java b/httpclient/src/test/java/org/baeldung/httpclient/HttpClientLiveTest.java index cebc3a8b26..1088bf3c4a 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientLiveTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/HttpClientLiveTest.java @@ -22,7 +22,10 @@ import org.apache.http.entity.ContentType; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.BasicHttpClientConnectionManager; +import org.apache.http.params.CoreProtocolPNames; +import org.apache.http.params.HttpProtocolParams; import org.apache.http.util.EntityUtils; import org.junit.After; import org.junit.Before; @@ -129,16 +132,30 @@ public class HttpClientLiveTest { // tests - headers + @SuppressWarnings("deprecation") + @Test + public final void givenDeprecatedApi_whenClientUsesCustomUserAgent_thenCorrect() throws ClientProtocolException, IOException { + final DefaultHttpClient client = new DefaultHttpClient(); + client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 Firefox/26.0"); + HttpProtocolParams.setUserAgent(client.getParams(), "Mozilla/5.0 Firefox/26.0"); + + final HttpGet request = new HttpGet(SAMPLE_URL); + response = client.execute(request); + } + @SuppressWarnings("deprecation") @Test public final void givenDeprecatedApi_whenRequestHasCustomUserAgent_thenCorrect() throws ClientProtocolException, IOException { - instance = new DefaultHttpClient(); + final DefaultHttpClient client = new DefaultHttpClient(); final HttpGet request = new HttpGet(SAMPLE_URL); request.setHeader(HttpHeaders.USER_AGENT, "Mozilla/5.0 Firefox/26.0"); + response = client.execute(request); + } - response = instance.execute(request); - - System.out.println(response); + @Test + public final void whenRequestHasCustomUserAgent_thenCorrect() throws ClientProtocolException, IOException { + instance = HttpClients.custom().setUserAgent("Mozilla/5.0 Firefox/26.0").build(); + response = instance.execute(new HttpGet(SAMPLE_URL)); } }