knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject git commit: KNOX-75: make Knox work with Secure Oozie. Contributed by Dilli Arumugam.
Date Mon, 17 Jun 2013 20:27:39 GMT
Updated Branches:
  refs/heads/master ad693b0e7 -> b79d6a8a1


KNOX-75: make Knox work with Secure Oozie.  Contributed by Dilli Arumugam.


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

Branch: refs/heads/master
Commit: b79d6a8a19ab58ffef1d80a4c11853bd7872fc4c
Parents: ad693b0
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Mon Jun 17 16:27:33 2013 -0400
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Mon Jun 17 16:27:33 2013 -0400

----------------------------------------------------------------------
 .../gateway/dispatch/HttpClientDispatch.java    | 47 +++++++++++---------
 1 file changed, 27 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/b79d6a8a/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
index dc6bc97..aabf9e0 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
@@ -17,16 +17,6 @@
  */
 package org.apache.hadoop.gateway.dispatch;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.charset.Charset;
-import java.security.Principal;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
 import org.apache.commons.io.IOUtils;
 import org.apache.hadoop.gateway.GatewayMessages;
 import org.apache.hadoop.gateway.GatewayResources;
@@ -53,16 +43,27 @@ import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HttpContext;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.Charset;
+import java.security.Principal;
+
 /**
  *
  */
 public class HttpClientDispatch extends AbstractGatewayDispatch {
 
   private static final String CT_APP_WWW_FORM_URL_ENCODED = "application/x-www-form-urlencoded";
+  private static final String CT_APP_XML = "application/xml";
 
   private static GatewayMessages LOG = MessagesFactory.get( GatewayMessages.class );
   private static GatewayResources RES = ResourcesFactory.get( GatewayResources.class );
   private static final EmptyJaasCredentials EMPTY_JAAS_CREDENTIALS = new EmptyJaasCredentials();
+  private static final int REPLAY_BUFFER_MAX_SIZE = 1024 * 1024; // limit to 1MB
 
   protected void executeRequest(
       HttpUriRequest outboundRequest,
@@ -126,17 +127,23 @@ public class HttpClientDispatch extends AbstractGatewayDispatch {
     String contentType = request.getContentType();
     String contentEncoding = request.getCharacterEncoding();
     HttpEntity entity = null;
-    if ((contentType != null)
-        && contentType.startsWith(CT_APP_WWW_FORM_URL_ENCODED)) {
-      if (contentEncoding == null) {
-        contentEncoding = Charset.defaultCharset().name();
+    if ((contentLength > 0) && (contentType != null)
+        && (contentType.startsWith(CT_APP_WWW_FORM_URL_ENCODED) || 
+            contentType.equalsIgnoreCase(CT_APP_XML))) {
+      if (contentLength <= REPLAY_BUFFER_MAX_SIZE) {
+        if (contentEncoding == null) {
+          contentEncoding = Charset.defaultCharset().name();
+        }
+        String body = IOUtils.toString(contentStream, contentEncoding);
+        // ASCII is OK here because the urlEncode about should have already
+        // escaped
+        byte[] bodyBytes = body.getBytes("US-ASCII");
+        ContentType ct = contentType.equalsIgnoreCase(CT_APP_XML) ? ContentType.APPLICATION_XML
+            : ContentType.APPLICATION_FORM_URLENCODED;
+        entity = new ByteArrayEntity(bodyBytes, ct);
+      } else {
+        entity = new InputStreamEntity(contentStream, contentLength);
       }
-      String body = IOUtils.toString(contentStream, contentEncoding);
-      // ASCII is OK here because the urlEncode about should have already
-      // escaped
-      byte[] bodyBytes = body.getBytes("US-ASCII");
-      entity = new ByteArrayEntity(bodyBytes,
-          ContentType.APPLICATION_FORM_URLENCODED);
     } else {
       InputStreamEntity streamEntity = new RepeatableInputStreamEntity(
           contentStream, contentLength); // DILLI


Mime
View raw message