knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject knox git commit: KNOX-738 - Remove references to deprecated httpclient class DefaultHttpClient
Date Thu, 31 Aug 2017 09:34:07 GMT
Repository: knox
Updated Branches:
  refs/heads/master 841295208 -> f1bbea9b7


KNOX-738 - Remove references to deprecated httpclient class DefaultHttpClient


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/f1bbea9b
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/f1bbea9b
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/f1bbea9b

Branch: refs/heads/master
Commit: f1bbea9b73d0e24454cf65a3c015b083f9247aa2
Parents: 8412952
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Thu Aug 31 10:33:35 2017 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Thu Aug 31 10:33:35 2017 +0100

----------------------------------------------------------------------
 .../ha/dispatch/DefaultHaDispatchTest.java      |  7 ++--
 .../apache/hadoop/gateway/AuditLoggingTest.java | 13 ++++---
 .../apache/hadoop/gateway/TempletonDemo.java    |  8 +++--
 .../gateway/rm/dispatch/RMHaDispatchTest.java   | 11 ++++--
 .../hdfs/dispatch/WebHdfsHaDispatchTest.java    |  7 ++--
 .../gateway/dispatch/DefaultDispatchTest.java   | 16 +++++++--
 .../hadoop/gateway/GatewayBasicFuncTest.java    | 36 +++++++++++++-------
 7 files changed, 67 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/f1bbea9b/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/dispatch/DefaultHaDispatchTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/dispatch/DefaultHaDispatchTest.java
b/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/dispatch/DefaultHaDispatchTest.java
index 0436532..bcb62f6 100644
--- a/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/dispatch/DefaultHaDispatchTest.java
+++ b/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/dispatch/DefaultHaDispatchTest.java
@@ -25,7 +25,8 @@ import org.apache.hadoop.gateway.ha.provider.impl.HaDescriptorFactory;
 import org.apache.hadoop.gateway.servlet.SynchronousServletOutputStreamAdapter;
 import org.apache.http.client.methods.HttpRequestBase;
 import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.params.BasicHttpParams;
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
@@ -88,7 +89,9 @@ public class DefaultHaDispatchTest {
     EasyMock.replay(filterConfig, servletContext, outboundRequest, inboundRequest, outboundResponse);
     Assert.assertEquals(uri1.toString(), provider.getActiveURL(serviceName));
     DefaultHaDispatch dispatch = new DefaultHaDispatch();
-    dispatch.setHttpClient(new DefaultHttpClient());
+    HttpClientBuilder builder = HttpClientBuilder.create();
+    CloseableHttpClient client = builder.build();
+    dispatch.setHttpClient(client);
     dispatch.setHaProvider(provider);
     dispatch.setServiceRole(serviceName);
     dispatch.init();

http://git-wip-us.apache.org/repos/asf/knox/blob/f1bbea9b/gateway-server/src/test/java/org/apache/hadoop/gateway/AuditLoggingTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/AuditLoggingTest.java
b/gateway-server/src/test/java/org/apache/hadoop/gateway/AuditLoggingTest.java
index a5893e6..6819d44 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/AuditLoggingTest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/AuditLoggingTest.java
@@ -51,7 +51,8 @@ import org.apache.hadoop.gateway.config.GatewayConfig;
 import org.apache.hadoop.gateway.dispatch.DefaultDispatch;
 import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
 import org.apache.hadoop.test.log.CollectAppender;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.log4j.spi.LoggingEvent;
 import org.easymock.EasyMock;
 import org.junit.After;
@@ -81,7 +82,7 @@ public class AuditLoggingTest {
   @Test
   /**
    * Empty filter chain. Two events with same correlation ID are expected:
-   * 
+   *
    * action=access request_type=uri outcome=unavailable
    * action=access request_type=uri outcome=success message=Response status: 404
    */
@@ -126,7 +127,7 @@ public class AuditLoggingTest {
   @Test
   /**
    * One NoOp filter in chain. Single audit event with same with specified request URI is
expected:
-   * 
+   *
    * action=access request_type=uri outcome=unavailable
    */
   public void testNoopFilter() throws ServletException, IOException,
@@ -178,7 +179,7 @@ public class AuditLoggingTest {
   @Test
   /**
    * Dispatching outbound request. Remote host is unreachable. Two log events is expected:
-   * 
+   *
    * action=dispatch request_type=uri outcome=FAILED
    * action=dispatch request_type=uri outcome=unavailable
    */
@@ -194,7 +195,9 @@ public class AuditLoggingTest {
     EasyMock.replay( outboundResponse );
 
     DefaultDispatch dispatch = new DefaultDispatch();
-    dispatch.setHttpClient(new DefaultHttpClient());
+    HttpClientBuilder builder = HttpClientBuilder.create();
+    CloseableHttpClient client = builder.build();
+    dispatch.setHttpClient(client);
     try {
       dispatch.doGet( new URI( uri ), inboundRequest, outboundResponse );
       fail( "Expected exception while accessing to unreachable host" );

http://git-wip-us.apache.org/repos/asf/knox/blob/f1bbea9b/gateway-server/src/test/java/org/apache/hadoop/gateway/TempletonDemo.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/TempletonDemo.java b/gateway-server/src/test/java/org/apache/hadoop/gateway/TempletonDemo.java
index e262761..bdcb26c 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/TempletonDemo.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/TempletonDemo.java
@@ -21,10 +21,10 @@ import org.apache.hadoop.test.category.ManualTests;
 import org.apache.hadoop.test.category.SlowTests;
 import org.apache.http.HttpResponse;
 import org.apache.http.NameValuePair;
-import org.apache.http.client.HttpClient;
 import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.HttpPost;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.message.BasicNameValuePair;
 import org.apache.http.util.EntityUtils;
 import org.apache.log4j.helpers.Loader;
@@ -53,7 +53,6 @@ public class TempletonDemo {
   }
 
   private void demo( String url ) throws IOException {
-    HttpClient client = new DefaultHttpClient();
     List<NameValuePair> parameters = new ArrayList<NameValuePair>();
     parameters.add( new BasicNameValuePair( "user.name", "hdfs" ) );
     parameters.add( new BasicNameValuePair( "jar", "wordcount/org.apache.hadoop-examples.jar"
) );
@@ -63,6 +62,9 @@ public class TempletonDemo {
     UrlEncodedFormEntity entity = new UrlEncodedFormEntity( parameters, Charset.forName(
"UTF-8" ) );
     HttpPost request = new HttpPost( url );
     request.setEntity( entity );
+
+    HttpClientBuilder builder = HttpClientBuilder.create();
+    CloseableHttpClient client = builder.build();
     HttpResponse response = client.execute( request );
     System.out.println( EntityUtils.toString( response.getEntity() ) );
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/f1bbea9b/gateway-service-rm/src/test/java/org/apache/hadoop/gateway/rm/dispatch/RMHaDispatchTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-rm/src/test/java/org/apache/hadoop/gateway/rm/dispatch/RMHaDispatchTest.java
b/gateway-service-rm/src/test/java/org/apache/hadoop/gateway/rm/dispatch/RMHaDispatchTest.java
index 88258c9..c14bd89 100644
--- a/gateway-service-rm/src/test/java/org/apache/hadoop/gateway/rm/dispatch/RMHaDispatchTest.java
+++ b/gateway-service-rm/src/test/java/org/apache/hadoop/gateway/rm/dispatch/RMHaDispatchTest.java
@@ -24,9 +24,10 @@ import org.apache.hadoop.gateway.ha.provider.impl.DefaultHaProvider;
 import org.apache.hadoop.gateway.ha.provider.impl.HaDescriptorFactory;
 import org.apache.http.client.methods.HttpRequestBase;
 import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.params.BasicHttpParams;
 import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.entity.ContentType;
 import org.apache.http.Header;
 import org.apache.http.message.BasicHttpResponse;
@@ -107,7 +108,9 @@ public class RMHaDispatchTest {
         EasyMock.replay(filterConfig, servletContext, outboundRequest, inboundRequest, outboundResponse);
         Assert.assertEquals(uri1.toString(), provider.getActiveURL(serviceName));
         RMHaDispatch dispatch = new RMHaDispatch();
-        dispatch.setHttpClient(new DefaultHttpClient());
+        HttpClientBuilder builder = HttpClientBuilder.create();
+        CloseableHttpClient client = builder.build();
+        dispatch.setHttpClient(client);
         dispatch.setHaProvider(provider);
         dispatch.init();
         long startTime = System.currentTimeMillis();
@@ -185,7 +188,9 @@ public class RMHaDispatchTest {
         EasyMock.replay(filterConfig, servletContext, inboundResponse, outboundRequest, inboundRequest,
outboundResponse);
 
         RMHaDispatch dispatch = new RMHaDispatch();
-        dispatch.setHttpClient(new DefaultHttpClient());
+        HttpClientBuilder builder = HttpClientBuilder.create();
+        CloseableHttpClient client = builder.build();
+        dispatch.setHttpClient(client);
         dispatch.setHaProvider(provider);
         dispatch.init();
         long startTime = System.currentTimeMillis();

http://git-wip-us.apache.org/repos/asf/knox/blob/f1bbea9b/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchTest.java
b/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchTest.java
index ed1eede..bcf80d8 100644
--- a/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchTest.java
+++ b/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchTest.java
@@ -25,7 +25,8 @@ import org.apache.hadoop.gateway.ha.provider.impl.HaDescriptorFactory;
 import org.apache.hadoop.gateway.servlet.SynchronousServletOutputStreamAdapter;
 import org.apache.http.client.methods.HttpRequestBase;
 import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.params.BasicHttpParams;
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
@@ -88,7 +89,9 @@ public class WebHdfsHaDispatchTest {
       EasyMock.replay(filterConfig, servletContext, outboundRequest, inboundRequest, outboundResponse);
       Assert.assertEquals(uri1.toString(), provider.getActiveURL(serviceName));
       WebHdfsHaDispatch dispatch = new WebHdfsHaDispatch();
-      dispatch.setHttpClient(new DefaultHttpClient());
+      HttpClientBuilder builder = HttpClientBuilder.create();
+      CloseableHttpClient client = builder.build();
+      dispatch.setHttpClient(client);
       dispatch.setHaProvider(provider);
       dispatch.init();
       long startTime = System.currentTimeMillis();

http://git-wip-us.apache.org/repos/asf/knox/blob/f1bbea9b/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/DefaultDispatchTest.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/DefaultDispatchTest.java
b/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/DefaultDispatchTest.java
index c51fb1e..f864712 100644
--- a/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/DefaultDispatchTest.java
+++ b/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/DefaultDispatchTest.java
@@ -44,8 +44,11 @@ import org.apache.hadoop.test.TestUtils;
 import org.apache.hadoop.test.category.FastTests;
 import org.apache.hadoop.test.category.UnitTests;
 import org.apache.http.HttpEntity;
+import org.apache.http.HttpVersion;
+import org.apache.http.RequestLine;
 import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.params.BasicHttpParams;
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
@@ -65,6 +68,11 @@ public class DefaultDispatchTest {
     HttpUriRequest outboundRequest = EasyMock.createNiceMock( HttpUriRequest.class );
     EasyMock.expect( outboundRequest.getMethod() ).andReturn( "GET" ).anyTimes();
     EasyMock.expect( outboundRequest.getURI() ).andReturn( uri  ).anyTimes();
+
+    RequestLine requestLine = EasyMock.createNiceMock( RequestLine.class );
+    EasyMock.expect( requestLine.getMethod() ).andReturn( "GET" ).anyTimes();
+    EasyMock.expect( requestLine.getProtocolVersion() ).andReturn( HttpVersion.HTTP_1_1 ).anyTimes();
+    EasyMock.expect( outboundRequest.getRequestLine() ).andReturn( requestLine ).anyTimes();
     EasyMock.expect( outboundRequest.getParams() ).andReturn( params ).anyTimes();
 
     HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class
);
@@ -82,10 +90,12 @@ public class DefaultDispatchTest {
       }
     });
 
-    EasyMock.replay( outboundRequest, inboundRequest, outboundResponse );
+    EasyMock.replay( outboundRequest, inboundRequest, outboundResponse, requestLine );
 
     DefaultDispatch dispatch = new DefaultDispatch();
-    dispatch.setHttpClient(new DefaultHttpClient());
+    HttpClientBuilder builder = HttpClientBuilder.create();
+    CloseableHttpClient client = builder.build();
+    dispatch.setHttpClient(client);
     try {
       dispatch.executeRequest( outboundRequest, inboundRequest, outboundResponse );
       fail( "Should have thrown IOException" );

http://git-wip-us.apache.org/repos/asf/knox/blob/f1bbea9b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
index bbb801b..499ba06 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
@@ -56,14 +56,16 @@ import org.apache.http.HttpStatus;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.AuthCache;
+import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.auth.BasicScheme;
 import org.apache.http.impl.client.BasicAuthCache;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.util.EntityUtils;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
@@ -4338,10 +4340,15 @@ public class GatewayBasicFuncTest {
 
     URL url = new URL( driver.getUrl( "OOZIE" ) + "/v1/jobs?action=start" + ( driver.isUseGateway()
? "" : "&user.name=" + user ) );
     HttpHost targetHost = new HttpHost( url.getHost(), url.getPort(), url.getProtocol() );
-    DefaultHttpClient client = new DefaultHttpClient();
-    client.getCredentialsProvider().setCredentials(
+    HttpClientBuilder builder = HttpClientBuilder.create();
+    CloseableHttpClient client = builder.build();
+
+    HttpClientContext context = HttpClientContext.create();
+    CredentialsProvider credsProvider = new BasicCredentialsProvider();
+    credsProvider.setCredentials(
         new AuthScope( targetHost ),
         new UsernamePasswordCredentials( user, password ) );
+    context.setCredentialsProvider( credsProvider );
 
     // Create AuthCache instance
     AuthCache authCache = new BasicAuthCache();
@@ -4349,15 +4356,14 @@ public class GatewayBasicFuncTest {
     BasicScheme basicAuth = new BasicScheme();
     authCache.put( targetHost, basicAuth );
     // Add AuthCache to the execution context
-    BasicHttpContext localContext = new BasicHttpContext();
-    localContext.setAttribute( ClientContext.AUTH_CACHE, authCache );
+    context.setAuthCache( authCache );
 
     HttpPost post = new HttpPost( url.toURI() );
 //      post.getParams().setParameter( "action", "start" );
     StringEntity entity = new StringEntity( request, org.apache.http.entity.ContentType.create(
"application/xml", "UTF-8" ) );
     post.setEntity( entity );
     post.setHeader( "X-XSRF-Header", "ksdjfhdsjkfhds" );
-    HttpResponse response = client.execute( targetHost, post, localContext );
+    HttpResponse response = client.execute( targetHost, post, context );
     assertThat( response.getStatusLine().getStatusCode(), Matchers.is(status) );
     String json = EntityUtils.toString( response.getEntity() );
 
@@ -4428,10 +4434,15 @@ public class GatewayBasicFuncTest {
     //NOTE:  For some reason REST-assured doesn't like this and ends up failing with Content-Length
issues.
     URL url = new URL( driver.getUrl( "OOZIE" ) + "/v1/job/" + id + ( driver.isUseGateway()
? "" : "?user.name=" + user ) );
     HttpHost targetHost = new HttpHost( url.getHost(), url.getPort(), url.getProtocol() );
-    DefaultHttpClient client = new DefaultHttpClient();
-    client.getCredentialsProvider().setCredentials(
+    HttpClientBuilder builder = HttpClientBuilder.create();
+    CloseableHttpClient client = builder.build();
+
+    HttpClientContext context = HttpClientContext.create();
+    CredentialsProvider credsProvider = new BasicCredentialsProvider();
+    credsProvider.setCredentials(
         new AuthScope( targetHost ),
         new UsernamePasswordCredentials( user, password ) );
+    context.setCredentialsProvider( credsProvider );
 
     // Create AuthCache instance
     AuthCache authCache = new BasicAuthCache();
@@ -4439,12 +4450,11 @@ public class GatewayBasicFuncTest {
     BasicScheme basicAuth = new BasicScheme();
     authCache.put( targetHost, basicAuth );
     // Add AuthCache to the execution context
-    BasicHttpContext localContext = new BasicHttpContext();
-    localContext.setAttribute( ClientContext.AUTH_CACHE, authCache );
+    context.setAuthCache( authCache );
 
     HttpGet request = new HttpGet( url.toURI() );
     request.setHeader("X-XSRF-Header", "ksdhfjkhdsjkf");
-    HttpResponse response = client.execute( targetHost, request, localContext );
+    HttpResponse response = client.execute( targetHost, request, context );
     assertThat( response.getStatusLine().getStatusCode(), Matchers.is(status) );
     String json = EntityUtils.toString( response.getEntity() );
     String jobStatus = JsonPath.from(json).getString( "status" );


Mime
View raw message