knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject git commit: Fix for Jira KNOX-58: NameNode endpoint exposed to gateway clients in runtime exception
Date Mon, 22 Apr 2013 21:41:09 GMT
Updated Branches:
  refs/heads/master d205789ab -> b2031a71a


Fix for Jira KNOX-58: NameNode endpoint exposed to gateway clients in runtime exception


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

Branch: refs/heads/master
Commit: b2031a71a631ea55f8450616cb45df871cd38525
Parents: d205789
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Mon Apr 22 17:41:00 2013 -0400
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Mon Apr 22 17:41:00 2013 -0400

----------------------------------------------------------------------
 .../org/apache/hadoop/gateway/GatewayMessages.java |    3 +
 .../apache/hadoop/gateway/GatewayResources.java    |    3 +
 .../gateway/dispatch/HttpClientDispatch.java       |   12 +++-
 .../gateway/dispatch/HttpClientDispatchTest.java   |   70 +++++++++++++++
 4 files changed, 87 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/b2031a71/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
index f661cd9..eb3e3dc 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
@@ -142,5 +142,8 @@ public interface GatewayMessages {
 
   @Message( level = MessageLevel.DEBUG, text = "Dispatching request: {0} {1}" )
   void dispatchRequest( String method, URI uri );
+  
+  @Message( level = MessageLevel.WARN, text = "Connection exception dispatching request:
{0} {1}" )
+  void dispatchServiceConnectionException( URI uri, @StackTrace(level=MessageLevel.DEBUG)
Exception e );
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/b2031a71/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
index bf42b57..3441d58 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
@@ -32,4 +32,7 @@ public interface GatewayResources {
   @Resource( text="Apache Hadoop Gateway" )
   String gatewayServletInfo();
 
+  @Resource( text="Service connectivity error." )
+  String dispatchConnectionError();
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/b2031a71/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 f64b76e..a755a90 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
@@ -18,7 +18,9 @@
 package org.apache.hadoop.gateway.dispatch;
 
 import org.apache.hadoop.gateway.GatewayMessages;
+import org.apache.hadoop.gateway.GatewayResources;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
+import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
@@ -45,6 +47,7 @@ import java.net.URISyntaxException;
 public class HttpClientDispatch extends AbstractGatewayDispatch {
 
   private static GatewayMessages LOG = MessagesFactory.get( GatewayMessages.class );
+  private static GatewayResources RES = ResourcesFactory.get( GatewayResources.class );
 
   protected void executeRequest(
       HttpUriRequest outboundRequest,
@@ -53,7 +56,14 @@ public class HttpClientDispatch extends AbstractGatewayDispatch {
           throws IOException {
     LOG.dispatchRequest( outboundRequest.getMethod(), outboundRequest.getURI() );
     HttpClient client = new DefaultHttpClient();
-    HttpResponse inboundResponse = client.execute( outboundRequest );
+    HttpResponse inboundResponse;
+    try {
+      inboundResponse = client.execute( outboundRequest );
+    } catch (IOException e) {
+      // we do not want to expose back end host. port end points to clients, see JIRA KNOX-58
+      LOG.dispatchServiceConnectionException( outboundRequest.getURI(), e );
+      throw new IOException( RES.dispatchConnectionError() );
+    }
 
     // Copy the client respond header to the server respond.
     outboundResponse.setStatus( inboundResponse.getStatusLine().getStatusCode() );

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/b2031a71/gateway-server/src/test/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatchTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatchTest.java
b/gateway-server/src/test/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatchTest.java
new file mode 100644
index 0000000..331d46a
--- /dev/null
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatchTest.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.dispatch;
+
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.params.BasicHttpParams;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.UnknownHostException;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+public class HttpClientDispatchTest {
+
+  // Make sure Hadoop cluster topology isn't exposed to client when there is a connectivity
issue.
+  @Test
+  public void testJiraKnox58() throws URISyntaxException {
+
+    URI uri = new URI( "http://unreachable-host" );
+    BasicHttpParams params = new BasicHttpParams();
+
+    HttpUriRequest outboundRequest = EasyMock.createNiceMock( HttpUriRequest.class );
+    EasyMock.expect( outboundRequest.getMethod() ).andReturn( "GET" ).anyTimes();
+    EasyMock.expect( outboundRequest.getURI() ).andReturn( uri  ).anyTimes();
+    EasyMock.expect( outboundRequest.getParams() ).andReturn( params ).anyTimes();
+
+    HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class
);
+
+    HttpServletResponse outboundResponse = EasyMock.createNiceMock( HttpServletResponse.class
);
+
+    EasyMock.replay( outboundRequest, inboundRequest, outboundResponse );
+
+    HttpClientDispatch dispatch = new HttpClientDispatch();
+    try {
+      dispatch.executeRequest( outboundRequest, inboundRequest, outboundResponse );
+      fail( "Should have thrown IOException" );
+    } catch( IOException e ) {
+      assertThat( e.getMessage(), not( containsString( "unreachable-host" ) ) );
+      assertThat( e, not( instanceOf( UnknownHostException.class ) ) ) ;
+      assertThat( "Message needs meaningful content.", e.getMessage().trim().length(), greaterThan(
12 ) );
+    }
+  }
+
+}


Mime
View raw message