knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject [1/3] knox git commit: Revert "[KNOX-681] - A PUT with Content-Type application/xml but no body causes NullPointerException"
Date Sat, 05 Mar 2016 21:59:52 GMT
Repository: knox
Updated Branches:
  refs/heads/master 8a6545109 -> 3d37f7b27


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

This reverts commit 8a6545109f257977838e015820ca9f1ca18aac74.


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

Branch: refs/heads/master
Commit: 8bee25912d72500a800e1759185ef5330cc3a995
Parents: 8a65451
Author: Kevin Minder <kminder@apache.org>
Authored: Sat Mar 5 15:44:58 2016 -0500
Committer: Kevin Minder <kminder@apache.org>
Committed: Sat Mar 5 15:44:58 2016 -0500

----------------------------------------------------------------------
 CHANGES                                         |   1 -
 .../filter/rewrite/impl/UrlRewriteRequest.java  |  19 ++--
 .../rewrite/impl/xml/XmlFilterReader.java       |   6 +-
 .../hadoop/gateway/GatewayMultiFuncTest.java    | 102 +------------------
 .../gateway/OozieServiceDefinitionTest.java     |   1 -
 .../test-knox678-utf8-chars-topology.xml        |   2 +-
 6 files changed, 12 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/8bee2591/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index a757eaa..06efd2d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,7 +10,6 @@ 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/8bee2591/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 fd6cd24..4197d65 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,14 +211,11 @@ public class UrlRewriteRequest extends GatewayRequestWrapper implements
Resolver
 
   @Override
   public ServletInputStream getInputStream() throws IOException {
-    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;
+    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 );
   }
 
   @Override
@@ -229,11 +226,7 @@ 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.
-    int contentLength = super.getContentLength();
-    if( contentLength > 0 ) {
-      contentLength = -1;
-    }
-    return contentLength;
+    return -1;
   }
 
   private UrlRewriteFilterContentDescriptor getRewriteFilterConfig( String filterName, MimeType
mimeType ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/8bee2591/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 cfaebd2..fe1682c 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,12 +120,10 @@ 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 new RuntimeException( e );
+        } catch( Exception e ) {
+          throw e instanceof IOException ? (IOException)e : new IOException( e );
         }
         available = buffer.length() - offset;
       } else {

http://git-wip-us.apache.org/repos/asf/knox/blob/8bee2591/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 cb3a1a1..8c29ce5 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,20 +37,7 @@ 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;
@@ -62,15 +49,14 @@ 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 {
@@ -239,86 +225,4 @@ public class GatewayMultiFuncTest {
     LOG_EXIT();
   }
 
-  @Test( timeout = TestUtils.MEDIUM_TIMEOUT )
-  public void testPostWithContentTypeKnox681() throws Exception {
-    LOG_ENTER();
-
-    MockServer mock = new MockServer( "REPEAT", true );
-
-    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" );
-    FileUtils.writeStringToFile( topoFile, topoStr );
-
-    topos.reloadTopologies();
-
-    mock
-        .expect()
-        .method( "PUT" )
-        .pathInfo( "/repeat-context/" )
-        .respond()
-        .status( HttpStatus.SC_CREATED )
-        .content( "{\"name\":\"value\"}".getBytes() )
-        .contentType( "application/json; charset=UTF-8" )
-        .header( "Location", gatewayUrl + "/topology/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 + "/topology/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/topology/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 + "/topology/repeat" );
-
-    client = HttpClients.createDefault();
-    request = new HttpPut( gatewayUrl + "/topology/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/topology/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();
-
-    LOG_EXIT();
-  }
-
 }
-
-

http://git-wip-us.apache.org/repos/asf/knox/blob/8bee2591/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 6a91a87..b2f982b 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
@@ -181,7 +181,6 @@ 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/8bee2591/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 7a0a916..fbbab48 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