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. Add charset/i18n debug logging.
Date Thu, 10 Mar 2016 02:25:46 GMT
Repository: knox
Updated Branches:
  refs/heads/master 3becd55dd -> 933b73e77


[KNOX-685] - Knox tests cleanup after Jetty 9 upgrade. Add charset/i18n debug logging.


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

Branch: refs/heads/master
Commit: 933b73e77ba96965b8f8ed15f28f4fb17db09ac9
Parents: 3becd55
Author: Kevin Minder <kminder@apache.org>
Authored: Wed Mar 9 21:25:35 2016 -0500
Committer: Kevin Minder <kminder@apache.org>
Committed: Wed Mar 9 21:25:35 2016 -0500

----------------------------------------------------------------------
 .../hadoop/gateway/SpiGatewayMessages.java      |  6 +++
 .../gateway/dispatch/DefaultDispatch.java       | 40 +++++++++++---------
 .../apache/hadoop/test/mock/MockServlet.java    |  1 +
 .../src/test/resources/log4j.properties         |  6 ++-
 4 files changed, 33 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/933b73e7/gateway-spi/src/main/java/org/apache/hadoop/gateway/SpiGatewayMessages.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/SpiGatewayMessages.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/SpiGatewayMessages.java
index 34ec105..4c760cb 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/SpiGatewayMessages.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/SpiGatewayMessages.java
@@ -23,6 +23,7 @@ import org.apache.hadoop.gateway.i18n.messages.Messages;
 import org.apache.hadoop.gateway.i18n.messages.StackTrace;
 
 import java.net.URI;
+import java.nio.charset.Charset;
 
 
 /**
@@ -55,4 +56,9 @@ public interface SpiGatewayMessages {
   @Message( level = MessageLevel.WARN, text = "Skipping unencodable parameter {0}={1}, {2}:
{3}" )
   void skippingUnencodableParameter( String name, String value, String encoding, @StackTrace(
level = MessageLevel.DEBUG ) Exception e );
 
+  @Message( level = MessageLevel.DEBUG, text = "Using default character set {1} for entity
of type {0}" )
+  void usingDefaultCharsetForEntity( String entityMimeType, String defaultCharset );
+
+  @Message( level = MessageLevel.DEBUG, text = "Using explicit character set {1} for entity
of type {0}" )
+  void usingExplicitCharsetForEntity( String mimeType, Charset charset );
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/933b73e7/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 992a1a6..6a7e6d8 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
@@ -67,7 +67,7 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
       AuditConstants.KNOX_SERVICE_NAME, AuditConstants.KNOX_COMPONENT_NAME);
 
   private Set<String> outboundResponseExcludeHeaders;
-  private Map<String,String> inboundResponseCharsetDefaults;
+  private Map<String,String> defaultCharsetforMimeTypes;
 
   private int replayBufferSize = -1;
 
@@ -79,11 +79,11 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
     outboundResponseExcludeHeaders.add(WWW_AUTHENTICATE);
 
     String utf8 = "UTF-8";
-    inboundResponseCharsetDefaults = new HashMap<>();
-    inboundResponseCharsetDefaults.put( "text/xml", utf8 );
-    inboundResponseCharsetDefaults.put( "text/json", utf8 );
-    inboundResponseCharsetDefaults.put( "application/xml", utf8 );
-    inboundResponseCharsetDefaults.put( "application/json", utf8 );
+    defaultCharsetforMimeTypes = new HashMap<>();
+    defaultCharsetforMimeTypes.put( "text/xml", utf8 );
+    defaultCharsetforMimeTypes.put( "text/json", utf8 );
+    defaultCharsetforMimeTypes.put( "application/xml", utf8 );
+    defaultCharsetforMimeTypes.put( "application/json", utf8 );
   }
 
   @Override
@@ -179,21 +179,25 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
     }
   }
 
-  private String getInboundResponseContentType( HttpEntity entity ) {
-    String name = null;
+  private String getInboundResponseContentType( final HttpEntity entity ) {
+    String fullContentType = null;
     if( entity != null ) {
-      ContentType type = ContentType.get( entity );
-      if( type != null ) {
-        if( type.getCharset() == null ) {
-          String charset = getInboundResponseCharacterEncoding( type.getMimeType() );
-          if( charset != null ) {
-            type = type.withCharset( charset );
+      ContentType entityContentType = ContentType.get( entity );
+      if( entityContentType != null ) {
+        if( entityContentType.getCharset() == null ) {
+          final String entityMimeType = entityContentType.getMimeType();
+          final String defaultCharset = getDefaultCharsetForMimeType( entityMimeType );
+          if( defaultCharset != null ) {
+            LOG.usingDefaultCharsetForEntity( entityMimeType, defaultCharset );
+            entityContentType = entityContentType.withCharset( defaultCharset );
           }
+        } else {
+          LOG.usingExplicitCharsetForEntity( entityContentType.getMimeType(), entityContentType.getCharset()
);
         }
-        name = type.toString();
+        fullContentType = entityContentType.toString();
       }
     }
-    return name;
+    return fullContentType;
   }
 
   protected void closeInboundResponse( HttpResponse response, InputStream stream ) throws
IOException {
@@ -298,10 +302,10 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
     return outboundResponseExcludeHeaders;
   }
 
-  protected String getInboundResponseCharacterEncoding( String mimeType ) {
+  protected String getDefaultCharsetForMimeType( String mimeType ) {
     String charset = null;
     if( mimeType != null ) {
-      charset = inboundResponseCharsetDefaults.get( mimeType.trim().toLowerCase() );
+      charset = defaultCharsetforMimeTypes.get( mimeType.trim().toLowerCase() );
     }
     return charset;
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/933b73e7/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 03f3efe..f13526c 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
@@ -52,6 +52,7 @@ public class MockServlet extends HttpServlet {
       interaction.respond().apply( response );
       LOG.debug( "MOCK-SERVLET-RESPONSE: " + response.getStatus() );
     } catch( AssertionError e ) {
+      LOG.debug( "MOCK-SERVLET-FAILURE: " + e.getMessage() );
       e.printStackTrace(); // I18N not required.
       throw new ServletException( e );
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/933b73e7/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 2e28e37..c371555 100644
--- a/gateway-test/src/test/resources/log4j.properties
+++ b/gateway-test/src/test/resources/log4j.properties
@@ -23,14 +23,16 @@ 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=ERROR
+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.eclipse.jetty=DEBUG
 #log4j.logger.org.apache.shiro=DEBUG
 #log4j.logger.org.apache.http=DEBUG
 #log4j.logger.org.apache.http.headers=DEBUG


Mime
View raw message