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-681] - A PUT with Content-Type application/xml but no body causes NullPointerException
Date Tue, 08 Mar 2016 19:45:28 GMT
Repository: knox
Updated Branches:
  refs/heads/master 3a7799fbf -> 7861f20e5


[KNOX-681] - A PUT with Content-Type application/xml but no body causes NullPointerException


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

Branch: refs/heads/master
Commit: 7861f20e5c318b5dcfe28949b68d5c8d82b4b390
Parents: 3a7799f
Author: Kevin Minder <kminder@apache.org>
Authored: Tue Mar 8 14:36:32 2016 -0500
Committer: Kevin Minder <kminder@apache.org>
Committed: Tue Mar 8 14:45:22 2016 -0500

----------------------------------------------------------------------
 CHANGES                                         |   1 +
 .../filter/rewrite/impl/UrlRewriteRequest.java  |  19 ++-
 .../rewrite/impl/xml/XmlFilterReader.java       |   6 +-
 .../hadoop/test/mock/MockResponseProvider.java  |   4 +
 .../hadoop/gateway/GatewayAppFuncTest.java      |   4 -
 .../hadoop/gateway/GatewayBasicFuncTest.java    |   5 -
 .../hadoop/gateway/GatewayMultiFuncTest.java    | 145 +++++++++++++++----
 .../hadoop/gateway/GatewaySampleFuncTest.java   |   5 -
 .../hadoop/gateway/GatewaySslFuncTest.java      |   4 -
 .../gateway/OozieServiceDefinitionTest.java     |   1 +
 .../test-knox678-utf8-chars-topology.xml        |   2 +-
 11 files changed, 142 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/7861f20e/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 06efd2d..a757eaa 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,7 @@ Release Notes - Apache Knox - Version 0.9.0
     * [KNOX-678] - Malformed UTF-8 characters in JSON Response
     * [KNOX-680] - Update Knox's HttpClient dependency to latest version
 ** Bug
+    * [KNOX-681] - A PUT with Content-Type application/xml but no body causes NullPointerException
 
 ------------------------------------------------------------------------------
 Release Notes - Apache Knox - Version 0.8.0

http://git-wip-us.apache.org/repos/asf/knox/blob/7861f20e/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
index 4197d65..fd6cd24 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
@@ -211,11 +211,14 @@ public class UrlRewriteRequest extends GatewayRequestWrapper implements
Resolver
 
   @Override
   public ServletInputStream getInputStream() throws IOException {
-    MimeType mimeType = getMimeType();
-    UrlRewriteFilterContentDescriptor filterContentConfig = getRewriteFilterConfig( bodyFilterName,
mimeType );
-    InputStream stream = UrlRewriteStreamFilterFactory.create(
-        mimeType, null, super.getInputStream(), rewriter, this, UrlRewriter.Direction.IN,
filterContentConfig );
-    return new UrlRewriteRequestStream( stream );
+    ServletInputStream input = super.getInputStream();
+    if( getContentLength() != 0 ) {
+      MimeType mimeType = getMimeType();
+      UrlRewriteFilterContentDescriptor filterContentConfig = getRewriteFilterConfig( bodyFilterName,
mimeType );
+      InputStream stream = UrlRewriteStreamFilterFactory.create( mimeType, null, input, rewriter,
this, UrlRewriter.Direction.IN, filterContentConfig );
+      input = new UrlRewriteRequestStream( stream );
+    }
+    return input;
   }
 
   @Override
@@ -226,7 +229,11 @@ public class UrlRewriteRequest extends GatewayRequestWrapper implements
Resolver
   @Override
   public int getContentLength() {
     // The rewrite might change the content length so return the default of -1 to indicate
the length is unknown.
-    return -1;
+    int contentLength = super.getContentLength();
+    if( contentLength > 0 ) {
+      contentLength = -1;
+    }
+    return contentLength;
   }
 
   private UrlRewriteFilterContentDescriptor getRewriteFilterConfig( String filterName, MimeType
mimeType ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/7861f20e/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
index fe1682c..cfaebd2 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
@@ -120,10 +120,12 @@ public abstract class XmlFilterReader extends Reader {
         try {
           XMLEvent event = parser.nextEvent();
           processEvent( event );
+        } catch( IOException e ) {
+          throw e;
         } catch( RuntimeException e ) {
           throw e;
-        } catch( Exception e ) {
-          throw e instanceof IOException ? (IOException)e : new IOException( e );
+        } catch ( Exception e ) {
+          throw new RuntimeException( e );
         }
         available = buffer.length() - offset;
       } else {

http://git-wip-us.apache.org/repos/asf/knox/blob/7861f20e/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockResponseProvider.java
----------------------------------------------------------------------
diff --git a/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockResponseProvider.java
b/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockResponseProvider.java
index 9bcc223..b2dd206 100644
--- a/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockResponseProvider.java
+++ b/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockResponseProvider.java
@@ -115,6 +115,8 @@ public class MockResponseProvider {
   public void apply( HttpServletResponse response ) throws IOException {
     if( statusCode != null ) {
       response.setStatus( statusCode );
+    } else {
+      response.setStatus( HttpServletResponse.SC_OK );
     }
     if( errorCode != null ) {
       if( errorMsg != null ) {
@@ -148,8 +150,10 @@ public class MockResponseProvider {
     if( contentLength != null ) {
       response.setContentLength( contentLength );
     }
+    response.flushBuffer();
     if( entity != null ) {
       response.getOutputStream().write( entity );
+      response.getOutputStream().flush();
       response.getOutputStream().close();
     }
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/7861f20e/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
index d599014..4bd956d 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
@@ -29,7 +29,6 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.UUID;
 
-import com.jayway.restassured.RestAssured;
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.hadoop.gateway.security.ldap.SimpleLdapDirectoryServer;
@@ -50,8 +49,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static com.jayway.restassured.RestAssured.given;
-import static com.jayway.restassured.config.ConnectionConfig.connectionConfig;
-import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
 import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
 import static org.hamcrest.CoreMatchers.equalTo;
@@ -87,7 +84,6 @@ public class GatewayAppFuncTest {
   @BeforeClass
   public static void setupSuite() throws Exception {
     LOG_ENTER();
-    RestAssured.config = newConfig().connectionConfig(connectionConfig().closeIdleConnectionsAfterEachResponse());
     //appenders = NoOpAppender.setUp();
     setupLdap();
     setupGateway();

http://git-wip-us.apache.org/repos/asf/knox/blob/7861f20e/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 5dab849..2df67dd 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
@@ -26,7 +26,6 @@ import java.io.PrintStream;
 import java.io.StringWriter;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
-import java.net.ServerSocket;
 import java.net.URI;
 import java.nio.charset.Charset;
 import java.util.HashMap;
@@ -34,7 +33,6 @@ import java.util.Map;
 import java.util.Map.Entry;
 import javax.ws.rs.core.MediaType;
 
-import com.jayway.restassured.RestAssured;
 import com.jayway.restassured.http.ContentType;
 import com.jayway.restassured.response.Cookie;
 import com.jayway.restassured.response.Header;
@@ -67,8 +65,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static com.jayway.restassured.RestAssured.given;
-import static com.jayway.restassured.config.ConnectionConfig.connectionConfig;
-import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
 import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
 import static org.hamcrest.CoreMatchers.anyOf;
@@ -133,7 +129,6 @@ public class GatewayBasicFuncTest {
   public static void setupSuite() throws Exception {
     //Log.setLog( new NoOpLogger() );
     LOG_ENTER();
-    RestAssured.config = newConfig().connectionConfig(connectionConfig().dontCloseIdleConnectionsAfterEachResponse()
);
     GatewayTestConfig config = new GatewayTestConfig();
     config.setGatewayPath( "gateway" );
     driver.setResourceBase(GatewayBasicFuncTest.class);

http://git-wip-us.apache.org/repos/asf/knox/blob/7861f20e/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayMultiFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayMultiFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayMultiFuncTest.java
index 9a6d9c4..3271dab 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayMultiFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayMultiFuncTest.java
@@ -26,8 +26,8 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.UUID;
 
-import com.jayway.restassured.RestAssured;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.hadoop.gateway.security.ldap.SimpleLdapDirectoryServer;
 import org.apache.hadoop.gateway.services.DefaultGatewayServices;
@@ -37,10 +37,22 @@ import org.apache.hadoop.gateway.services.topology.TopologyService;
 import org.apache.hadoop.test.TestUtils;
 import org.apache.hadoop.test.category.ReleaseTest;
 import org.apache.hadoop.test.mock.MockServer;
+import org.apache.http.HttpHost;
 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.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.impl.client.BasicAuthCache;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
 import org.apache.log4j.Appender;
 import org.hamcrest.MatcherAssert;
-import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -49,14 +61,15 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static com.jayway.restassured.RestAssured.given;
-import static com.jayway.restassured.config.ConnectionConfig.connectionConfig;
-import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
 import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
+import static org.hamcrest.CoreMatchers.endsWith;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
+import static org.xmlmatchers.XmlMatchers.hasXPath;
+import static org.xmlmatchers.transform.XmlConverters.the;
 
 @Category(ReleaseTest.class)
 public class GatewayMultiFuncTest {
@@ -70,13 +83,10 @@ public class GatewayMultiFuncTest {
   private static GatewayServer gateway;
   private static int gatewayPort;
   private static String gatewayUrl;
-  private static String clusterUrl;
   private static SimpleLdapDirectoryServer ldap;
   private static TcpTransport ldapTransport;
-  private static int ldapPort;
   private static Properties params;
   private static TopologyService topos;
-  private static MockServer mockWebHdfs;
 
   @BeforeClass
   public static void setupSuite() throws Exception {
@@ -97,12 +107,6 @@ public class GatewayMultiFuncTest {
     LOG_EXIT();
   }
 
-  @After
-  public void cleanupTest() throws Exception {
-    FileUtils.cleanDirectory( new File( config.getGatewayTopologyDir() ) );
-    FileUtils.cleanDirectory( new File( config.getGatewayDeploymentDir() ) );
-  }
-
   public static void setupLdap() throws Exception {
     URL usersUrl = TestUtils.getResourceUrl( DAT, "users.ldif" );
     ldapTransport = new TcpTransport( 0 );
@@ -136,14 +140,9 @@ public class GatewayMultiFuncTest {
     File deployDir = new File( config.getGatewayDeploymentDir() );
     deployDir.mkdirs();
 
-    setupMockServers();
     startGatewayServer();
   }
 
-  public static void setupMockServers() throws Exception {
-    mockWebHdfs = new MockServer( "WEBHDFS", true );
-  }
-
   public static void startGatewayServer() throws Exception {
     services = new DefaultGatewayServices();
     Map<String,String> options = new HashMap<String,String>();
@@ -161,13 +160,11 @@ public class GatewayMultiFuncTest {
 
     gatewayPort = gateway.getAddresses()[0].getPort();
     gatewayUrl = "http://localhost:" + gatewayPort + "/" + config.getGatewayPath();
-    clusterUrl = gatewayUrl + "/test-topology";
 
     LOG.info( "Gateway port = " + gateway.getAddresses()[ 0 ].getPort() );
 
     params = new Properties();
     params.put( "LDAP_URL", "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort()
);
-    params.put( "WEBHDFS_URL", "http://localhost:" + mockWebHdfs.getPort() );
   }
 
   @Test( timeout = TestUtils.MEDIUM_TIMEOUT )
@@ -176,10 +173,12 @@ public class GatewayMultiFuncTest {
 
     MockServer mock = new MockServer( "REPEAT", true );
 
+    params = new Properties();
+    params.put( "LDAP_URL", "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort()
);
     params.put( "MOCK_SERVER_PORT", mock.getPort() );
 
     String topoStr = TestUtils.merge( DAT, "topologies/test-knox678-utf8-chars-topology.xml",
params );
-    File topoFile = new File( config.getGatewayTopologyDir(), "topology.xml" );
+    File topoFile = new File( config.getGatewayTopologyDir(), "knox678.xml" );
     FileUtils.writeStringToFile( topoFile, topoStr );
 
     topos.reloadTopologies();
@@ -187,7 +186,8 @@ public class GatewayMultiFuncTest {
     String uname = "guest";
     String pword = uname + "-password";
 
-    mock.expect().respond().contentType( "application/json" ).content( "{\"msg\":\"H\u00eallo\"}",
Charset.forName( "UTF8" ) );
+    mock.expect().method( "GET" )
+        .respond().contentType( "application/json" ).contentLength( -1 ).content( "{\"msg\":\"H\u00eallo\"}",
Charset.forName( "UTF8" ) );
     given()
         //.log().all()
         .auth().preemptive().basic( uname, pword )
@@ -195,10 +195,11 @@ public class GatewayMultiFuncTest {
         //.log().all()
         .statusCode( HttpStatus.SC_OK )
         .body( "msg", is( "H\u00eallo" ) )
-        .when().get( gatewayUrl + "/topology/repeat" );
+        .when().get( gatewayUrl + "/knox678/repeat" );
     assertThat( mock.isEmpty(), is(true) );
 
-    mock.expect().respond().contentType( "application/json" ).content( "{\"msg\":\"H\u00eallo\"}",
Charset.forName( "UTF8" ) );
+    mock.expect().method( "GET" )
+        .respond().contentType( "application/json" ).contentLength( -1 ).content( "{\"msg\":\"H\u00eallo\"}",
Charset.forName( "UTF8" ) );
     given()
         //.log().all()
         .auth().preemptive().basic( uname, pword )
@@ -206,10 +207,11 @@ public class GatewayMultiFuncTest {
         //.log().all()
         .statusCode( HttpStatus.SC_OK )
         .body( "msg", is( "H\u00eallo" ) )
-        .when().get( gatewayUrl + "/topology/repeat" );
+        .when().get( gatewayUrl + "/knox678/repeat" );
     assertThat( mock.isEmpty(), is(true) );
 
-    mock.expect().respond().contentType( "application/octet-stream" ).content( "H\u00eallo".getBytes()
);
+    mock.expect().method( "GET" )
+        .respond().contentType( "application/octet-stream" ).contentLength( -1 ).content(
"H\u00eallo".getBytes() );
     byte[] body = given()
         //.log().all()
         .auth().preemptive().basic( uname, pword )
@@ -217,11 +219,100 @@ public class GatewayMultiFuncTest {
         //.log().all()
         .statusCode( HttpStatus.SC_OK )
         //.contentType( "application/octet-stream" )
-        .when().get( gatewayUrl + "/topology/repeat" ).andReturn().asByteArray();
+        .when().get( gatewayUrl + "/knox678/repeat" ).andReturn().asByteArray();
     assertThat( body, is(equalTo("H\u00eallo".getBytes())) );
     assertThat( mock.isEmpty(), is(true) );
 
+    mock.stop();
+
+    LOG_EXIT();
+  }
+
+  @Test( timeout = TestUtils.MEDIUM_TIMEOUT )
+  public void testPostWithContentTypeKnox681() throws Exception {
+    LOG_ENTER();
+
+    MockServer mock = new MockServer( "REPEAT", true );
+
+    params = new Properties();
+    params.put( "MOCK_SERVER_PORT", mock.getPort() );
+    params.put( "LDAP_URL", "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort()
);
+
+    String topoStr = TestUtils.merge( DAT, "topologies/test-knox678-utf8-chars-topology.xml",
params );
+    File topoFile = new File( config.getGatewayTopologyDir(), "knox681.xml" );
+    FileUtils.writeStringToFile( topoFile, topoStr );
+
+    topos.reloadTopologies();
+
+    mock
+        .expect()
+        .method( "PUT" )
+        .pathInfo( "/repeat-context/" )
+        .respond()
+        .status( HttpStatus.SC_CREATED )
+        .content( "{\"name\":\"value\"}".getBytes() )
+        .contentLength( -1 )
+        .contentType( "application/json; charset=UTF-8" )
+        .header( "Location", gatewayUrl + "/knox681/repeat" );
+
+    String uname = "guest";
+    String pword = uname + "-password";
+
+    HttpHost targetHost = new HttpHost( "localhost", gatewayPort, "http" );
+    CredentialsProvider credsProvider = new BasicCredentialsProvider();
+    credsProvider.setCredentials(
+        new AuthScope( targetHost.getHostName(), targetHost.getPort() ),
+        new UsernamePasswordCredentials( uname, pword ) );
+
+    AuthCache authCache = new BasicAuthCache();
+    BasicScheme basicAuth = new BasicScheme();
+    authCache.put( targetHost, basicAuth );
+
+    HttpClientContext context = HttpClientContext.create();
+    context.setCredentialsProvider( credsProvider );
+    context.setAuthCache( authCache );
+
+    CloseableHttpClient client = HttpClients.createDefault();
+    HttpPut request = new HttpPut( gatewayUrl + "/knox681/repeat" );
+    request.addHeader( "X-XSRF-Header", "jksdhfkhdsf" );
+    request.addHeader( "Content-Type", "application/json" );
+    CloseableHttpResponse response = client.execute( request, context );
+    assertThat( response.getStatusLine().getStatusCode(), is( HttpStatus.SC_CREATED ) );
+    assertThat( response.getFirstHeader( "Location" ).getValue(), endsWith("/gateway/knox681/repeat"
) );
+    assertThat( response.getFirstHeader( "Content-Type" ).getValue(), is("application/json;
charset=UTF-8") );
+    String body = new String( IOUtils.toByteArray( response.getEntity().getContent() ), Charset.forName(
"UTF-8" ) );
+    assertThat( body, is( "{\"name\":\"value\"}" ) );
+    response.close();
+    client.close();
+
+    mock
+        .expect()
+        .method( "PUT" )
+        .pathInfo( "/repeat-context/" )
+        .respond()
+        .status( HttpStatus.SC_CREATED )
+        .content( "<test-xml/>".getBytes() )
+        .contentType( "application/xml; charset=UTF-8" )
+        .header( "Location", gatewayUrl + "/knox681/repeat" );
+
+    client = HttpClients.createDefault();
+    request = new HttpPut( gatewayUrl + "/knox681/repeat" );
+    request.addHeader( "X-XSRF-Header", "jksdhfkhdsf" );
+    request.addHeader( "Content-Type", "application/xml" );
+    response = client.execute( request, context );
+    assertThat( response.getStatusLine().getStatusCode(), is( HttpStatus.SC_CREATED ) );
+    assertThat( response.getFirstHeader( "Location" ).getValue(), endsWith("/gateway/knox681/repeat"
) );
+    assertThat( response.getFirstHeader( "Content-Type" ).getValue(), is("application/xml;
charset=UTF-8") );
+    body = new String( IOUtils.toByteArray( response.getEntity().getContent() ), Charset.forName(
"UTF-8" ) );
+    assertThat( the(body), hasXPath( "/test-xml" ) );
+    response.close();
+    client.close();
+
+    mock.stop();
+
     LOG_EXIT();
   }
 
 }
+
+

http://git-wip-us.apache.org/repos/asf/knox/blob/7861f20e/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
index a740d96..d59f194 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
@@ -17,7 +17,6 @@
  */
 package org.apache.hadoop.gateway;
 
-import com.jayway.restassured.RestAssured;
 import com.mycila.xmltool.XMLDoc;
 import com.mycila.xmltool.XMLTag;
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
@@ -41,7 +40,6 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.ServerSocket;
 import java.net.URL;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -49,8 +47,6 @@ import java.util.Map;
 import java.util.UUID;
 
 import static com.jayway.restassured.RestAssured.given;
-import static com.jayway.restassured.config.ConnectionConfig.connectionConfig;
-import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
 import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
 import static org.hamcrest.CoreMatchers.is;
@@ -73,7 +69,6 @@ public class GatewaySampleFuncTest {
   @BeforeClass
   public static void setupSuite() throws Exception {
     LOG_ENTER();
-    RestAssured.config = newConfig().connectionConfig(connectionConfig().closeIdleConnectionsAfterEachResponse());
     //appenders = NoOpAppender.setUp();
     setupLdap();
     setupGateway();

http://git-wip-us.apache.org/repos/asf/knox/blob/7861f20e/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySslFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySslFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySslFuncTest.java
index 1bbb402..163b209 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySslFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySslFuncTest.java
@@ -40,7 +40,6 @@ import javax.net.ssl.TrustManager;
 import javax.net.ssl.X509TrustManager;
 import javax.xml.transform.stream.StreamSource;
 
-import com.jayway.restassured.RestAssured;
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.hadoop.gateway.security.ldap.SimpleLdapDirectoryServer;
@@ -75,8 +74,6 @@ import org.junit.experimental.categories.Category;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static com.jayway.restassured.config.ConnectionConfig.connectionConfig;
-import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
 import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
 import static org.hamcrest.CoreMatchers.notNullValue;
@@ -108,7 +105,6 @@ public class GatewaySslFuncTest {
   @BeforeClass
   public static void setupSuite() throws Exception {
     LOG_ENTER();
-    RestAssured.config = newConfig().connectionConfig(connectionConfig().closeIdleConnectionsAfterEachResponse());
     //appenders = NoOpAppender.setUp();
     setupLdap();
     setupGateway();

http://git-wip-us.apache.org/repos/asf/knox/blob/7861f20e/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
index 9171e7c..5acd34e 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
@@ -178,6 +178,7 @@ public class OozieServiceDefinitionTest {
     HttpServletRequest servletRequest = EasyMock.createNiceMock( HttpServletRequest.class
);
     EasyMock.expect( servletRequest.getInputStream() ).andReturn( new MockServletInputStream(
TestUtils.getResourceStream( OozieServiceDefinitionTest.class, testResource ) ) ).anyTimes();
     EasyMock.expect( servletRequest.getContentType() ).andReturn( "text/xml" ).anyTimes();
+    EasyMock.expect( servletRequest.getContentLength() ).andReturn( -1 ).anyTimes();
 
     FilterConfig filterConfig = EasyMock.createNiceMock( FilterConfig.class );
     EasyMock.expect( filterConfig.getServletContext() ).andReturn( servletContext ).anyTimes();

http://git-wip-us.apache.org/repos/asf/knox/blob/7861f20e/gateway-test/src/test/resources/org/apache/hadoop/gateway/GatewayMultiFuncTest/topologies/test-knox678-utf8-chars-topology.xml
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/resources/org/apache/hadoop/gateway/GatewayMultiFuncTest/topologies/test-knox678-utf8-chars-topology.xml
b/gateway-test/src/test/resources/org/apache/hadoop/gateway/GatewayMultiFuncTest/topologies/test-knox678-utf8-chars-topology.xml
index fbbab48..7a0a916 100644
--- a/gateway-test/src/test/resources/org/apache/hadoop/gateway/GatewayMultiFuncTest/topologies/test-knox678-utf8-chars-topology.xml
+++ b/gateway-test/src/test/resources/org/apache/hadoop/gateway/GatewayMultiFuncTest/topologies/test-knox678-utf8-chars-topology.xml
@@ -49,6 +49,6 @@
     </gateway>
     <service>
         <role>REPEAT</role>
-        <url>http://localhost:${MOCK_SERVER_PORT}/repeat-context</url>
+        <url>http://localhost:$MOCK_SERVER_PORT/repeat-context</url>
     </service>
 </topology>


Mime
View raw message