You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by mo...@apache.org on 2017/09/01 13:17:01 UTC
[03/64] [partial] knox git commit: KNOX-998 - Refactoring save 1
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/TestFilterChain.java
----------------------------------------------------------------------
diff --git a/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/TestFilterChain.java b/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/TestFilterChain.java
deleted file mode 100644
index 1ab8e22..0000000
--- a/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/TestFilterChain.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.filter;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import java.io.IOException;
-import java.util.Stack;
-
-public class TestFilterChain extends Stack<Filter> implements FilterChain {
- @Override
- public void doFilter( ServletRequest request, ServletResponse response ) throws IOException, ServletException {
- if( !isEmpty() ) pop().doFilter( request, response, this );
- }
-}
-
-
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/XForwardHeaderFilterTest.java
----------------------------------------------------------------------
diff --git a/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/XForwardHeaderFilterTest.java b/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/XForwardHeaderFilterTest.java
deleted file mode 100644
index d1d1a99..0000000
--- a/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/XForwardHeaderFilterTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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.filter;
-
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public class XForwardHeaderFilterTest {
-
- public static class AssertXForwardedHeaders extends TestFilterAdapter {
- @Override
- public void doFilter( HttpServletRequest request, HttpServletResponse response, FilterChain chain ) throws IOException, ServletException {
- assertThat( request.getHeader( "X-Forwarded-For" ), is( "127.0.0.1" ) );
- assertThat( request.getHeader( "X-Forwarded-Proto" ), is( "http" ) );
- assertThat( request.getHeader( "X-Forwarded-Port" ), is( "8888" ) );
- assertThat( request.getHeader( "X-Forwarded-Host" ), is( "localhost:8888" ) );
- assertThat( request.getHeader( "X-Forwarded-Server" ), is( "localhost" ) );
- assertThat( request.getHeader( "X-Forwarded-Context" ), is( "/context" ) );
- }
- }
-
- @Test
- public void testXForwardHeaders() throws ServletException, IOException {
- HttpServletRequest request = EasyMock.createNiceMock( HttpServletRequest.class );
- EasyMock.expect( request.getRemoteAddr() ).andReturn( "127.0.0.1" ).anyTimes();
- EasyMock.expect( request.isSecure() ).andReturn( false ).anyTimes();
- EasyMock.expect( request.getLocalPort() ).andReturn( 8888 ).anyTimes();
- EasyMock.expect( request.getHeader( "Host" ) ).andReturn( "localhost:8888" ).anyTimes();
- EasyMock.expect( request.getServerName() ).andReturn( "localhost" ).anyTimes();
- EasyMock.expect( request.getContextPath() ).andReturn( "/context" ).anyTimes();
- HttpServletResponse response = EasyMock.createNiceMock( HttpServletResponse.class );
- EasyMock.replay( request, response );
-
- TestFilterChain chain = new TestFilterChain();
-
- XForwardedHeaderFilter filter = new XForwardedHeaderFilter();
-
- chain.push( new AssertXForwardedHeaders() );
- chain.push( filter );
- chain.doFilter( request, response );
- }
-
- public static class AssertProxiedXForwardedHeaders extends TestFilterAdapter {
- @Override
- public void doFilter( HttpServletRequest request, HttpServletResponse response, FilterChain chain ) throws IOException, ServletException {
- assertThat( request.getHeader( "X-Forwarded-For" ), is( "127.0.0.0,127.0.0.1" ) );
- assertThat( request.getHeader( "X-Forwarded-Proto" ), is( "https" ) );
- assertThat( request.getHeader( "X-Forwarded-Port" ), is( "9999" ) );
- assertThat( request.getHeader( "X-Forwarded-Host" ), is( "remotehost:9999" ) );
- assertThat( request.getHeader( "X-Forwarded-Server" ), is( "localhost" ) );
- assertThat( request.getHeader( "X-Forwarded-Context" ), is( "/upstream/context" ) );
- }
- }
-
- @Test
- public void testProxiedXForwardHeaders() throws ServletException, IOException {
- HttpServletRequest request = EasyMock.createNiceMock( HttpServletRequest.class );
-
- EasyMock.expect( request.getHeader( "X-Forwarded-For" ) ).andReturn( "127.0.0.0" ).anyTimes();
- EasyMock.expect( request.getHeader( "X-Forwarded-Proto" ) ).andReturn( "https" ).anyTimes();
- EasyMock.expect( request.getHeader( "X-Forwarded-Port" ) ).andReturn( "9999" ).anyTimes();
- EasyMock.expect( request.getHeader( "X-Forwarded-Host" ) ).andReturn( "remotehost:9999" ).anyTimes();
- EasyMock.expect( request.getHeader( "X-Forwarded-Server" ) ).andReturn( "remotehost" ).anyTimes();
- EasyMock.expect( request.getHeader( "X-Forwarded-Context" ) ).andReturn( "/upstream" ).anyTimes();
-
- EasyMock.expect( request.getRemoteAddr() ).andReturn( "127.0.0.1" ).anyTimes();
- EasyMock.expect( request.isSecure() ).andReturn( false ).anyTimes();
- EasyMock.expect( request.getLocalPort() ).andReturn( 8888 ).anyTimes();
- EasyMock.expect( request.getHeader( "Host" ) ).andReturn( "localhost:8888" ).anyTimes();
- EasyMock.expect( request.getServerName() ).andReturn( "localhost" ).anyTimes();
- EasyMock.expect( request.getContextPath() ).andReturn( "/context" ).anyTimes();
-
- HttpServletResponse response = EasyMock.createNiceMock( HttpServletResponse.class );
- EasyMock.replay( request, response );
-
- TestFilterChain chain = new TestFilterChain();
-
- XForwardedHeaderFilter filter = new XForwardedHeaderFilter();
-
- chain.push( new AssertProxiedXForwardedHeaders() );
- chain.push( filter );
- chain.doFilter( request, response );
- }
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/CompositeEnumerationTest.java
----------------------------------------------------------------------
diff --git a/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/CompositeEnumerationTest.java b/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/CompositeEnumerationTest.java
new file mode 100644
index 0000000..25e9d5e
--- /dev/null
+++ b/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/CompositeEnumerationTest.java
@@ -0,0 +1,117 @@
+/**
+ * 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.knox.gateway.filter;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+import static junit.framework.TestCase.fail;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class CompositeEnumerationTest {
+
+ @Test
+ public void testBasics() {
+
+ String[] a = new String[]{ "1", "2" };
+ Enumeration<String> ea = Collections.enumeration( Arrays.asList( a ) );
+
+ String[] b = new String[]{ "3", "4" };
+ Enumeration<String> eb = Collections.enumeration( Arrays.asList( b ) );
+
+ CompositeEnumeration<String> ce = new CompositeEnumeration<String>( ea, eb );
+
+ assertThat( ce.nextElement(), is( "1" ) );
+ assertThat( ce.nextElement(), is( "2" ) );
+ assertThat( ce.nextElement(), is( "3" ) );
+ assertThat( ce.nextElement(), is( "4" ) );
+ assertThat( ce.hasMoreElements(), is( false ) );
+
+ }
+
+ @Test
+ public void testSingleValues() {
+ String[] a = new String[]{ "1" };
+ Enumeration<String> ea = Collections.enumeration( Arrays.asList( a ) );
+
+ String[] b = new String[]{ "2" };
+ Enumeration<String> eb = Collections.enumeration( Arrays.asList( b ) );
+
+ CompositeEnumeration<String> ce = new CompositeEnumeration<String>( ea, eb );
+
+ assertThat( ce.nextElement(), is( "1" ) );
+ assertThat( ce.nextElement(), is( "2" ) );
+ assertThat( ce.hasMoreElements(), is( false ) );
+ }
+
+ @Test
+ public void testEmptyEnumerations() {
+
+ String[] a = new String[]{ "1", "2" };
+ String[] b = new String[]{ "3", "4" };
+ String[] c = new String[]{};
+
+ Enumeration<String> e1 = Collections.enumeration( Arrays.asList( a ) );
+ Enumeration<String> e2 = Collections.enumeration( Arrays.asList( c ) );
+ CompositeEnumeration<String> ce = new CompositeEnumeration<String>( e1, e2 );
+ assertThat( ce.nextElement(), is( "1" ) );
+ assertThat( ce.nextElement(), is( "2" ) );
+ assertThat( ce.hasMoreElements(), is( false ) );
+
+ e1 = Collections.enumeration( Arrays.asList( c ) );
+ e2 = Collections.enumeration( Arrays.asList( a ) );
+ ce = new CompositeEnumeration<String>( e1, e2 );
+ assertThat( ce.nextElement(), is( "1" ) );
+ assertThat( ce.nextElement(), is( "2" ) );
+ assertThat( ce.hasMoreElements(), is( false ) );
+
+ e1 = Collections.enumeration( Arrays.asList( c ) );
+ e2 = Collections.enumeration( Arrays.asList( c ) );
+ ce = new CompositeEnumeration<String>( e1, e2 );
+ assertThat( ce.hasMoreElements(), is( false ) );
+ }
+
+ @Test
+ public void testEmpty() {
+ CompositeEnumeration<String> ce = new CompositeEnumeration<String>();
+ assertThat( ce.hasMoreElements(), is( false ) );
+
+ try {
+ ce.nextElement();
+ fail( "Should have throws NoSuchElementExcpetion" );
+ } catch( NoSuchElementException e ) {
+ // Expected.
+ }
+ }
+
+ @Test
+ public void testNulls() {
+ try {
+ CompositeEnumeration<String> ce = new CompositeEnumeration<String>( null );
+ fail( "Expected IllegalArgumentException" );
+ } catch( IllegalArgumentException e ) {
+ // Expected.
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/TestFilterAdapter.java
----------------------------------------------------------------------
diff --git a/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/TestFilterAdapter.java b/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/TestFilterAdapter.java
new file mode 100644
index 0000000..88a1e29
--- /dev/null
+++ b/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/TestFilterAdapter.java
@@ -0,0 +1,45 @@
+/**
+ * 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.knox.gateway.filter;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public abstract class TestFilterAdapter implements Filter {
+
+ public abstract void doFilter( HttpServletRequest request, HttpServletResponse response, FilterChain chain ) throws IOException, ServletException;
+
+ @Override
+ public void init( FilterConfig filterConfig ) throws ServletException {}
+
+ @Override
+ public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException, ServletException {
+ doFilter( (HttpServletRequest)request, (HttpServletResponse)response, chain );
+ }
+
+ @Override
+ public void destroy() {}
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/TestFilterChain.java
----------------------------------------------------------------------
diff --git a/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/TestFilterChain.java b/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/TestFilterChain.java
new file mode 100644
index 0000000..385bf58
--- /dev/null
+++ b/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/TestFilterChain.java
@@ -0,0 +1,35 @@
+/**
+ * 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.knox.gateway.filter;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.IOException;
+import java.util.Stack;
+
+public class TestFilterChain extends Stack<Filter> implements FilterChain {
+ @Override
+ public void doFilter( ServletRequest request, ServletResponse response ) throws IOException, ServletException {
+ if( !isEmpty() ) pop().doFilter( request, response, this );
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/XForwardHeaderFilterTest.java
----------------------------------------------------------------------
diff --git a/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/XForwardHeaderFilterTest.java b/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/XForwardHeaderFilterTest.java
new file mode 100644
index 0000000..1d9c64c
--- /dev/null
+++ b/gateway-server-xforwarded-filter/src/test/java/org/apache/knox/gateway/filter/XForwardHeaderFilterTest.java
@@ -0,0 +1,108 @@
+/**
+ * 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.knox.gateway.filter;
+
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class XForwardHeaderFilterTest {
+
+ public static class AssertXForwardedHeaders extends TestFilterAdapter {
+ @Override
+ public void doFilter( HttpServletRequest request, HttpServletResponse response, FilterChain chain ) throws IOException, ServletException {
+ assertThat( request.getHeader( "X-Forwarded-For" ), is( "127.0.0.1" ) );
+ assertThat( request.getHeader( "X-Forwarded-Proto" ), is( "http" ) );
+ assertThat( request.getHeader( "X-Forwarded-Port" ), is( "8888" ) );
+ assertThat( request.getHeader( "X-Forwarded-Host" ), is( "localhost:8888" ) );
+ assertThat( request.getHeader( "X-Forwarded-Server" ), is( "localhost" ) );
+ assertThat( request.getHeader( "X-Forwarded-Context" ), is( "/context" ) );
+ }
+ }
+
+ @Test
+ public void testXForwardHeaders() throws ServletException, IOException {
+ HttpServletRequest request = EasyMock.createNiceMock( HttpServletRequest.class );
+ EasyMock.expect( request.getRemoteAddr() ).andReturn( "127.0.0.1" ).anyTimes();
+ EasyMock.expect( request.isSecure() ).andReturn( false ).anyTimes();
+ EasyMock.expect( request.getLocalPort() ).andReturn( 8888 ).anyTimes();
+ EasyMock.expect( request.getHeader( "Host" ) ).andReturn( "localhost:8888" ).anyTimes();
+ EasyMock.expect( request.getServerName() ).andReturn( "localhost" ).anyTimes();
+ EasyMock.expect( request.getContextPath() ).andReturn( "/context" ).anyTimes();
+ HttpServletResponse response = EasyMock.createNiceMock( HttpServletResponse.class );
+ EasyMock.replay( request, response );
+
+ TestFilterChain chain = new TestFilterChain();
+
+ XForwardedHeaderFilter filter = new XForwardedHeaderFilter();
+
+ chain.push( new AssertXForwardedHeaders() );
+ chain.push( filter );
+ chain.doFilter( request, response );
+ }
+
+ public static class AssertProxiedXForwardedHeaders extends TestFilterAdapter {
+ @Override
+ public void doFilter( HttpServletRequest request, HttpServletResponse response, FilterChain chain ) throws IOException, ServletException {
+ assertThat( request.getHeader( "X-Forwarded-For" ), is( "127.0.0.0,127.0.0.1" ) );
+ assertThat( request.getHeader( "X-Forwarded-Proto" ), is( "https" ) );
+ assertThat( request.getHeader( "X-Forwarded-Port" ), is( "9999" ) );
+ assertThat( request.getHeader( "X-Forwarded-Host" ), is( "remotehost:9999" ) );
+ assertThat( request.getHeader( "X-Forwarded-Server" ), is( "localhost" ) );
+ assertThat( request.getHeader( "X-Forwarded-Context" ), is( "/upstream/context" ) );
+ }
+ }
+
+ @Test
+ public void testProxiedXForwardHeaders() throws ServletException, IOException {
+ HttpServletRequest request = EasyMock.createNiceMock( HttpServletRequest.class );
+
+ EasyMock.expect( request.getHeader( "X-Forwarded-For" ) ).andReturn( "127.0.0.0" ).anyTimes();
+ EasyMock.expect( request.getHeader( "X-Forwarded-Proto" ) ).andReturn( "https" ).anyTimes();
+ EasyMock.expect( request.getHeader( "X-Forwarded-Port" ) ).andReturn( "9999" ).anyTimes();
+ EasyMock.expect( request.getHeader( "X-Forwarded-Host" ) ).andReturn( "remotehost:9999" ).anyTimes();
+ EasyMock.expect( request.getHeader( "X-Forwarded-Server" ) ).andReturn( "remotehost" ).anyTimes();
+ EasyMock.expect( request.getHeader( "X-Forwarded-Context" ) ).andReturn( "/upstream" ).anyTimes();
+
+ EasyMock.expect( request.getRemoteAddr() ).andReturn( "127.0.0.1" ).anyTimes();
+ EasyMock.expect( request.isSecure() ).andReturn( false ).anyTimes();
+ EasyMock.expect( request.getLocalPort() ).andReturn( 8888 ).anyTimes();
+ EasyMock.expect( request.getHeader( "Host" ) ).andReturn( "localhost:8888" ).anyTimes();
+ EasyMock.expect( request.getServerName() ).andReturn( "localhost" ).anyTimes();
+ EasyMock.expect( request.getContextPath() ).andReturn( "/context" ).anyTimes();
+
+ HttpServletResponse response = EasyMock.createNiceMock( HttpServletResponse.class );
+ EasyMock.replay( request, response );
+
+ TestFilterChain chain = new TestFilterChain();
+
+ XForwardedHeaderFilter filter = new XForwardedHeaderFilter();
+
+ chain.push( new AssertProxiedXForwardedHeaders() );
+ chain.push( filter );
+ chain.doFilter( request, response );
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayCommandLine.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayCommandLine.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayCommandLine.java
deleted file mode 100644
index a7e2ebc..0000000
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayCommandLine.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * 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;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.cli.PosixParser;
-import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
-
-import java.io.PrintWriter;
-
-import static org.apache.commons.cli.HelpFormatter.*;
-
-public class GatewayCommandLine {
-
- public static CommandLine parse( String[] args ) throws ParseException {
- CommandLineParser parser = new PosixParser();
- CommandLine commandLine = parser.parse( createCommandLine(), args );
- return commandLine;
- }
-
- public static void printUsage() {
- PrintWriter printer = new PrintWriter( System.err );
- new HelpFormatter().printUsage( printer, LINE_WIDTH, COMMAND_NAME, createCommandLine() );
- printer.flush();
- }
-
- public static void printHelp() {
- PrintWriter printer = new PrintWriter( System.err );
- new HelpFormatter().printHelp(printer, LINE_WIDTH, COMMAND_NAME, null, createCommandLine(), DEFAULT_LEFT_PAD, DEFAULT_DESC_PAD, null);
- printer.flush();
- }
-
- /** default number of characters per line */
- public static final int LINE_WIDTH = 80;
- /** Name of the command to use in the command line */
- public static final String COMMAND_NAME= "knox";
-
- public static final String HELP_LONG = "help";
- public static final String HELP_SHORT = "h";
-
- public static final String VERSION_LONG = "version";
- public static final String VERSION_SHORT = "v";
-
- public static final String PERSIST_LONG = "persist-master";
- public static final String PERSIST_SHORT = "pm";
-
- public static final String NOSTART_LONG = "nostart";
- public static final String NOSTART_SHORT = "ns";
-
- public static final String REDEPLOY_LONG = "redeploy";
- public static final String REDEPLOY_SHORT = "rd";
-
- private static Options createCommandLine() {
- Options options = new Options();
- options.addOption( HELP_SHORT, HELP_LONG, false, res.helpMessage() );
- options.addOption( VERSION_SHORT, VERSION_LONG, false, res.versionHelpMessage() );
- Option redeploy = new Option( REDEPLOY_SHORT, REDEPLOY_LONG, true, res.redeployHelpMessage() );
- redeploy.setOptionalArg( true );
- options.addOption( redeploy );
- options.addOption( PERSIST_SHORT, PERSIST_LONG, false, res.persistMasterHelpMessage() );
- options.addOption( NOSTART_SHORT, NOSTART_LONG, false, res.nostartHelpMessage() );
- return options;
- }
-
- private static GatewayResources res = ResourcesFactory.get( GatewayResources.class );
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFactory.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFactory.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFactory.java
deleted file mode 100644
index f813b44..0000000
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFactory.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * 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;
-
-import org.apache.hadoop.gateway.descriptor.FilterDescriptor;
-import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor;
-import org.apache.hadoop.gateway.descriptor.GatewayDescriptor;
-import org.apache.hadoop.gateway.descriptor.GatewayParamDescriptor;
-import org.apache.hadoop.gateway.descriptor.ResourceDescriptor;
-import org.apache.hadoop.gateway.descriptor.ResourceParamDescriptor;
-
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- *
- */
-public class GatewayFactory {
-
-// public static GatewayFilter create( Config gatewayConfig ) throws URISyntaxException {
-// GatewayFilter gateway = new GatewayFilter();
-// for( Config service : gatewayConfig.getChildren().values() ) {
-// addService( gateway, service );
-// }
-// return gateway;
-// }
-//
-// private static void addService( GatewayFilter gateway, Config serviceConfig ) throws URISyntaxException {
-// for( Config filterConfig : serviceConfig.getChildren().values() ) {
-// addFilter( gateway, filterConfig );
-// }
-// }
-//
-// private static void addFilter( GatewayFilter gateway, Config filterConfig ) throws URISyntaxException {
-// String source = filterConfig.get( "pattern" );
-// String name = filterConfig.get( "name" );
-// String clazz = filterConfig.get( "class" );
-// gateway.addFilter( source, name, clazz, filterConfig );
-// }
-
- public static GatewayFilter create( GatewayDescriptor descriptor ) throws URISyntaxException {
- GatewayFilter filter = new GatewayFilter();
- for( ResourceDescriptor resource : descriptor.resources() ) {
- addResource( filter, resource );
- }
- return filter;
- }
-
- private static void addResource( GatewayFilter gateway, ResourceDescriptor resource ) throws URISyntaxException {
- for( FilterDescriptor filter : resource.filters() ) {
- addFilter( gateway, filter );
- }
- }
-
- private static void addFilter( GatewayFilter gateway, FilterDescriptor filter ) throws URISyntaxException {
- String name = filter.name();
- if( name == null ) {
- name = filter.role();
- }
- gateway.addFilter( filter.up().pattern(), name, filter.impl(), createParams( filter ), filter.up().role() );
- }
-
- private static Map<String, String> createParams( FilterDescriptor filter ) {
- Map<String, String> paramMap = new HashMap<>();
- ResourceDescriptor resource = filter.up();
- GatewayDescriptor gateway = resource.up();
- for( GatewayParamDescriptor param : gateway.params() ) {
- paramMap.put( param.name(), param.value() );
- }
- for( ResourceParamDescriptor param : resource.params() ) {
- paramMap.put( param.name(), param.value() );
- }
- //TODO: Should all elements of the resource and gateway descriptor somehow be added to the filter params?
- //TODO: Should we use some composite params object instead of copying all these name value pairs?
- paramMap.put( "pattern", resource.pattern() );
- List<FilterParamDescriptor> paramList = filter.params();
- for( FilterParamDescriptor param : paramList ) {
- paramMap.put( param.name(), param.value() );
- }
- return paramMap;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java
deleted file mode 100644
index c92ebfe..0000000
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java
+++ /dev/null
@@ -1,390 +0,0 @@
-/**
- * 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;
-
-import org.apache.hadoop.gateway.audit.api.Action;
-import org.apache.hadoop.gateway.audit.api.ActionOutcome;
-import org.apache.hadoop.gateway.audit.api.AuditContext;
-import org.apache.hadoop.gateway.audit.api.AuditService;
-import org.apache.hadoop.gateway.audit.api.AuditServiceFactory;
-import org.apache.hadoop.gateway.audit.api.Auditor;
-import org.apache.hadoop.gateway.audit.api.CorrelationContext;
-import org.apache.hadoop.gateway.audit.api.CorrelationServiceFactory;
-import org.apache.hadoop.gateway.audit.api.ResourceType;
-import org.apache.hadoop.gateway.audit.log4j.audit.AuditConstants;
-import org.apache.hadoop.gateway.config.GatewayConfig;
-import org.apache.hadoop.gateway.filter.AbstractGatewayFilter;
-import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
-import org.apache.hadoop.gateway.util.urltemplate.Matcher;
-import org.apache.hadoop.gateway.util.urltemplate.Parser;
-import org.apache.hadoop.gateway.util.urltemplate.Template;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-
-/**
- *
- */
-public class GatewayFilter implements Filter {
-
- private static final FilterChain EMPTY_CHAIN = new FilterChain() {
- public void doFilter( ServletRequest servletRequest, ServletResponse servletResponse ) throws IOException, ServletException {
- }
- };
-
- private static final GatewayMessages LOG = MessagesFactory.get( GatewayMessages.class );
- private static final GatewayResources RES = ResourcesFactory.get( GatewayResources.class );
- private static AuditService auditService = AuditServiceFactory.getAuditService();
- private static Auditor auditor = auditService.getAuditor(
- AuditConstants.DEFAULT_AUDITOR_NAME, AuditConstants.KNOX_SERVICE_NAME,
- AuditConstants.KNOX_COMPONENT_NAME );
-
- private Set<Holder> holders;
- private Matcher<Chain> chains;
- private FilterConfig config;
-
- public GatewayFilter() {
- holders = new HashSet<>();
- chains = new Matcher<Chain>();
- }
-
- @Override
- public void init( FilterConfig filterConfig ) throws ServletException {
- this.config = filterConfig;
- }
-
- @Override
- public void doFilter( ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain ) throws IOException, ServletException {
- doFilter( servletRequest, servletResponse );
- if( filterChain != null ) {
- filterChain.doFilter( servletRequest, servletResponse );
- }
- }
-
- @SuppressWarnings("unchecked")
- public void doFilter( ServletRequest servletRequest, ServletResponse servletResponse ) throws IOException, ServletException {
- HttpServletRequest httpRequest = (HttpServletRequest)servletRequest;
- HttpServletResponse httpResponse = (HttpServletResponse)servletResponse;
-
- //TODO: The resulting pathInfo + query needs to be added to the servlet context somehow so that filters don't need to rebuild it. This is done in HttpClientDispatch right now for example.
- String servlet = httpRequest.getServletPath();
- String path = httpRequest.getPathInfo();
- String query = httpRequest.getQueryString();
- String requestPath = ( servlet == null ? "" : servlet ) + ( path == null ? "" : path );
- String requestPathWithQuery = requestPath + ( query == null ? "" : "?" + query );
-
- Template pathWithQueryTemplate;
- try {
- pathWithQueryTemplate = Parser.parseLiteral( requestPathWithQuery );
- } catch( URISyntaxException e ) {
- throw new ServletException( e );
- }
- String contextWithPathAndQuery = httpRequest.getContextPath() + requestPathWithQuery;
- LOG.receivedRequest( httpRequest.getMethod(), requestPath );
-
- servletRequest.setAttribute(
- AbstractGatewayFilter.SOURCE_REQUEST_URL_ATTRIBUTE_NAME, pathWithQueryTemplate );
- servletRequest.setAttribute(
- AbstractGatewayFilter.SOURCE_REQUEST_CONTEXT_URL_ATTRIBUTE_NAME, contextWithPathAndQuery );
-
- Matcher<Chain>.Match match = chains.match( pathWithQueryTemplate );
-
- assignCorrelationRequestId();
- // Populate Audit/correlation parameters
- AuditContext auditContext = auditService.getContext();
- auditContext.setTargetServiceName( match == null ? null : match.getValue().getResourceRole() );
- auditContext.setRemoteIp( getRemoteAddress(servletRequest) );
- auditContext.setRemoteHostname( servletRequest.getRemoteHost() );
- auditor.audit(
- Action.ACCESS, contextWithPathAndQuery, ResourceType.URI,
- ActionOutcome.UNAVAILABLE, RES.requestMethod(((HttpServletRequest)servletRequest).getMethod()));
-
- if( match != null ) {
- Chain chain = match.getValue();
- servletRequest.setAttribute( AbstractGatewayFilter.TARGET_SERVICE_ROLE, chain.getResourceRole() );
- try {
- chain.doFilter( servletRequest, servletResponse );
- } catch( IOException e ) {
- LOG.failedToExecuteFilter( e );
- auditor.audit( Action.ACCESS, contextWithPathAndQuery, ResourceType.URI, ActionOutcome.FAILURE );
- throw e;
- } catch( ServletException e ) {
- LOG.failedToExecuteFilter( e );
- auditor.audit( Action.ACCESS, contextWithPathAndQuery, ResourceType.URI, ActionOutcome.FAILURE );
- throw e;
- } catch( RuntimeException e ) {
- LOG.failedToExecuteFilter( e );
- auditor.audit( Action.ACCESS, contextWithPathAndQuery, ResourceType.URI, ActionOutcome.FAILURE );
- throw e;
- } catch( ThreadDeath e ) {
- LOG.failedToExecuteFilter( e );
- auditor.audit( Action.ACCESS, contextWithPathAndQuery, ResourceType.URI, ActionOutcome.FAILURE );
- throw e;
- } catch( Throwable e ) {
- LOG.failedToExecuteFilter( e );
- auditor.audit( Action.ACCESS, contextWithPathAndQuery, ResourceType.URI, ActionOutcome.FAILURE );
- throw new ServletException( e );
- }
- } else {
- LOG.failedToMatchPath( requestPath );
- httpResponse.setStatus( HttpServletResponse.SC_NOT_FOUND );
- }
- //KAM[ Don't do this or the Jetty default servlet will overwrite any response setup by the filter.
- // filterChain.doFilter( servletRequest, servletResponse );
- //]
- }
-
- private String getRemoteAddress(ServletRequest servletRequest) {
- GatewayConfig gatewayConfig =
- (GatewayConfig) servletRequest.getServletContext().
- getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
-
- String addrHeaderName = gatewayConfig.getHeaderNameForRemoteAddress();
- String addr = ((HttpServletRequest)servletRequest).getHeader(addrHeaderName);
- if (addr == null || addr.trim().isEmpty()) {
- addr = servletRequest.getRemoteAddr();
- }
- return addr;
- }
-
- @Override
- public void destroy() {
- for( Holder holder : holders ) {
- holder.destroy();
- }
- }
-
- private void addHolder( Holder holder ) {
- holders.add( holder );
- Chain chain = chains.get( holder.template );
- if( chain == null ) {
- chain = new Chain();
- chain.setResourceRole( holder.getResourceRole() );
- chains.add( holder.template, chain );
- }
- chain.chain.add( holder );
- }
-
- public void addFilter( String path, String name, Filter filter, Map<String,String> params, String resourceRole ) throws URISyntaxException {
- Holder holder = new Holder( path, name, filter, params, resourceRole );
- addHolder( holder );
- }
-
-// public void addFilter( String path, String name, Class<RegexDirFilter> clazz, Map<String,String> params ) throws URISyntaxException {
-// Holder holder = new Holder( path, name, clazz, params );
-// addHolder( holder );
-// }
-
- public void addFilter( String path, String name, String clazz, Map<String,String> params, String resourceRole ) throws URISyntaxException {
- Holder holder = new Holder( path, name, clazz, params, resourceRole );
- addHolder( holder );
- }
-
- // Now creating the correlation context only if required since it may be created upstream in the CorrelationHandler.
- private void assignCorrelationRequestId() {
- CorrelationContext correlationContext = CorrelationServiceFactory.getCorrelationService().getContext();
- if( correlationContext == null ) {
- correlationContext = CorrelationServiceFactory.getCorrelationService().createContext();
- }
- String requestId = correlationContext.getRequestId();
- if( requestId == null ) {
- correlationContext.setRequestId( UUID.randomUUID().toString() );
- }
- }
-
- private class Chain implements FilterChain {
-
- private List<Holder> chain;
- private String resourceRole;
-
- private Chain() {
- this.chain = new ArrayList<Holder>();
- }
-
- private Chain( List<Holder> chain ) {
- this.chain = chain;
- }
-
- public void doFilter( ServletRequest servletRequest, ServletResponse servletResponse ) throws IOException, ServletException {
- if( chain != null && !chain.isEmpty() ) {
- final Filter filter = chain.get( 0 );
- final FilterChain chain = subChain();
- filter.doFilter( servletRequest, servletResponse, chain );
- }
- }
-
- private FilterChain subChain() {
- if( chain != null && chain.size() > 1 ) {
- return new Chain( chain.subList( 1, chain.size() ) );
- } else {
- return EMPTY_CHAIN;
- }
- }
-
- private String getResourceRole() {
- return resourceRole;
- }
-
- private void setResourceRole( String resourceRole ) {
- this.resourceRole = resourceRole;
- }
-
- }
-
- private class Holder implements Filter, FilterConfig {
-// private String path;
- private Template template;
- private String name;
- private Map<String,String> params;
- private Filter instance;
- private Class<? extends Filter> clazz;
- private String type;
- private String resourceRole;
-
- private Holder( String path, String name, Filter filter, Map<String,String> params, String resourceRole ) throws URISyntaxException {
-// this.path = path;
- this.template = Parser.parseTemplate( path );
- this.name = name;
- this.params = params;
- this.instance = filter;
- this.clazz = filter.getClass();
- this.type = clazz.getCanonicalName();
- this.resourceRole = resourceRole;
- }
-
-// private Holder( String path, String name, Class<RegexDirFilter> clazz, Map<String,String> params ) throws URISyntaxException {
-// this.path = path;
-// this.template = Parser.parse( path );
-// this.name = name;
-// this.params = params;
-// this.instance = null;
-// this.clazz = clazz;
-// this.type = clazz.getCanonicalName();
-// }
-
- private Holder( String path, String name, String clazz, Map<String,String> params, String resourceRole ) throws URISyntaxException {
-// this.path = path;
- this.template = Parser.parseTemplate( path );
- this.name = name;
- this.params = params;
- this.instance = null;
- this.clazz = null;
- this.type = clazz;
- this.resourceRole = resourceRole;
- }
-
- @Override
- public String getFilterName() {
- return name;
- }
-
- @Override
- public ServletContext getServletContext() {
- return GatewayFilter.this.config.getServletContext();
- }
-
- @Override
- public String getInitParameter( String name ) {
- String value = null;
- if( params != null ) {
- value = params.get( name );
- }
- return value;
- }
-
- @Override
- public Enumeration<String> getInitParameterNames() {
- Enumeration<String> names = null;
- if( params != null ) {
- names = Collections.enumeration( params.keySet() );
- }
- return names;
- }
-
- @Override
- public void init( FilterConfig filterConfig ) throws ServletException {
- getInstance().init( filterConfig );
- }
-
- @Override
- public void doFilter( ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain ) throws IOException, ServletException {
- final Filter filter = getInstance();
- filter.doFilter( servletRequest, servletResponse, filterChain );
- }
-
- @Override
- public void destroy() {
- if( instance != null ) {
- instance.destroy();
- instance = null;
- }
- }
-
- @SuppressWarnings("unchecked")
- private Class<? extends Filter> getClazz() throws ClassNotFoundException {
- if( clazz == null ) {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- if( loader == null ) {
- loader = this.getClass().getClassLoader();
- }
- clazz = (Class)loader.loadClass( type );
- }
- return clazz;
- }
-
- private Filter getInstance() throws ServletException {
- if( instance == null ) {
- try {
- if( clazz == null ) {
- clazz = getClazz();
- }
- instance = clazz.newInstance();
- instance.init( this );
- } catch( Exception e ) {
- throw new ServletException( e );
- }
- }
- return instance;
- }
-
- private String getResourceRole() {
- return resourceRole;
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayForwardingServlet.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayForwardingServlet.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayForwardingServlet.java
deleted file mode 100644
index f2d21be..0000000
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayForwardingServlet.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/**
- * 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;
-
-import org.apache.hadoop.gateway.audit.api.*;
-import org.apache.hadoop.gateway.audit.log4j.audit.AuditConstants;
-import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
-
-import java.io.*;
-
-import javax.servlet.*;
-import javax.servlet.http.*;
-
-public class GatewayForwardingServlet extends HttpServlet{
-
- private static final long serialVersionUID = 1L;
-
- private static final String AUDIT_ACTION = "forward";
-
- private static final GatewayResources RES = ResourcesFactory.get( GatewayResources.class );
- private static final GatewayMessages LOG = MessagesFactory.get( GatewayMessages.class );
-
- private static AuditService auditService = AuditServiceFactory.getAuditService();
- private static Auditor auditor = AuditServiceFactory.getAuditService()
- .getAuditor( AuditConstants.DEFAULT_AUDITOR_NAME,
- AuditConstants.KNOX_SERVICE_NAME, AuditConstants.KNOX_COMPONENT_NAME );
-
- private String redirectToContext = null;
-
- @Override
- protected void doHead(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- doGet(req, resp);
- }
-
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- doGet(req, resp);
- }
-
- @Override
- protected void doPut(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- doGet(req, resp);
- }
-
- @Override
- protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- doGet(req, resp);
- }
-
- @Override
- protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- doGet(req, resp);
- }
-
- @Override
- public void init(ServletConfig config) throws ServletException {
- super.init(config);
-
- redirectToContext = config.getInitParameter("redirectTo");
- }
-
- public void doGet(HttpServletRequest request,
- HttpServletResponse response)
- throws ServletException, IOException
- {
- String origPath = getRequestPath( request );
- try {
- auditService.createContext();
-
- String origRequest = getRequestLine( request );
-
- auditor.audit(
- AUDIT_ACTION, origPath, ResourceType.URI,
- ActionOutcome.UNAVAILABLE, RES.forwardToDefaultTopology( request.getMethod(), redirectToContext ) );
-
- // Perform cross context dispatch to the configured topology context
- ServletContext ctx = getServletContext().getContext(redirectToContext);
- RequestDispatcher dispatcher = ctx.getRequestDispatcher(origRequest);
-
- dispatcher.forward(request, response);
-
- auditor.audit(
- AUDIT_ACTION, origPath, ResourceType.URI,
- ActionOutcome.SUCCESS, RES.responseStatus( response.getStatus() ) );
-
- } catch( ServletException | IOException | RuntimeException e ) {
- auditor.audit(
- AUDIT_ACTION, origPath, ResourceType.URI,
- ActionOutcome.FAILURE );
- throw e;
- } catch( Throwable e ) {
- auditor.audit(
- AUDIT_ACTION, origPath, ResourceType.URI,
- ActionOutcome.FAILURE );
- throw new ServletException(e);
- } finally {
- auditService.detachContext();
- }
- }
-
- private static final String getRequestPath( final HttpServletRequest request ) {
- final String path = request.getPathInfo();
- if( path == null ) {
- return "";
- } else {
- return path;
- }
- }
-
- private static final String getRequestLine( final HttpServletRequest request ) {
- final String path = getRequestPath( request );
- final String query = request.getQueryString();
- if( query == null ) {
- return path;
- } else {
- return path + "?" + query;
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/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
deleted file mode 100644
index 1f94584..0000000
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
+++ /dev/null
@@ -1,516 +0,0 @@
-/**
- * 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;
-
-import org.apache.commons.cli.ParseException;
-import org.apache.hadoop.gateway.i18n.messages.Message;
-import org.apache.hadoop.gateway.i18n.messages.MessageLevel;
-import org.apache.hadoop.gateway.i18n.messages.Messages;
-import org.apache.hadoop.gateway.i18n.messages.StackTrace;
-import org.apache.hadoop.gateway.services.security.KeystoreServiceException;
-
-import java.io.File;
-import java.net.URI;
-import java.util.Date;
-import java.util.Map;
-import java.util.Set;
-
-/**
- *
- */
-@Messages(logger="org.apache.hadoop.gateway")
-public interface GatewayMessages {
-
- @Message( level = MessageLevel.FATAL, text = "Failed to parse command line: {0}" )
- void failedToParseCommandLine( @StackTrace( level = MessageLevel.DEBUG ) ParseException e );
-
- @Message( level = MessageLevel.INFO, text = "Starting gateway..." )
- void startingGateway();
-
- @Message( level = MessageLevel.FATAL, text = "Failed to start gateway: {0}" )
- void failedToStartGateway( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.INFO, text = "Started gateway on port {0}." )
- void startedGateway( int port );
-
- @Message( level = MessageLevel.INFO, text = "Stopping gateway..." )
- void stoppingGateway();
-
- @Message( level = MessageLevel.INFO, text = "Stopped gateway." )
- void stoppedGateway();
-
- @Message( level = MessageLevel.INFO, text = "Loading configuration resource {0}" )
- void loadingConfigurationResource( String res );
-
- @Message( level = MessageLevel.INFO, text = "Loading configuration file {0}" )
- void loadingConfigurationFile( String file );
-
- @Message( level = MessageLevel.WARN, text = "Failed to load configuration file {0}: {1}" )
- void failedToLoadConfig( String path, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.INFO, text = "Using {1} as GATEWAY_HOME via {0}." )
- void settingGatewayHomeDir( String location, String home );
-
- @Message( level = MessageLevel.INFO, text = "Loading topologies from directory: {0}" )
- void loadingTopologiesFromDirectory( String topologiesDir );
-
- @Message( level = MessageLevel.DEBUG, text = "Loading topology file: {0}" )
- void loadingTopologyFile( String fileName );
-
- @Message( level = MessageLevel.INFO, text = "Monitoring topologies in directory: {0}" )
- void monitoringTopologyChangesInDirectory( String topologiesDir );
-
- @Message( level = MessageLevel.INFO, text = "Deploying topology {0} to {1}" )
- void deployingTopology( String clusterName, String warDirName );
-
- @Message( level = MessageLevel.DEBUG, text = "Deployed topology {0}." )
- void deployedTopology( String clusterName );
-
- @Message( level = MessageLevel.INFO, text = "Loading topology {0} from {1}" )
- void redeployingTopology( String clusterName, String warDirName );
-
- @Message( level = MessageLevel.DEBUG, text = "Redeployed topology {0}." )
- void redeployedTopology( String clusterName );
-
- @Message( level = MessageLevel.INFO, text = "Activating topology {0}" )
- void activatingTopology( String name );
-
- @Message( level = MessageLevel.INFO, text = "Activating topology {0} archive {1}" )
- void activatingTopologyArchive( String topology, String archive );
-
- @Message( level = MessageLevel.INFO, text = "Deactivating topology {0}" )
- void deactivatingTopology( String name );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to deploy topology {0}: {1}" )
- void failedToDeployTopology( String name, @StackTrace(level=MessageLevel.DEBUG) Throwable e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to redeploy topology {0}" )
- void failedToRedeployTopology( String name );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to redeploy topology {0}: {1}" )
- void failedToRedeployTopology( String name, @StackTrace(level=MessageLevel.DEBUG) Throwable e );
-
- @Message(level = MessageLevel.ERROR, text = "Failed to load topology {0}: Topology configuration is invalid!")
- void failedToLoadTopology(String fileName);
-
- @Message( level = MessageLevel.ERROR, text = "Failed to redeploy topologies: {0}" )
- void failedToRedeployTopologies( @StackTrace(level=MessageLevel.DEBUG) Throwable e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to undeploy topology {0}: {1}" )
- void failedToUndeployTopology( String name, @StackTrace(level=MessageLevel.DEBUG) Exception e );
-
- @Message( level = MessageLevel.INFO, text = "Deleting topology {0}" )
- void deletingTopology( String topologyName );
-
- @Message( level = MessageLevel.INFO, text = "Deleting deployed topology {0}" )
- void deletingDeployment( String warDirName );
-
- @Message( level = MessageLevel.DEBUG, text = "Purge backups of deployed topology {0}" )
- void cleanupDeployments( String topologyName );
-
- @Message( level = MessageLevel.INFO, text = "Deleting backup deployed topology {0}" )
- void cleanupDeployment( String absolutePath );
-
- @Message( level = MessageLevel.INFO, text = "Creating gateway home directory: {0}" )
- void creatingGatewayHomeDir( File homeDir );
-
- @Message( level = MessageLevel.INFO, text = "Creating gateway deployment directory: {0}" )
- void creatingGatewayDeploymentDir( File topologiesDir );
-
- @Message( level = MessageLevel.INFO, text = "Creating default gateway configuration file: {0}" )
- void creatingDefaultConfigFile( File defaultConfigFile );
-
- @Message( level = MessageLevel.INFO, text = "Creating sample topology file: {0}" )
- void creatingDefaultTopologyFile( File defaultConfigFile );
-
- @Message( level = MessageLevel.WARN, text = "Ignoring service deployment contributor with invalid null name: {0}" )
- void ignoringServiceContributorWithMissingName( String className );
-
- @Message( level = MessageLevel.WARN, text = "Ignoring service deployment contributor with invalid null role: {0}" )
- void ignoringServiceContributorWithMissingRole( String className );
-
- @Message( level = MessageLevel.WARN, text = "Ignoring service deployment contributor with invalid null version: {0}" )
- void ignoringServiceContributorWithMissingVersion( String className );
-
- @Message( level = MessageLevel.WARN, text = "Ignoring provider deployment contributor with invalid null name: {0}" )
- void ignoringProviderContributorWithMissingName( String className );
-
- @Message( level = MessageLevel.WARN, text = "Ignoring provider deployment contributor with invalid null role: {0}" )
- void ignoringProviderContributorWithMissingRole( String className );
-
- @Message( level = MessageLevel.INFO, text = "Loaded logging configuration: {0}" )
- void loadedLoggingConfig( String fileName );
-
- @Message( level = MessageLevel.WARN, text = "Failed to load logging configuration: {0}" )
- void failedToLoadLoggingConfig( String fileName );
-
- @Message( level = MessageLevel.INFO, text = "Creating credential store for the gateway instance." )
- void creatingCredentialStoreForGateway();
-
- @Message( level = MessageLevel.INFO, text = "Credential store for the gateway instance found - no need to create one." )
- void credentialStoreForGatewayFoundNotCreating();
-
- @Message( level = MessageLevel.INFO, text = "Creating keystore for the gateway instance." )
- void creatingKeyStoreForGateway();
-
- @Message( level = MessageLevel.INFO, text = "Keystore for the gateway instance found - no need to create one." )
- void keyStoreForGatewayFoundNotCreating();
-
- @Message( level = MessageLevel.INFO, text = "Creating credential store for the cluster: {0}" )
- void creatingCredentialStoreForCluster(String clusterName);
-
- @Message( level = MessageLevel.INFO, text = "Credential store found for the cluster: {0} - no need to create one." )
- void credentialStoreForClusterFoundNotCreating(String clusterName);
-
- @Message( level = MessageLevel.DEBUG, text = "Received request: {0} {1}" )
- void receivedRequest( String method, String uri );
-
- @Message( level = MessageLevel.DEBUG, text = "Dispatch 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.WARN) Exception e );
-
- @Message( level = MessageLevel.DEBUG, text = "Signature verified: {0}" )
- void signatureVerified( boolean verified );
-
- @Message( level = MessageLevel.DEBUG, text = "Apache Knox Gateway {0} ({1})" )
- void gatewayVersionMessage( String version, String hash );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to inject service {0}: {1}" )
- void failedToInjectService( String serviceName, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to finalize contribution: {0}" )
- void failedToFinalizeContribution( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to contribute service [role={1}, name={0}]: {2}" )
- void failedToContributeService( String name, String role, @StackTrace( level = MessageLevel.ERROR ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to contribute provider [role={1}, name={0}]: {2}" )
- void failedToContributeProvider( String name, String role, @StackTrace( level = MessageLevel.ERROR ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to initialize contribution: {0}" )
- void failedToInitializeContribution( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to initialize servlet instance: {0}" )
- void failedToInitializeServletInstace( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Gateway processing failed: {0}" )
- void failedToExecuteFilter( @StackTrace( level = MessageLevel.INFO ) Throwable t );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to load topology {0}: {1}")
- void failedToLoadTopology( String fileName, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to load topology {0}, retrying after {1}ms: {2}")
- void failedToLoadTopologyRetrying( String friendlyURI, String delay, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to handle topology events: {0}" )
- void failedToHandleTopologyEvents( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to reload topologies: {0}" )
- void failedToReloadTopologies( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.FATAL, text = "Unsupported encoding: {0}" )
- void unsupportedEncoding( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to persist master secret: {0}" )
- void failedToPersistMasterSecret( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to encrypt master secret: {0}" )
- void failedToEncryptMasterSecret( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to initialize master service from persistent master {0}: {1}" )
- void failedToInitializeFromPersistentMaster( String masterFileName, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to encode passphrase: {0}" )
- void failedToEncodePassphrase( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to verify signature: {0}")
- void failedToVerifySignature( @StackTrace(level=MessageLevel.DEBUG) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to sign the data: {0}")
- void failedToSignData( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to decrypt password for cluster {0}: {1}" )
- void failedToDecryptPasswordForCluster( String clusterName, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to encrypt password for cluster {0}: {1}")
- void failedToEncryptPasswordForCluster( String clusterName, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to create keystore [filename={0}, type={1}]: {2}" )
- void failedToCreateKeystore( String fileName, String keyStoreType, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to load keystore [filename={0}, type={1}]: {2}" )
- void failedToLoadKeystore( String fileName, String keyStoreType, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to add key for cluster {0}: {1}" )
- void failedToAddKeyForCluster( String clusterName, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to add credential for cluster {0}: {1}" )
- void failedToAddCredentialForCluster( String clusterName, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to get key for Gateway {0}: {1}" )
- void failedToGetKeyForGateway( String alias, @StackTrace( level=MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to get credential for cluster {0}: {1}" )
- void failedToGetCredentialForCluster( String clusterName, @StackTrace(level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to get key for cluster {0}: {1}" )
- void failedToGetKeyForCluster( String clusterName, @StackTrace(level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to add self signed certificate for Gateway {0}: {1}" )
- void failedToAddSeflSignedCertForGateway( String alias, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to generate secret key from password: {0}" )
- void failedToGenerateKeyFromPassword( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to establish connection to {0}: {1}" )
- void failedToEstablishConnectionToUrl( String url, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to interpret property \"{0}\": {1}")
- void failedToInterpretProperty( String property, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to instantiate the internal gateway services." )
- void failedToInstantiateGatewayServices();
-
- @Message( level = MessageLevel.ERROR, text = "Failed to serialize map to Json string {0}: {1}" )
- void failedToSerializeMapToJSON( Map<String, Object> map, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to get map from Json string {0}: {1}" )
- void failedToGetMapFromJsonString( String json, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.DEBUG, text = "Successful Knox->Hadoop SPNegotiation authentication for URL: {0}" )
- void successfulSPNegoAuthn(String uri);
-
- @Message( level = MessageLevel.ERROR, text = "Failed Knox->Hadoop SPNegotiation authentication for URL: {0}" )
- void failedSPNegoAuthn(String uri);
-
- @Message( level = MessageLevel.DEBUG, text = "Dispatch response status: {0}" )
- void dispatchResponseStatusCode(int statusCode);
-
- @Message( level = MessageLevel.DEBUG, text = "Dispatch response status: {0}, Location: {1}" )
- void dispatchResponseCreatedStatusCode( int statusCode, String location );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to decrypt cipher text for cluster {0}: due to inability to retrieve the password." )
- void failedToDecryptCipherForClusterNullPassword(String clusterName);
-
- @Message( level = MessageLevel.DEBUG, text = "Gateway services have not been initialized." )
- void gatewayServicesNotInitialized();
-
- @Message( level = MessageLevel.INFO, text = "The Gateway SSL certificate is issued to hostname: {0}." )
- void certificateHostNameForGateway(String cn);
-
- @Message( level = MessageLevel.INFO, text = "The Gateway SSL certificate is valid between: {0} and {1}." )
- void certificateValidityPeriod(Date notBefore, Date notAfter);
-
- @Message( level = MessageLevel.ERROR, text = "Unable to retrieve certificate for Gateway: {0}." )
- void unableToRetrieveCertificateForGateway(Exception e);
-
- @Message( level = MessageLevel.ERROR, text = "Failed to generate alias for cluster: {0} {1}." )
- void failedToGenerateAliasForCluster(String clusterName, KeystoreServiceException e);
-
- @Message( level = MessageLevel.DEBUG, text = "Key passphrase not found in credential store - using master secret." )
- void assumingKeyPassphraseIsMaster();
-
- @Message( level = MessageLevel.ERROR, text = "Failed to remove alias for cluster: {0} {1}." )
- void failedToRemoveCredentialForCluster(String clusterName, Exception e);
-
- @Message( level = MessageLevel.WARN, text = "Failed to match path {0}" )
- void failedToMatchPath( String path );
-
- @Message( level = MessageLevel.ERROR, text = "Failed to get system ldap connection: {0}" )
- void failedToGetSystemLdapConnection( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.WARN, text = "Value not found for cluster:{0}, alias: {1}" )
- void aliasValueNotFound( String cluster, String alias );
-
- @Message( level = MessageLevel.INFO, text = "Computed userDn: {0} using dnTemplate for principal: {1}" )
- void computedUserDn(String userDn, String principal);
-
- @Message( level = MessageLevel.DEBUG, text = "Searching from {0} where {1} scope {2}" )
- void searchBaseFilterScope( String searchBase, String searchFilter, String searchScope );
-
- @Message( level = MessageLevel.INFO, text = "Computed userDn: {0} using ldapSearch for principal: {1}" )
- void searchedAndFoundUserDn(String userDn, String principal);
-
- @Message( level = MessageLevel.INFO, text = "Computed roles/groups: {0} for principal: {1}" )
- void lookedUpUserRoles(Set<String> roleNames, String userName);
-
- @Message( level = MessageLevel.DEBUG, text = "Initialize provider: {1}/{0}" )
- void initializeProvider( String name, String role );
-
- @Message( level = MessageLevel.DEBUG, text = "Initialize service: {1}/{0}" )
- void initializeService( String name, String role );
-
- @Message( level = MessageLevel.DEBUG, text = "Contribute provider: {1}/{0}" )
- void contributeProvider( String name, String role );
-
- @Message( level = MessageLevel.DEBUG, text = "Contribute service: {1}/{0}" )
- void contributeService( String name, String role );
-
- @Message( level = MessageLevel.DEBUG, text = "Finalize provider: {1}/{0}" )
- void finalizeProvider( String name, String role );
-
- @Message( level = MessageLevel.DEBUG, text = "Finalize service: {1}/{0}" )
- void finalizeService( String name, String role );
-
- @Message( level = MessageLevel.DEBUG, text = "Configured services directory is {0}" )
- void usingServicesDirectory(String path);
-
- @Message( level = MessageLevel.ERROR, text = "Failed to unmarshall service definition file {0} file : {1}" )
- void failedToLoadServiceDefinition(String fileName, @StackTrace( level = MessageLevel.DEBUG ) Exception e);
-
- @Message( level = MessageLevel.ERROR, text = "Failed to find service definition file {0} file : {1}" )
- void failedToFindServiceDefinitionFile(String fileName, @StackTrace( level = MessageLevel.DEBUG ) Exception e);
-
- @Message( level = MessageLevel.ERROR, text = "Failed to find rewrite file {0} file : {1}" )
- void failedToFindRewriteFile(String fileName, @StackTrace( level = MessageLevel.DEBUG ) Exception e);
-
- @Message( level = MessageLevel.ERROR, text = "Failed to unmarshall rewrite file {0} file : {1}" )
- void failedToLoadRewriteFile(String fileName, @StackTrace( level = MessageLevel.DEBUG ) Exception e);
-
- @Message( level = MessageLevel.DEBUG, text = "No rewrite file found in service directory {0}" )
- void noRewriteFileFound(String path);
-
- @Message( level = MessageLevel.DEBUG, text = "Added Service definition name: {0}, role : {1}, version : {2}" )
- void addedServiceDefinition(String serviceName, String serviceRole, String version);
-
- @Message( level = MessageLevel.INFO, text = "System Property: {0}={1}" )
- void logSysProp( String name, String property );
-
- @Message( level = MessageLevel.ERROR, text = "Unable to get password: {0}" )
- void unableToGetPassword(@StackTrace( level = MessageLevel.DEBUG ) Exception e);
-
- @Message( level = MessageLevel.DEBUG, text = "Initialize application: {0}" )
- void initializeApplication( String name );
-
- @Message( level = MessageLevel.DEBUG, text = "Contribute application: {0}" )
- void contributeApplication( String name );
-
- @Message( level = MessageLevel.DEBUG, text = "Finalize application: {0}" )
- void finalizeApplication( String name );
-
- @Message( level = MessageLevel.INFO, text = "Default topology {0} at {1}" )
- void defaultTopologySetup( String defaultTopologyName, String redirectContext );
-
- @Message( level = MessageLevel.DEBUG, text = "Default topology forward from {0} to {1}" )
- void defaultTopologyForward( String oldTarget, String newTarget );
-
- @Message( level = MessageLevel.ERROR, text = "Unable to setup PagedResults" )
- void unableToSetupPagedResults();
-
- @Message( level = MessageLevel.INFO, text = "Ignoring PartialResultException" )
- void ignoringPartialResultException();
-
- @Message( level = MessageLevel.WARN, text = "Only retrieved first {0} groups due to SizeLimitExceededException." )
- void sizeLimitExceededOnlyRetrieved(int numResults);
-
- @Message( level = MessageLevel.DEBUG, text = "Failed to parse path into Template: {0} : {1}" )
- void failedToParsePath( String path, @StackTrace( level = MessageLevel.DEBUG ) Exception e );
-
- @Message( level = MessageLevel.DEBUG, text = "Failed to initialize metrics reporter {0} : {1}" )
- void failedToInitializeReporter( String name, @StackTrace( level = MessageLevel.DEBUG ) Exception e);
-
- @Message( level = MessageLevel.DEBUG, text = "Failed to start metrics reporter {0} : {1}" )
- void failedToStartReporter( String name, @StackTrace( level = MessageLevel.DEBUG ) Exception e);
-
- @Message( level = MessageLevel.DEBUG, text = "Failed to stop metrics reporter {0} : {1}" )
- void failedToStopReporter( String name, @StackTrace( level = MessageLevel.DEBUG ) Exception e);
-
- @Message( level = MessageLevel.INFO, text = "Cookie scoping feature enabled: {0}" )
- void cookieScopingFeatureEnabled( boolean enabled );
-
- /**
- * Log whether Topology port mapping feature is enabled/disabled.
- *
- * @param enabled
- */
- @Message(level = MessageLevel.INFO,
- text = "Topology port mapping feature enabled: {0}")
- void gatewayTopologyPortMappingEnabled(final boolean enabled);
-
- /**
- * @param topology
- * @param port
- */
- @Message(level = MessageLevel.DEBUG,
- text = "Creating a connector for topology {0} listening on port {1}.")
- void createJettyConnector(final String topology, final int port);
-
- /**
- * @param topology
- */
- @Message(level = MessageLevel.DEBUG,
- text = "Creating a handler for topology {0}.")
- void createJettyHandler(final String topology);
-
- /**
- * @param oldTarget
- * @param newTarget
- */
- @Message(level = MessageLevel.INFO,
- text = "Updating request context from {0} to {1}")
- void topologyPortMappingAddContext(final String oldTarget,
- final String newTarget);
-
- /**
- * @param oldTarget
- * @param newTarget
- */
- @Message(level = MessageLevel.DEBUG,
- text = "Updating request target from {0} to {1}")
- void topologyPortMappingUpdateRequest(final String oldTarget,
- final String newTarget);
-
- /**
- * Messages for Topology Port Mapping
- *
- * @param port
- * @param topology
- */
- @Message(level = MessageLevel.ERROR,
- text = "Port {0} configured for Topology - {1} is already in use.")
- void portAlreadyInUse(final int port, final String topology);
-
- /**
- * Messages for Topology Port Mapping
- *
- * @param port
- */
- @Message(level = MessageLevel.ERROR,
- text = "Port {0} is already in use.")
- void portAlreadyInUse(final int port);
-
- /**
- * Log topology and port
- *
- * @param topology
- * @param port
- */
- @Message(level = MessageLevel.INFO,
- text = "Started gateway, topology \"{0}\" listening on port \"{1}\".")
- void startedGateway(final String topology, final int port);
-
- @Message(level = MessageLevel.ERROR,
- text =
- " Could not find topology \"{0}\" mapped to port \"{1}\" configured in gateway-config.xml. "
- + "This invalid topology mapping will be ignored by the gateway. "
- + "Gateway restart will be required if in the future \"{0}\" topology is added.")
- void topologyPortMappingCannotFindTopology(final String topology,
- final int port);
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/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
deleted file mode 100644
index ca73279..0000000
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * 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;
-
-import org.apache.hadoop.gateway.i18n.resources.Resource;
-import org.apache.hadoop.gateway.i18n.resources.Resources;
-
-/**
- *
- */
-@Resources
-public interface GatewayResources {
-
- @Resource( text="Apache Knox Gateway {0} ({1})" )
- String gatewayVersionMessage( String version, String hash );
-
- @Resource( text="Apache Knox Gateway" )
- String gatewayServletInfo();
-
- @Resource( text="Service connectivity error." )
- String dispatchConnectionError();
-
- @Resource( text="Display command line help." )
- String helpMessage();
-
- @Resource( text="This parameter causes the server to exit before starting to service requests. This is typically used with the -persist-master parameter." )
- String nostartHelpMessage();
-
- @Resource( text="This parameter causes the provider master secret to be persisted. This prevents the server from prompting for a master secret on subsequent starts." )
- String persistMasterHelpMessage();
-
- @Resource( text="This parameter causes the existing topologies to be redeployed. A single topology may be specified via an optional parameter. The server will not be started." )
- String redeployHelpMessage();
-
- @Resource( text="Display server version information." )
- String versionHelpMessage();
-
- @Resource( text="Topology is required." )
- String topologyIsRequiredError();
-
- @Resource( text="Provider is required." )
- String providerIsRequiredError();
-
- @Resource( text="Unsupported property''s token: {0}" )
- String unsupportedPropertyTokenError(String token);
-
- @Resource( text="Failed to build topology: wrong data format." )
- String wrongTopologyDataFormatError();
-
- @Resource( text="Provider parameter name is required." )
- String providerParameterNameIsRequiredError();
-
- @Resource( text="Provider parameter value is required." )
- String providerParameterValueIsRequiredError();
-
- @Resource( text="Service parameter name is required." )
- String serviceParameterNameIsRequiredError();
-
- @Resource( text="Service parameter value is required." )
- String serviceParameterValueIsRequiredError();
-
- @Resource( text="Failed to create keystore directory: {0}" )
- String failedToCreateKeyStoreDirectory( String name );
-
- @Resource( text="Response status: {0}" )
- String responseStatus( int status );
-
- @Resource( text="Request method: {0}" )
- String requestMethod( String method );
-
- @Resource( text="Forward method: {0} to default context: {1}" )
- String forwardToDefaultTopology(String method, String context );
-}