knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject knox git commit: [KNOX-685] - Knox tests cleanup after Jetty 9 upgrade. Final cleanup.
Date Fri, 11 Mar 2016 22:43:29 GMT
Repository: knox
Updated Branches:
  refs/heads/master 99593c2e7 -> 2074cddf0


[KNOX-685] - Knox tests cleanup after Jetty 9 upgrade. Final cleanup.


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

Branch: refs/heads/master
Commit: 2074cddf07218ccdd7c198292519cc6df2577e4c
Parents: 99593c2
Author: Kevin Minder <kminder@apache.org>
Authored: Fri Mar 11 17:43:24 2016 -0500
Committer: Kevin Minder <kminder@apache.org>
Committed: Fri Mar 11 17:43:24 2016 -0500

----------------------------------------------------------------------
 .../pom.xml                                     |  5 ++
 .../function/UsernameFunctionProcessorTest.java | 13 +----
 .../impl/ServiceRegistryFunctionsTest.java      | 14 +-----
 .../rewrite/api/UrlRewriteServletFilter.java    |  6 ---
 .../filter/rewrite/impl/UrlRewriteResponse.java | 47 ++----------------
 .../api/UrlRewriteServletFilterTest.java        | 52 ++++++++------------
 .../impl/FrontendFunctionProcessorTest.java     | 14 +-----
 .../src/test/resources/log4j.properties         |  7 ++-
 .../gateway/dispatch/DefaultDispatch.java       | 19 +------
 .../java/org/apache/hadoop/test/TestUtils.java  | 20 ++++++++
 .../apache/hadoop/test/mock/MockServlet.java    |  6 +--
 .../src/test/resources/log4j.properties         | 10 ++--
 .../apache/hadoop/gateway/util/MimeTypes.java   | 21 ++++++++
 13 files changed, 87 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-provider-identity-assertion-common/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-provider-identity-assertion-common/pom.xml b/gateway-provider-identity-assertion-common/pom.xml
index e107e41..f72ad9d 100644
--- a/gateway-provider-identity-assertion-common/pom.xml
+++ b/gateway-provider-identity-assertion-common/pom.xml
@@ -64,6 +64,11 @@
             <artifactId>gateway-test-utils</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.velocity</groupId>
+            <artifactId>velocity</artifactId>
+            <scope>test</scope>
+        </dependency>
 
         <dependency>
             <groupId>org.eclipse.jetty</groupId>

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
b/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
index 1f6d4ec..278d463 100644
--- a/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
+++ b/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
@@ -24,6 +24,7 @@ import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
 import org.apache.hadoop.gateway.identityasserter.common.function.UsernameFunctionProcessor;
 import org.apache.hadoop.gateway.security.PrimaryPrincipal;
 import org.apache.hadoop.gateway.util.urltemplate.Parser;
+import org.apache.hadoop.test.TestUtils;
 import org.apache.hadoop.test.log.NoOpLogger;
 import org.apache.hadoop.test.mock.MockInteraction;
 import org.apache.hadoop.test.mock.MockServlet;
@@ -120,16 +121,6 @@ public class UsernameFunctionProcessorTest {
     }
   }
 
-  private void execute() throws Exception {
-    System.out.println( "REQUEST=" + request );
-    ByteBuffer requestBuffer = request.generate();
-    System.out.println( "REQUEST-BUFFER=[" + new String(requestBuffer.array(),0,requestBuffer.limit())
+ "]" );
-    ByteBuffer responseBuffer = server.getResponses( requestBuffer );
-    response = HttpTester.parseResponse( responseBuffer );
-    System.out.println( "RESPONSE-BUFFER=[" + new String(responseBuffer.array(),0,responseBuffer.limit())
+ "]" );
-    System.out.println( "RESPONSE=" + response );
-  }
-
   @Test
   public void testInitialize() throws Exception {
     UsernameFunctionProcessor processor = new UsernameFunctionProcessor();
@@ -202,7 +193,7 @@ public class UsernameFunctionProcessorTest {
     request.setHeader( "Content-Type", "text/xml; charset=UTF-8" );
     request.setContent( input );
 
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), Is.is( 200 ) );

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceRegistryFunctionsTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceRegistryFunctionsTest.java
b/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceRegistryFunctionsTest.java
index 6035605..c61c013 100644
--- a/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceRegistryFunctionsTest.java
+++ b/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceRegistryFunctionsTest.java
@@ -113,16 +113,6 @@ public class ServiceRegistryFunctionsTest {
     response = null;
   }
 
-  private void execute() throws Exception {
-    System.out.println( "REQUEST=" + request );
-    ByteBuffer requestBuffer = request.generate();
-    System.out.println( "REQUEST-BUFFER=[" + new String(requestBuffer.array(),0,requestBuffer.limit())
+ "]" );
-    ByteBuffer responseBuffer = server.getResponses( requestBuffer );
-    response = HttpTester.parseResponse( responseBuffer );
-    System.out.println( "RESPONSE-BUFFER=[" + new String(responseBuffer.array(),0,responseBuffer.limit())
+ "]" );
-    System.out.println( "RESPONSE=" + response );
-  }
-
   @Test
   public void testServiceRegistryFunctionsOnXmlRequestBody() throws Exception {
     Map<String,String> initParams = new HashMap<String,String>();
@@ -149,7 +139,7 @@ public class ServiceRegistryFunctionsTest {
     request.setHeader( "Content-Type", "text/xml; charset=UTF-8" );
     request.setContent( input );
 
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), Is.is( 200 ) );
@@ -181,7 +171,7 @@ public class ServiceRegistryFunctionsTest {
     request.setHeader( "Content-Type", "application/json; charset=UTF-8" );
     request.setContent( input );
 
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), Is.is( 200 ) );

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilter.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilter.java
index f8f8f74..74ac67a 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilter.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilter.java
@@ -21,7 +21,6 @@ import org.apache.hadoop.gateway.filter.AbstractGatewayFilter;
 import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteRequest;
 import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteResponse;
 import org.apache.hadoop.gateway.util.MimeTypes;
-import org.apache.log4j.Logger;
 
 import javax.activation.MimeType;
 import javax.servlet.FilterChain;
@@ -36,8 +35,6 @@ import java.io.IOException;
  */
 public class UrlRewriteServletFilter extends AbstractGatewayFilter {
 
-  Logger LOG = Logger.getLogger(UrlRewriteServletFilter.class.getName());
-
   public static final String REQUEST_URL_RULE_PARAM = "request.url";
   public static final String REQUEST_HEADERS_FILTER_PARAM = "request.headers";
   public static final String REQUEST_COOKIES_FILTER_PARAM = "request.cookies";
@@ -57,13 +54,10 @@ public class UrlRewriteServletFilter extends AbstractGatewayFilter {
   @Override
   protected void doFilter( HttpServletRequest request, HttpServletResponse response, FilterChain
chain )
       throws IOException, ServletException {
-    LOG.debug("URL-REWRITE-SERVLET-FILTER:DO-FILTER: BEGIN");
     FilterConfig config = getConfig();
     UrlRewriteRequest rewriteRequest = new UrlRewriteRequest( config, request );
     UrlRewriteResponse rewriteResponse = new UrlRewriteResponse( config, rewriteRequest,
response );
-    LOG.debug("URL-REWRITE-SERVLET-FILTER:DO-FILTER: FILTER");
     chain.doFilter( rewriteRequest, rewriteResponse );
-    LOG.debug("URL-REWRITE-SERVLET-FILTER:DO-FILTER: END");
   }
 
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
index 59676a3..5e4aae3 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
@@ -32,7 +32,6 @@ import org.apache.hadoop.gateway.util.urltemplate.Params;
 import org.apache.hadoop.gateway.util.urltemplate.Parser;
 import org.apache.hadoop.gateway.util.urltemplate.Template;
 import org.apache.commons.io.IOUtils;
-import org.apache.log4j.Logger;
 
 import javax.activation.MimeType;
 import javax.servlet.FilterConfig;
@@ -52,13 +51,6 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
 import java.util.zip.ZipException;
@@ -71,12 +63,8 @@ import static org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteUtil.pickF
  */
 public class UrlRewriteResponse extends GatewayResponseWrapper implements Params, ResponseStreamer
{
 
-  private static Logger LOGGER = Logger.getLogger( UrlRewriteResponse.class );
-
   private static final UrlRewriteMessages LOG = MessagesFactory.get( UrlRewriteMessages.class
);
 
-  private static final ExecutorService DNS_LOOKUP_THREAD_POOL = Executors.newCachedThreadPool();
-
   // An 8K buffer better matches the underlying buffer sizes.
   // Testing with 16K made no appreciable difference.
   private static final int STREAM_BUFFER_SIZE = 8 * 1024;
@@ -227,45 +215,16 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements
Params
     }
   }
 
-  private static class AsyncDnsRequest implements Callable<String> {
-    private String hostName;
-    public AsyncDnsRequest( String hostName ) {
-      this.hostName = hostName;
-    }
-    @Override
-    public String call() throws Exception {
-      String resolvedHostName = hostName;
-      try {
-        LOGGER.debug( "LOOKUP HOSTNAME FOR " + hostName );
-        resolvedHostName = InetAddress.getByName( hostName ).getHostName();
-        LOGGER.debug( "FOUND HOSTNAME " + resolvedHostName );
-      } catch( UnknownHostException e ) {
-        // Ignore it and use the original hostname.
-        LOGGER.debug( "FAILED TO RESOLVE " + hostName );
-        e.printStackTrace();
-      }
-      return resolvedHostName;
-    }
-  }
-
   // KNOX-464: Doing this because Jetty only returns the string version of the IP address
for request.getLocalName().
   // Hopefully the local hostname will be cached so this will not be a significant performance
hit.
   // Previously this was an inline request.getServerName() but this ended up mixing the hostname
from the Host header
   // and the local port which was making load balancer configuration difficult if not impossible.
   private String getRequestLocalHostName() {
     String hostName = request.getLocalName();
-    Future<String> future = DNS_LOOKUP_THREAD_POOL.submit( new AsyncDnsRequest( hostName
) );
     try {
-      hostName = future.get( 100, TimeUnit.MILLISECONDS );
-    } catch( TimeoutException e ) {
-      LOGGER.debug( "TIMEOUT RESOLVING " + hostName );
-      e.printStackTrace();
-    } catch( InterruptedException e ) {
-      LOGGER.debug( "INTERRUPTED RESOLVING " + hostName );
-      e.printStackTrace();
-    } catch( ExecutionException e ) {
-      LOGGER.debug( "ERROR RESOLVING " + hostName );
-      e.printStackTrace();
+      hostName = InetAddress.getByName( hostName ).getHostName();
+    } catch( UnknownHostException e ) {
+      // Ignore it and use the original hostname.
     }
     return hostName;
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
index 19dee66..fc544e9 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
@@ -20,8 +20,8 @@ package org.apache.hadoop.gateway.filter.rewrite.api;
 import com.jayway.jsonassert.JsonAssert;
 import org.apache.hadoop.gateway.filter.AbstractGatewayFilter;
 import org.apache.hadoop.gateway.util.urltemplate.Parser;
+import org.apache.hadoop.test.TestUtils;
 import org.apache.hadoop.test.log.NoOpAppender;
-import org.apache.hadoop.test.log.NoOpLogger;
 import org.apache.hadoop.test.mock.MockInteraction;
 import org.apache.hadoop.test.mock.MockServlet;
 import org.apache.log4j.Appender;
@@ -32,7 +32,6 @@ import org.eclipse.jetty.servlet.ServletHolder;
 import org.eclipse.jetty.http.HttpTester;
 import org.eclipse.jetty.servlet.ServletTester;
 import org.eclipse.jetty.util.ArrayQueue;
-import org.eclipse.jetty.util.log.Log;
 import org.junit.After;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -48,7 +47,6 @@ import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.util.EnumSet;
 import java.util.Enumeration;
@@ -116,16 +114,6 @@ public class UrlRewriteServletFilterTest {
     }
   }
 
-  private void execute() throws Exception {
-    LOG.debug( "REQUEST=" + request );
-    ByteBuffer requestBuffer = request.generate();
-    LOG.debug( "REQUEST-BUFFER=[" + new String(requestBuffer.array(),0,requestBuffer.limit())
+ "]" );
-    ByteBuffer responseBuffer = server.getResponses( requestBuffer );
-    response = HttpTester.parseResponse( responseBuffer );
-    LOG.debug( "RESPONSE-BUFFER=[" + new String(responseBuffer.array(),0,responseBuffer.limit())
+ "]" );
-    LOG.debug( "RESPONSE=" + response );
-  }
-
   @Test
   public void testInboundRequestUrlRewrite() throws Exception {
     setUp( null );
@@ -141,7 +129,7 @@ public class UrlRewriteServletFilterTest {
     //request.setVersion( "HTTP/1.1" );
     request.setHeader( "Host", "mock-host:1" );
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -166,7 +154,7 @@ public class UrlRewriteServletFilterTest {
     request.setHeader( "Host", "mock-host:1" );
     request.setHeader( "Location", "http://mock-host:1/test-input-path" );
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -189,7 +177,7 @@ public class UrlRewriteServletFilterTest {
     //request.setVersion( "HTTP/1.1" );
     request.setHeader( "Host", "mock-host:1" );
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 201 ) );
@@ -216,7 +204,7 @@ public class UrlRewriteServletFilterTest {
     request.setHeader( "Cookie", "cookie-name=cookie-value; Domain=docs.foo.com; Path=/accounts;
Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; HttpOnly" );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 201 ) );
@@ -242,7 +230,7 @@ public class UrlRewriteServletFilterTest {
     request.setHeader( "Host", "mock-host:1" );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -273,7 +261,7 @@ public class UrlRewriteServletFilterTest {
     request.setContent( inputJson );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -305,7 +293,7 @@ public class UrlRewriteServletFilterTest {
     request.setContent( input );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -334,7 +322,7 @@ public class UrlRewriteServletFilterTest {
     request.setHeader( "Host", "mock-host:1" );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -364,7 +352,7 @@ public class UrlRewriteServletFilterTest {
     request.setContent( input );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -393,7 +381,7 @@ public class UrlRewriteServletFilterTest {
     request.setContent( input );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -426,7 +414,7 @@ public class UrlRewriteServletFilterTest {
     request.setContent( input );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -461,7 +449,7 @@ public class UrlRewriteServletFilterTest {
     request.setContent( input );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -501,7 +489,7 @@ public class UrlRewriteServletFilterTest {
     request.setContent( inputJson );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -534,7 +522,7 @@ public class UrlRewriteServletFilterTest {
     request.setContent( input );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -570,7 +558,7 @@ public class UrlRewriteServletFilterTest {
       request.setContent( input );
 
       // Execute the request.
-      execute();
+      response = TestUtils.execute( server, request );
 
       // Test the results.
       assertThat( response.getStatus(), is( 500 ) );
@@ -605,7 +593,7 @@ public class UrlRewriteServletFilterTest {
     request.setContent( input );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );
@@ -635,7 +623,7 @@ public class UrlRewriteServletFilterTest {
     request.setHeader( "Host", "mock-host:42" );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 307 ) );
@@ -680,7 +668,7 @@ public class UrlRewriteServletFilterTest {
     request.setContent( responseJson );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     assertThat( response.getStatus(), is( 200 ) );
     JsonAssert.with( response.getContent() ).assertThat( "$.url", is( "http://mock-host:42/test-output-path-2"
) );
@@ -709,7 +697,7 @@ public class UrlRewriteServletFilterTest {
     request.setHeader( "Host", "mock-host:42" );
 
     // Execute the request.
-    execute();
+    response = TestUtils.execute( server, request );
 
     // Test the results.
     assertThat( response.getStatus(), is( 200 ) );

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
index f245836..27f1c75 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
@@ -80,16 +80,6 @@ public class FrontendFunctionProcessorTest {
   private ArrayQueue<MockInteraction> interactions;
   private MockInteraction interaction;
 
-  private void execute() throws Exception {
-    System.out.println( "REQUEST=" + request );
-    ByteBuffer requestBuffer = request.generate();
-    System.out.println( "REQUEST-BUFFER=[" + new String(requestBuffer.array(),0,requestBuffer.limit())
+ "]" );
-    ByteBuffer responseBuffer = server.getResponses( requestBuffer );
-    response = HttpTester.parseResponse( responseBuffer );
-    System.out.println( "RESPONSE-BUFFER=[" + new String(responseBuffer.array(),0,responseBuffer.limit())
+ "]" );
-    System.out.println( "RESPONSE=" + response );
-  }
-
   @SuppressWarnings("rawtypes")
   @Test
   public void testServiceLoader() throws Exception {
@@ -203,7 +193,7 @@ public class FrontendFunctionProcessorTest {
     //request.setVersion( "HTTP/1.1" );
     request.setHeader( "Host", "test-host:42" );
 
-    execute();
+    response = TestUtils.execute( server, request );
 
     assertThat( response.getStatus(), Is.is( 200 ) );
 
@@ -248,7 +238,7 @@ public class FrontendFunctionProcessorTest {
     //request.setVersion( "HTTP/1.1" );
     request.setHeader( "Host", "test-host:42" );
 
-    execute();
+    response = TestUtils.execute( server, request );
 
     assertThat( response.getStatus(), Is.is( 200 ) );
 

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-provider-rewrite/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/resources/log4j.properties b/gateway-provider-rewrite/src/test/resources/log4j.properties
index 04cf553..c2cbce6 100644
--- a/gateway-provider-rewrite/src/test/resources/log4j.properties
+++ b/gateway-provider-rewrite/src/test/resources/log4j.properties
@@ -22,14 +22,13 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n
 
-log4j.logger.org.apache.hadoop.gateway=DEBUG
+#log4j.logger.org.apache.hadoop.gateway=DEBUG
 #log4j.logger.org.apache.hadoop.gateway.http=TRACE
 #log4j.logger.org.apache.hadoop.gateway.http.request.body=OFF
 #log4j.logger.org.apache.hadoop.gateway.http.response.body=OFF
 
-log4j.logger.org.apache.directory=ERROR
-
-log4j.logger.org.eclipse.jetty=DEBUG
+#log4j.logger.org.apache.directory=DEBUG
+#log4j.logger.org.eclipse.jetty=DEBUG
 #log4j.logger.org.apache.shiro=DEBUG
 #log4j.logger.org.apache.http=DEBUG
 #log4j.logger.org.apache.http.headers=DEBUG

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultDispatch.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultDispatch.java
index acd8ef7..d1cef55 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultDispatch.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultDispatch.java
@@ -30,6 +30,7 @@ import org.apache.hadoop.gateway.config.Default;
 import org.apache.hadoop.gateway.config.GatewayConfig;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
 import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
+import org.apache.hadoop.gateway.util.MimeTypes;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
@@ -67,7 +68,6 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
       AuditConstants.KNOX_SERVICE_NAME, AuditConstants.KNOX_COMPONENT_NAME);
 
   private Set<String> outboundResponseExcludeHeaders;
-  private Map<String,String> defaultCharsetforMimeTypes;
 
   private int replayBufferSize = -1;
 
@@ -77,13 +77,6 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
     outboundResponseExcludeHeaders = new HashSet<>();
     outboundResponseExcludeHeaders.add(SET_COOKIE);
     outboundResponseExcludeHeaders.add(WWW_AUTHENTICATE);
-
-    String utf8 = "UTF-8";
-    defaultCharsetforMimeTypes = new HashMap<>();
-    defaultCharsetforMimeTypes.put( "text/xml", utf8 );
-    defaultCharsetforMimeTypes.put( "text/json", utf8 );
-    defaultCharsetforMimeTypes.put( "application/xml", utf8 );
-    defaultCharsetforMimeTypes.put( "application/json", utf8 );
   }
 
   @Override
@@ -186,7 +179,7 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
       if( entityContentType != null ) {
         if( entityContentType.getCharset() == null ) {
           final String entityMimeType = entityContentType.getMimeType();
-          final String defaultCharset = getDefaultCharsetForMimeType( entityMimeType );
+          final String defaultCharset = MimeTypes.getDefaultCharsetForMimeType( entityMimeType
);
           if( defaultCharset != null ) {
             LOG.usingDefaultCharsetForEntity( entityMimeType, defaultCharset );
             entityContentType = entityContentType.withCharset( defaultCharset );
@@ -307,12 +300,4 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
     return outboundResponseExcludeHeaders;
   }
 
-  protected String getDefaultCharsetForMimeType( String mimeType ) {
-    String charset = null;
-    if( mimeType != null ) {
-      charset = defaultCharsetforMimeTypes.get( mimeType.trim().toLowerCase() );
-    }
-    return charset;
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
----------------------------------------------------------------------
diff --git a/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java b/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
index b6dfe54..87f801c 100644
--- a/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
+++ b/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
@@ -29,8 +29,10 @@ import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.URL;
+import java.nio.ByteBuffer;
 import java.util.Properties;
 import java.util.UUID;
+import java.util.concurrent.TimeUnit;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -43,17 +45,22 @@ import javax.xml.transform.stream.StreamResult;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
+import org.eclipse.jetty.http.HttpTester;
+import org.eclipse.jetty.servlet.ServletTester;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 public class TestUtils {
 
+  private static Logger LOG = Logger.getLogger(TestUtils.class);
+
   public static final long SHORT_TIMEOUT = 1000L;
   public static final long MEDIUM_TIMEOUT = 20 * 1000L;
   public static final long LONG_TIMEOUT = 60 * 1000L;
@@ -222,4 +229,17 @@ public class TestUtils {
       }
     }
   }
+
+  public static HttpTester.Response execute( ServletTester server, HttpTester.Request request
) throws Exception {
+    LOG.debug( "execute: request=" + request );
+    ByteBuffer requestBuffer = request.generate();
+    LOG.trace( "execute: requestBuffer=[" + new String(requestBuffer.array(),0,requestBuffer.limit())
+ "]" );
+    ByteBuffer responseBuffer = server.getResponses( requestBuffer, 30, TimeUnit.SECONDS
);
+    HttpTester.Response response = HttpTester.parseResponse( responseBuffer );
+    LOG.trace( "execute: responseBuffer=[" + new String(responseBuffer.array(),0,responseBuffer.limit())
+ "]" );
+    LOG.debug( "execute: reponse=" + response );
+    return response;
+  }
+
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServlet.java
----------------------------------------------------------------------
diff --git a/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServlet.java
b/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServlet.java
index f13526c..18191b5 100644
--- a/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServlet.java
+++ b/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServlet.java
@@ -42,7 +42,7 @@ public class MockServlet extends HttpServlet {
 
   @Override
   protected void service( HttpServletRequest request, HttpServletResponse response ) throws
ServletException, IOException {
-    LOG.debug( "MOCK-SERLVET-REQUEST: " + request.getMethod() + " " + request.getRequestURL()
+ "?" + request.getQueryString() );
+    LOG.debug( "service: request=" + request.getMethod() + " " + request.getRequestURL()
+ "?" + request.getQueryString() );
     try {
       if( interactions.isEmpty() ) {
         fail( "Mock servlet " + name + " received a request but the expected interaction
queue is empty." );
@@ -50,9 +50,9 @@ public class MockServlet extends HttpServlet {
       MockInteraction interaction = interactions.remove();
       interaction.expect().match( request );
       interaction.respond().apply( response );
-      LOG.debug( "MOCK-SERVLET-RESPONSE: " + response.getStatus() );
+      LOG.debug( "service: response=" + response.getStatus() );
     } catch( AssertionError e ) {
-      LOG.debug( "MOCK-SERVLET-FAILURE: " + e.getMessage() );
+      LOG.debug( "service: exception=" + e.getMessage() );
       e.printStackTrace(); // I18N not required.
       throw new ServletException( e );
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-test/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/resources/log4j.properties b/gateway-test/src/test/resources/log4j.properties
index c371555..5c77441 100644
--- a/gateway-test/src/test/resources/log4j.properties
+++ b/gateway-test/src/test/resources/log4j.properties
@@ -23,16 +23,14 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n
 
-#log4j.logger.org.apache.hadoop.gateway=ERROR
-log4j.logger.org.apache.hadoop.gateway=DEBUG
-log4j.logger.org.apache.hadoop.test=DEBUG
+#log4j.logger.org.apache.hadoop.gateway=DEBUG
+#log4j.logger.org.apache.hadoop.test=DEBUG
 #log4j.logger.org.apache.hadoop.gateway.http=TRACE
 #log4j.logger.org.apache.hadoop.gateway.http.request.body=OFF
 #log4j.logger.org.apache.hadoop.gateway.http.response.body=OFF
 
-log4j.logger.org.apache.directory=ERROR
-
-log4j.logger.org.eclipse.jetty=DEBUG
+#log4j.logger.org.apache.directory=DEBUG
+#log4j.logger.org.eclipse.jetty=DEBUG
 #log4j.logger.org.apache.shiro=DEBUG
 #log4j.logger.org.apache.http=DEBUG
 #log4j.logger.org.apache.http.headers=DEBUG

http://git-wip-us.apache.org/repos/asf/knox/blob/2074cddf/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/MimeTypes.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/MimeTypes.java
b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/MimeTypes.java
index cdcb6cc..6b54603 100644
--- a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/MimeTypes.java
+++ b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/MimeTypes.java
@@ -17,6 +17,8 @@
  */
 package org.apache.hadoop.gateway.util;
 
+import java.util.HashMap;
+import java.util.Map;
 import javax.activation.MimeType;
 import javax.activation.MimeTypeParseException;
 
@@ -24,6 +26,17 @@ public class MimeTypes {
 
   private static final String CHARSET_PARAMETER_NAME = "charset";
 
+  private static final String UTF8_CHARSET = "UTF-8";
+
+  private static Map<String,String> DEFAULT_CHARSETS;
+  static {
+    DEFAULT_CHARSETS = new HashMap<>();
+    DEFAULT_CHARSETS.put( "text/xml", UTF8_CHARSET );
+    DEFAULT_CHARSETS.put( "text/json", UTF8_CHARSET );
+    DEFAULT_CHARSETS.put( "application/xml", UTF8_CHARSET );
+    DEFAULT_CHARSETS.put( "application/json", UTF8_CHARSET );
+  }
+
   public static MimeType create( final String base, final String encoding ) {
     MimeType type = null;
     if( base != null ) {
@@ -54,4 +67,12 @@ public class MimeTypes {
     type.setParameter( CHARSET_PARAMETER_NAME, charset );
   }
 
+  public static String getDefaultCharsetForMimeType( final String mimeType ) {
+    String charset = null;
+    if( mimeType != null ) {
+      charset = DEFAULT_CHARSETS.get( mimeType.trim().toLowerCase() );
+    }
+    return charset;
+  }
+
 }


Mime
View raw message