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:27 UTC
[29/64] [partial] knox git commit: KNOX-998 - Refactoring save 1
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessor.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessor.java
deleted file mode 100644
index be1eca5..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessor.java
+++ /dev/null
@@ -1,125 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.FrontendFunctionDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.i18n.UrlRewriteResources;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteResolver;
-import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
-import org.apache.hadoop.gateway.services.GatewayServices;
-
-import java.net.URI;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class FrontendFunctionProcessor implements UrlRewriteFunctionProcessor<FrontendFunctionDescriptor> {
-
- private static UrlRewriteResources RES = ResourcesFactory.get( UrlRewriteResources.class );
-
- private Map<String,UrlRewriteResolver> resolvers;
-
- @Override
- public String name() {
- return FrontendFunctionDescriptor.FUNCTION_NAME;
- }
-
- @Override
- public void initialize( UrlRewriteEnvironment environment, FrontendFunctionDescriptor descriptor ) throws Exception {
- if( environment == null ) {
- throw new IllegalArgumentException( "environment==null" );
- }
- URI frontend = environment.getAttribute( FrontendFunctionDescriptor.FRONTEND_URI_ATTRIBUTE );
- resolvers = new HashMap<>();
- if( frontend == null ) {
- resolvers.put( "url", new ParamResolver( "gateway.url" ) );
- resolvers.put( "addr", new ParamResolver( "gateway.addr" ) );
- resolvers.put( "scheme", new ParamResolver( "gateway.scheme" ) );
- resolvers.put( "host", new ParamResolver( "gateway.host" ) );
- resolvers.put( "port", new ParamResolver( "gateway.port" ) );
- resolvers.put( "path", new ParamResolver( "gateway.path" ) );
- } else {
- resolvers.put( "url", new FixedResolver( frontend.toString() ) );
- resolvers.put( "addr", new FixedResolver( frontend.getHost() + ":" + frontend.getPort() ) );
- resolvers.put( "scheme", new FixedResolver( frontend.getScheme() ) );
- resolvers.put( "host", new FixedResolver( frontend.getHost() ) );
- resolvers.put( "port", new FixedResolver( Integer.toString( frontend.getPort() ) ) );
- resolvers.put( "path", new FixedResolver( frontend.getPath() ) );
- }
- resolvers.put( "topology", new FixedResolver( (String)environment.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE) ) );
- resolvers.put( "address", resolvers.get( "addr" ) );
- }
-
- @Override
- public void destroy() throws Exception {
- resolvers.clear();
- }
-
- @Override
- public List<String> resolve( UrlRewriteContext context, List<String> parameters ) throws Exception {
- String parameter = "url";
- if( parameters != null && parameters.size() > 0 ) {
- String first = parameters.get( 0 );
- if( first != null ) {
- parameter = first;
- }
- }
- parameter = parameter.trim().toLowerCase();
- UrlRewriteResolver resolver = resolvers.get( parameter );
- if( resolver == null ) {
- throw new IllegalArgumentException( RES.invalidFrontendFunctionParameter( parameter ) );
- }
- List<String> results = resolver.resolve( context, parameters );
- return results;
- }
-
- private static class ParamResolver implements UrlRewriteResolver {
-
- private String paramName;
-
- private ParamResolver( String paramName ) {
- this.paramName = paramName;
- }
-
- @Override
- public List<String> resolve( UrlRewriteContext context, List<String> parameter ) throws Exception {
- return context.getParameters().resolve( paramName );
- }
-
- }
-
- private static class FixedResolver implements UrlRewriteResolver {
-
- private List<String> fixedValues;
-
- private FixedResolver( String... fixedValues ) {
- this.fixedValues = Arrays.asList( fixedValues );
- }
-
- @Override
- public List<String> resolve( UrlRewriteContext context, List<String> parameter ) throws Exception {
- return fixedValues;
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteContextImpl.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteContextImpl.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteContextImpl.java
deleted file mode 100644
index 4a153d0..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteContextImpl.java
+++ /dev/null
@@ -1,152 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import org.apache.hadoop.gateway.filter.rewrite.i18n.UrlRewriteMessages;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
-import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.util.urltemplate.Evaluator;
-import org.apache.hadoop.gateway.util.urltemplate.Params;
-import org.apache.hadoop.gateway.util.urltemplate.Resolver;
-import org.apache.hadoop.gateway.util.urltemplate.Template;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public class UrlRewriteContextImpl implements UrlRewriteContext {
-
- private static final UrlRewriteMessages LOG = MessagesFactory.get( UrlRewriteMessages.class );
-
- private UrlRewriteEnvironment environment;
- private Resolver resolver;
- private Evaluator evaluator;
- private Map<String,UrlRewriteFunctionProcessor> functions;
- private ContextParameters params;
- private UrlRewriter.Direction direction;
- private Template originalUrl;
- private Template currentUrl;
-
- public UrlRewriteContextImpl(
- UrlRewriteEnvironment environment,
- Resolver resolver,
- Map<String,UrlRewriteFunctionProcessor> functions,
- UrlRewriter.Direction direction,
- Template url ) {
- this.environment = environment;
- this.resolver = resolver;
- this.functions = functions;
- this.params = new ContextParameters();
- this.evaluator = new ContextEvaluator();
- this.direction = direction;
- this.originalUrl = url;
- this.currentUrl = url;
- }
-
- @Override
- public UrlRewriter.Direction getDirection() {
- return direction;
- }
-
- @Override
- public Template getOriginalUrl() {
- return originalUrl;
- }
-
- @Override
- public Template getCurrentUrl() {
- return currentUrl;
- }
-
- @Override
- public void setCurrentUrl( Template url ) {
- currentUrl = url;
- }
-
- @Override
- public void addParameters( Params parameters ) {
- params.add( parameters );
- }
-
- @Override
- public Params getParameters() {
- return params;
- }
-
- @Override
- public Evaluator getEvaluator() {
- return evaluator;
- }
-
- private class ContextParameters implements Params {
-
- Map<String,List<String>> map = new HashMap<>();
-
- @Override
- public Set<String> getNames() {
- return map.keySet();
- }
-
- @Override
- public List<String> resolve( String name ) {
- List<String> values = map.get( name ); // Try to find the name in the context map.
- if( values == null ) {
- try {
- values = resolver.resolve( name );
- if( values == null ) {
- values = environment.resolve( name ); // Try to find the name in the environment.
- }
- } catch( Exception e ) {
- LOG.failedToFindValuesByParameter( name, e );
- // Ignore it and return null.
- }
- }
- return values;
- }
-
- public void add( Params params ) {
- for( String name : params.getNames() ) {
- map.put( name, params.resolve( name ) );
- }
- }
-
- }
-
- private class ContextEvaluator implements Evaluator {
-
- @Override
- public List<String> evaluate( String function, List<String> parameters ) {
- List<String> results = null;
- UrlRewriteFunctionProcessor processor = functions.get( function );
- if( processor != null ) {
- try {
- results = processor.resolve( UrlRewriteContextImpl.this, parameters );
- } catch( Exception e ) {
- LOG.failedToInvokeRewriteFunction( function, e );
- results = null;
- }
- }
- return results;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteDeploymentContributor.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteDeploymentContributor.java
deleted file mode 100644
index d48468c..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteDeploymentContributor.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.filter.rewrite.impl;
-
-import org.apache.hadoop.gateway.deploy.DeploymentContext;
-import org.apache.hadoop.gateway.deploy.ProviderDeploymentContributorBase;
-import org.apache.hadoop.gateway.descriptor.FilterDescriptor;
-import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor;
-import org.apache.hadoop.gateway.descriptor.ResourceDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFactory;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletContextListener;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletFilter;
-import org.apache.hadoop.gateway.filter.rewrite.i18n.UrlRewriteMessages;
-import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.topology.Provider;
-import org.apache.hadoop.gateway.topology.Service;
-import org.jboss.shrinkwrap.api.asset.StringAsset;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.List;
-
-public class UrlRewriteDeploymentContributor extends ProviderDeploymentContributorBase {
-
- private static final String PROVIDER_ROLE_NAME = "rewrite";
- private static final String PROVIDER_IMPL_NAME = "url-rewrite";
- private static final String PARAM_SERVICE_ROLE = "service.role";
- private static final UrlRewriteMessages LOG = MessagesFactory.get( UrlRewriteMessages.class );
-
- @Override
- public String getRole() {
- return PROVIDER_ROLE_NAME;
- }
-
- @Override
- public String getName() {
- return PROVIDER_IMPL_NAME;
- }
-
- public void initializeContribution( DeploymentContext context ) {
- context.addDescriptor( getRole(), UrlRewriteRulesDescriptorFactory.create() );
- }
-
- public void contributeProvider( DeploymentContext context, Provider provider ) {
- }
-
- public void finalizeContribution( DeploymentContext context ) {
- // Write the descriptor into the archive.
- UrlRewriteRulesDescriptor descriptor = context.getDescriptor( getRole() );
- StringWriter writer = new StringWriter();
- try {
- UrlRewriteRulesDescriptorFactory.store( descriptor, "xml", writer );
- } catch( IOException e ) {
- LOG.failedToWriteRulesDescriptor( e );
- }
- String asset = writer.toString();
- context.getWebArchive().addAsWebInfResource(
- new StringAsset( asset ),
- UrlRewriteServletContextListener.DESCRIPTOR_DEFAULT_FILE_NAME );
-
- // Tell the provider the location of the descriptor.
- context.getWebAppDescriptor().createListener().listenerClass( UrlRewriteServletContextListener.class.getName() );
- context.getWebAppDescriptor().createContextParam()
- .paramName( UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME )
- .paramValue( UrlRewriteServletContextListener.DESCRIPTOR_DEFAULT_LOCATION );
-// ServletType<WebAppDescriptor> servlet = findServlet( context, context.getTopology().getName() );
-// servlet.createInitParam()
-// .paramName( UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME )
-// .paramValue( DESCRIPTOR_FILE_NAME );
- }
-
- @Override
- public void contributeFilter(
- DeploymentContext context,
- Provider provider,
- Service service,
- ResourceDescriptor resource,
- List<FilterParamDescriptor> params ) {
- FilterDescriptor filterDescriptor = resource.addFilter();
- filterDescriptor.role( getRole() ).name( getName() ).impl( UrlRewriteServletFilter.class ).params( params );
- filterDescriptor.param().name(PARAM_SERVICE_ROLE).value(service.getRole());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterApplyDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterApplyDescriptorImpl.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterApplyDescriptorImpl.java
deleted file mode 100644
index ff3c4d5..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterApplyDescriptorImpl.java
+++ /dev/null
@@ -1,47 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor;
-
-public class UrlRewriteFilterApplyDescriptorImpl
- extends UrlRewriteFilterSelectorDescriptorBase<UrlRewriteFilterApplyDescriptor>
- implements UrlRewriteFilterApplyDescriptor {
-
- private String rule;
-
- @Override
- public String rule() {
- return rule;
- }
-
- @Override
- public UrlRewriteFilterApplyDescriptor rule( String rule ) {
- this.rule = rule;
- return this;
- }
-
- public void setRule( String rule ) {
- this.rule = rule;
- }
-
- public String getRule() {
- return rule;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterBufferDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterBufferDescriptorImpl.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterBufferDescriptorImpl.java
deleted file mode 100644
index d8ac83d..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterBufferDescriptorImpl.java
+++ /dev/null
@@ -1,37 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterDetectDescriptor;
-
-public class UrlRewriteFilterBufferDescriptorImpl
- extends UrlRewriteFilterGroupDescriptorBase
- implements UrlRewriteFilterBufferDescriptor {
-
- @Override
- public UrlRewriteFilterDetectDescriptor addDetect( String path, String value ) {
- UrlRewriteFilterDetectDescriptor detect = new UrlRewriteFilterDetectDescriptorImpl();
- detect.path( path );
- detect.value( value );
- addSelector( detect );
- return detect;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterContentDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterContentDescriptorImpl.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterContentDescriptorImpl.java
deleted file mode 100644
index 3d42537..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterContentDescriptorImpl.java
+++ /dev/null
@@ -1,80 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
-
-public class UrlRewriteFilterContentDescriptorImpl
- extends UrlRewriteFilterGroupDescriptorBase
- implements UrlRewriteFilterContentDescriptor {
-
- private String type;
-
- private String asType;
-
- public UrlRewriteFilterContentDescriptorImpl() {
- }
-
- @Override
- public String type() {
- return this.type;
- }
-
- @Override
- public String asType() {
- return asType;
- }
-
- @Override
- public UrlRewriteFilterContentDescriptor type( String type ) {
- this.type = type;
- return this;
- }
-
- @Override
- public UrlRewriteFilterContentDescriptor asType( String type ) {
- asType = type;
- return this;
- }
-
- public void setType(String type ) {
- type( type );
- }
-
- public String getType() {
- return type;
- }
-
- public String getAsType() {
- return asType;
- }
-
- public void setAsType(String asType) {
- this.asType = asType;
- }
-
- @Override
- public UrlRewriteFilterBufferDescriptor addBuffer( String path ) {
- UrlRewriteFilterBufferDescriptor descriptor = new UrlRewriteFilterBufferDescriptorImpl();
- descriptor.path( path );
- addSelector( descriptor );
- return descriptor;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterDescriptorImpl.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterDescriptorImpl.java
deleted file mode 100644
index 5a72547..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterDescriptorImpl.java
+++ /dev/null
@@ -1,87 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor;
-import org.apache.hadoop.gateway.util.MimeTypeMap;
-
-import javax.activation.MimeType;
-import javax.activation.MimeTypeParseException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class UrlRewriteFilterDescriptorImpl implements UrlRewriteFilterDescriptor {
-
- private String name;
- private List<UrlRewriteFilterContentDescriptor> contentList = new ArrayList<UrlRewriteFilterContentDescriptor>();
- private MimeTypeMap<UrlRewriteFilterContentDescriptor> contentMap = new MimeTypeMap<UrlRewriteFilterContentDescriptor>();
-
- public UrlRewriteFilterDescriptorImpl() {
- }
-
- @Override
- public String name() {
- return this.name;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public UrlRewriteFilterDescriptor name( String name ) {
- this.name = name;
- return this;
- }
-
- public void setName( String name ) {
- this.name = name;
- }
-
- @Override
- public List<UrlRewriteFilterContentDescriptor> getContents() {
- return contentList;
- }
-
- @Override
- public UrlRewriteFilterContentDescriptor getContent( String type ) {
- return contentMap.get( type );
- }
-
- @Override
- public UrlRewriteFilterContentDescriptor getContent( MimeType type ) {
- return contentMap.get( type );
- }
-
- @Override
- public UrlRewriteFilterContentDescriptor addContent( String type ) {
- UrlRewriteFilterContentDescriptorImpl impl = new UrlRewriteFilterContentDescriptorImpl();
- impl.type( type );
- contentList.add( impl );
- try {
- contentMap.put( new MimeType( type ), impl );
- } catch( MimeTypeParseException e ) {
- throw new IllegalArgumentException( type, e );
- }
- return impl;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterDetectDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterDetectDescriptorImpl.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterDetectDescriptorImpl.java
deleted file mode 100644
index b4b14a6..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterDetectDescriptorImpl.java
+++ /dev/null
@@ -1,65 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterDetectDescriptor;
-
-public class UrlRewriteFilterDetectDescriptorImpl
- extends UrlRewriteFilterGroupDescriptorBase
- implements UrlRewriteFilterDetectDescriptor {
-
- private String value;
- private Object compiledValue;
-
- @Override
- public String value() {
- return value;
- }
-
- @Override
- public UrlRewriteFilterDetectDescriptor value( String value ) {
- this.value = value;
- return this;
- }
-
- public void setValue( String value ) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
-
- @Override
- public <C> C compiledValue() {
- return (C)compiledValue;
- }
-
- @Override
- public UrlRewriteFilterDetectDescriptor compiledValue( String compiledValue ) {
- this.compiledValue = compiledValue;
- return this;
- }
-
- @Override
- public <C> C compiledValue( Compiler<C> compiler ) {
- compiledValue = compiler.compile( value, (C)compiledValue );
- return (C)compiledValue;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterGroupDescriptorBase.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterGroupDescriptorBase.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterGroupDescriptorBase.java
deleted file mode 100644
index 228cfa4..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterGroupDescriptorBase.java
+++ /dev/null
@@ -1,52 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterGroupDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class UrlRewriteFilterGroupDescriptorBase
- extends UrlRewriteFilterSelectorDescriptorBase
- implements UrlRewriteFilterGroupDescriptor {
-
- private List<UrlRewriteFilterPathDescriptor> selectors = new ArrayList<UrlRewriteFilterPathDescriptor>();
-
- @Override
- public List<UrlRewriteFilterPathDescriptor> getSelectors() {
- return selectors;
- }
-
- @Override
- public void addSelector( UrlRewriteFilterPathDescriptor selector ) {
- this.selectors.add( selector );
- }
-
- @Override
- public UrlRewriteFilterApplyDescriptor addApply( String path, String rule ) {
- UrlRewriteFilterApplyDescriptor apply = new UrlRewriteFilterApplyDescriptorImpl();
- apply.path( path );
- apply.rule( rule );
- addSelector( apply );
- return apply;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterReader.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterReader.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterReader.java
deleted file mode 100644
index c291468..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterReader.java
+++ /dev/null
@@ -1,39 +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.rewrite.impl;
-
-import java.util.regex.Pattern;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor;
-
-
-public interface UrlRewriteFilterReader {
-
- public String filterValueString( String name, String value, String rule );
-
- public static class RegexCompiler implements UrlRewriteFilterPathDescriptor.Compiler<Pattern> {
- @Override
- public Pattern compile( String expression, Pattern compiled ) {
- if( compiled != null ) {
- return compiled;
- } else {
- return Pattern.compile( expression );
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterScopeDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterScopeDescriptorImpl.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterScopeDescriptorImpl.java
deleted file mode 100644
index bdebe69..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterScopeDescriptorImpl.java
+++ /dev/null
@@ -1,25 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterScopeDescriptor;
-
-public class UrlRewriteFilterScopeDescriptorImpl
- extends UrlRewriteFilterGroupDescriptorBase
- implements UrlRewriteFilterScopeDescriptor {
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterSelectorDescriptorBase.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterSelectorDescriptorBase.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterSelectorDescriptorBase.java
deleted file mode 100644
index ff4ab22..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFilterSelectorDescriptorBase.java
+++ /dev/null
@@ -1,64 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor;
-
-public class UrlRewriteFilterSelectorDescriptorBase<T> implements UrlRewriteFilterPathDescriptor<T> {
-
- private String path;
- private Object compiledPath;
-
- @Override
- public String path() {
- return path;
- }
-
- @Override
- public T path( String path ) {
- this.path = path;
- return (T)this;
- }
-
- public void setPath( String path ) {
- this.path = path;
- }
-
- public String getPath() {
- return path;
- }
-
- @Override
- public <C> C compiledPath() {
- return (C)compiledPath;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public T compiledPath( Object compiledPath ) {
- this.compiledPath = compiledPath;
- return (T)this;
- }
-
- @Override
- public <C> C compiledPath( Compiler<C> compiler ) {
- compiledPath = compiler.compile( path, (C)compiledPath );
- return (C)compiledPath;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFunctionProcessorFactory.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFunctionProcessorFactory.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFunctionProcessorFactory.java
deleted file mode 100644
index 2676cfc..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteFunctionProcessorFactory.java
+++ /dev/null
@@ -1,113 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptorFactory;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
-
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.ServiceLoader;
-
-public abstract class UrlRewriteFunctionProcessorFactory {
-
- private static final Map<Class<? extends UrlRewriteFunctionDescriptor>,Map<String,Class<? extends UrlRewriteFunctionProcessor>>> MAP
- = loadProcessors();
-
- private UrlRewriteFunctionProcessorFactory() {
- }
-
- public static UrlRewriteFunctionProcessor create( String name, UrlRewriteFunctionDescriptor descriptor )
- throws IllegalAccessException, InstantiationException {
- UrlRewriteFunctionProcessor processor;
- if( descriptor == null ) {
- descriptor = UrlRewriteFunctionDescriptorFactory.create( name );
- }
- Map<String,Class<? extends UrlRewriteFunctionProcessor>> typeMap;
- typeMap = MAP.get( descriptor.getClass() );
- if( typeMap == null ) {
- Class<? extends UrlRewriteFunctionDescriptor> descriptorInterface = getDescriptorInterface( descriptor );
- typeMap = MAP.get( descriptorInterface );
- }
- if( typeMap == null ) {
- throw new IllegalArgumentException( descriptor.getClass().getName() );
- } else {
- Class<? extends UrlRewriteFunctionProcessor> processorClass = typeMap.get( name );
- if( processorClass == null ) {
- throw new IllegalArgumentException( name );
- } else {
- processor = processorClass.newInstance();
- }
- }
- return processor;
- }
-
- private static Map<Class<? extends UrlRewriteFunctionDescriptor>,Map<String,Class<? extends UrlRewriteFunctionProcessor>>> loadProcessors() {
- Map<Class<? extends UrlRewriteFunctionDescriptor>,Map<String,Class<? extends UrlRewriteFunctionProcessor>>> descriptorMap
- = new HashMap<>();
- ServiceLoader<UrlRewriteFunctionProcessor> processors = ServiceLoader.load( UrlRewriteFunctionProcessor.class );
- for( UrlRewriteFunctionProcessor processor : processors ) {
- Class<? extends UrlRewriteFunctionDescriptor> descriptorInterface = getDescriptorInterface( processor );
- Map<String,Class<? extends UrlRewriteFunctionProcessor>> typeMap = descriptorMap.get( descriptorInterface );
- if( typeMap == null ) {
- typeMap = new HashMap<>();
- descriptorMap.put( descriptorInterface, typeMap );
- }
- String functionName = processor.name();
- typeMap.put( functionName, processor.getClass() );
- }
- return descriptorMap;
- }
-
- private static Class<? extends UrlRewriteFunctionDescriptor> getDescriptorInterface(
- UrlRewriteFunctionDescriptor descriptor ) {
- Class<? extends UrlRewriteFunctionDescriptor> descriptorClass = null;
- for( Type interfaceType : descriptor.getClass().getGenericInterfaces() ) {
- Class genericClass = (Class)interfaceType;
- if( UrlRewriteFunctionDescriptor.class.isAssignableFrom( genericClass ) ) {
- descriptorClass = uncheckedDescriptorClassCast( genericClass );
- break;
- }
- }
- return descriptorClass;
- }
-
- private static Class<? extends UrlRewriteFunctionDescriptor> getDescriptorInterface(
- UrlRewriteFunctionProcessor processor ) {
- Class<? extends UrlRewriteFunctionDescriptor> descriptorClass = null;
- Class<? extends UrlRewriteFunctionProcessor> processorClass = processor.getClass();
- for( Type interfaceType : processorClass.getGenericInterfaces() ) {
- if( UrlRewriteFunctionProcessor.class.isAssignableFrom(
- (Class)((ParameterizedType)interfaceType).getRawType() ) ) {
- ParameterizedType interfaceClass = (ParameterizedType)interfaceType;
- descriptorClass = uncheckedDescriptorClassCast( interfaceClass.getActualTypeArguments()[ 0 ] );
- break;
- }
- }
- return descriptorClass;
- }
-
- @SuppressWarnings("unchecked")
- private static Class<? extends UrlRewriteFunctionDescriptor> uncheckedDescriptorClassCast( Type type ) {
- return (Class<? extends UrlRewriteFunctionDescriptor>)type;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/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
deleted file mode 100644
index de9331b..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
+++ /dev/null
@@ -1,265 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.AbstractGatewayFilter;
-import org.apache.hadoop.gateway.filter.GatewayRequestWrapper;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletContextListener;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletFilter;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStreamFilterFactory;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import org.apache.hadoop.gateway.filter.rewrite.i18n.UrlRewriteMessages;
-import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.util.MimeTypes;
-import org.apache.hadoop.gateway.util.urltemplate.Parser;
-import org.apache.hadoop.gateway.util.urltemplate.Resolver;
-import org.apache.hadoop.gateway.util.urltemplate.Template;
-
-import javax.activation.MimeType;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.HttpServletRequest;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-import java.net.URISyntaxException;
-import java.net.URLDecoder;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.List;
-
-import static org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteUtil.pickFirstRuleWithEqualsIgnoreCasePathMatch;
-
-public class UrlRewriteRequest extends GatewayRequestWrapper implements Resolver {
-
- private static final UrlRewriteMessages LOG = MessagesFactory.get( UrlRewriteMessages.class );
- private static final String[] EMPTY_STRING_ARRAY = new String[]{};
-
- private FilterConfig config;
- private UrlRewriter rewriter;
- private String urlRuleName;
- private String bodyFilterName;
- private String headersFilterName;
- private UrlRewriteFilterContentDescriptor headersFilterConfig;
- private String cookiesFilterName;
-
- /**
- * Constructs a request object wrapping the given request.
- *
- * @throws IllegalArgumentException if the request is null
- */
- public UrlRewriteRequest( FilterConfig config, HttpServletRequest request ) throws IOException {
- super( request );
- this.config = config;
- this.rewriter = UrlRewriteServletContextListener.getUrlRewriter( config.getServletContext() );
- this.urlRuleName = config.getInitParameter( UrlRewriteServletFilter.REQUEST_URL_RULE_PARAM );
- this.bodyFilterName = config.getInitParameter( UrlRewriteServletFilter.REQUEST_BODY_FILTER_PARAM );
- this.headersFilterName = config.getInitParameter( UrlRewriteServletFilter.REQUEST_HEADERS_FILTER_PARAM );
- this.headersFilterConfig = getRewriteFilterConfig( headersFilterName, UrlRewriteServletFilter.HEADERS_MIME_TYPE );
- this.cookiesFilterName = config.getInitParameter( UrlRewriteServletFilter.REQUEST_COOKIES_FILTER_PARAM );
- }
-
- private Template getSourceUrl() {
- Template urlTemplate;
- //KNOX-439[
- //StringBuffer urlString = super.getRequestURL();
- StringBuffer urlString = new StringBuffer( 128 );
- urlString.append( getScheme() );
- urlString.append( "://" );
- urlString.append( getServerName() );
- urlString.append( ":" );
- urlString.append( getServerPort() );
- urlString.append( super.getRequestURI() );
- //]
- String queryString = super.getQueryString();
- if( queryString != null ) {
- urlString.append( '?' );
- urlString.append( queryString );
- }
- try {
- urlTemplate = Parser.parseLiteral( urlString.toString() );
- } catch( URISyntaxException e ) {
- LOG.failedToParseValueForUrlRewrite( urlString.toString() );
- // Shouldn't be possible given that the URL is constructed from parts of an existing URL.
- urlTemplate = null;
- }
- return urlTemplate;
- }
-
- // Note: Source url was added to the request attributes by the GatewayFilter doFilter method.
- private Template getTargetUrl() {
- boolean rewriteRequestUrl = true;
- Template targetUrl;
- if( rewriteRequestUrl ) {
- targetUrl = (Template)getAttribute( AbstractGatewayFilter.TARGET_REQUEST_URL_ATTRIBUTE_NAME );
- if( targetUrl == null ) {
- Template sourceUrl = getSourceUrl();
- targetUrl = rewriter.rewrite( this, sourceUrl, UrlRewriter.Direction.IN, urlRuleName );
- setAttribute( AbstractGatewayFilter.TARGET_REQUEST_URL_ATTRIBUTE_NAME, targetUrl );
- }
- } else {
- targetUrl = (Template)getAttribute( AbstractGatewayFilter.SOURCE_REQUEST_URL_ATTRIBUTE_NAME );
- }
- return targetUrl;
- }
-
- private String[] splitTargetUrl( Template url ) {
- if( url == null ) {
- return EMPTY_STRING_ARRAY;
- } else {
- String s = url.toString();
- return s.split( "\\?" );
- }
- }
-
- @Override
- public StringBuffer getRequestURL() {
- return new StringBuffer( getRequestURI() );
- }
-
- //TODO: I think this method is implemented wrong based on the HttpServletRequest.getRequestURI docs.
- // It should not include the scheme or authority parts.
- @Override
- public String getRequestURI() {
- String[] split = splitTargetUrl( getTargetUrl() );
- if( split.length > 0 ) {
- return split[0];
- } else {
- return "";
- }
- }
-
- @Override
- public String getQueryString() {
- String[] split = splitTargetUrl( getTargetUrl() );
- if( split.length > 1 ) {
- try {
- return URLDecoder.decode(split[1], "UTF-8");
- } catch ( UnsupportedEncodingException e ) {
- LOG.failedToDecodeQueryString(split[1], e);
- return split[1];
- }
- } else {
- return null;
- }
- }
-
- private String rewriteValue( UrlRewriter rewriter, String value, String rule ) {
- try {
- Template input = Parser.parseLiteral( value );
- Template output = rewriter.rewrite( this, input, UrlRewriter.Direction.IN, rule );
- value = output.getPattern();
- } catch( URISyntaxException e ) {
- LOG.failedToParseValueForUrlRewrite( value );
- }
- return value;
- }
-
- @Override
- public String getHeader( String name ) {
- String value = super.getHeader( name );
- if( value != null ) {
- value = rewriteValue( rewriter, super.getHeader( name ), pickFirstRuleWithEqualsIgnoreCasePathMatch( headersFilterConfig, name ) );
- }
- return value;
- }
-
- @SuppressWarnings("unchecked")
- public Enumeration getHeaders( String name ) {
- return new EnumerationRewriter( rewriter, super.getHeaders( name ), pickFirstRuleWithEqualsIgnoreCasePathMatch( headersFilterConfig, name ) );
- }
-
- @Override
- public List<String> resolve( String name ) {
- return Arrays.asList( config.getInitParameter( name ) );
- }
-
- private class EnumerationRewriter implements Enumeration<String> {
-
- private UrlRewriter rewriter;
- private Enumeration<String> delegate;
- private String rule;
-
- private EnumerationRewriter( UrlRewriter rewriter, Enumeration<String> delegate, String rule ) {
- this.rewriter = rewriter;
- this.delegate = delegate;
- this.rule = rule;
- }
-
- @Override
- public boolean hasMoreElements() {
- return delegate.hasMoreElements();
- }
-
- @Override
- public String nextElement() {
- return rewriteValue( rewriter, delegate.nextElement(), rule );
- }
- }
-
- @Override
- public ServletInputStream getInputStream() throws IOException {
- ServletInputStream input = super.getInputStream();
- if( getContentLength() != 0 ) {
- MimeType mimeType = getMimeType();
- UrlRewriteFilterContentDescriptor filterContentConfig = getRewriteFilterConfig( bodyFilterName, mimeType );
- if (filterContentConfig != null) {
- String asType = filterContentConfig.asType();
- if ( asType != null && asType.trim().length() > 0 ) {
- mimeType = MimeTypes.create(asType, getCharacterEncoding());
- }
- }
- InputStream stream = UrlRewriteStreamFilterFactory.create( mimeType, null, input, rewriter, this, UrlRewriter.Direction.IN, filterContentConfig );
- input = new UrlRewriteRequestStream( stream );
- }
- return input;
- }
-
- @Override
- public BufferedReader getReader() throws IOException {
- return new BufferedReader( new InputStreamReader( getInputStream(), getCharacterEncoding() ) );
- }
-
- @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;
- }
-
- private UrlRewriteFilterContentDescriptor getRewriteFilterConfig( String filterName, MimeType mimeType ) {
- UrlRewriteFilterContentDescriptor filterContentConfig = null;
- UrlRewriteRulesDescriptor rewriteConfig = rewriter.getConfig();
- if( rewriteConfig != null ) {
- UrlRewriteFilterDescriptor filterConfig = rewriteConfig.getFilter( filterName );
- if( filterConfig != null ) {
- filterContentConfig = filterConfig.getContent( mimeType );
- }
- }
- return filterContentConfig;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequestStream.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequestStream.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequestStream.java
deleted file mode 100644
index 1904d15..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequestStream.java
+++ /dev/null
@@ -1,39 +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.rewrite.impl;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.hadoop.gateway.servlet.SynchronousServletInputStreamAdapter;
-
-//TODO: This needs to be coded much more efficiently!
-public class UrlRewriteRequestStream extends SynchronousServletInputStreamAdapter {
-
- private InputStream stream;
-
- public UrlRewriteRequestStream( InputStream stream ) {
- this.stream = stream;
- }
-
- @Override
- public int read() throws IOException {
- return stream.read();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
deleted file mode 100644
index d4e31e3..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
+++ /dev/null
@@ -1,330 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.GatewayResponseWrapper;
-import org.apache.hadoop.gateway.filter.ResponseStreamer;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletContextListener;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletFilter;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStreamFilterFactory;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import org.apache.hadoop.gateway.filter.rewrite.i18n.UrlRewriteMessages;
-import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.util.MimeTypes;
-import org.apache.hadoop.gateway.util.Urls;
-import org.apache.hadoop.gateway.util.urltemplate.Params;
-import org.apache.hadoop.gateway.util.urltemplate.Parser;
-import org.apache.hadoop.gateway.util.urltemplate.Template;
-import org.apache.commons.io.IOUtils;
-
-import javax.activation.MimeType;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import java.io.BufferedInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.URISyntaxException;
-import java.net.UnknownHostException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
-import java.util.zip.ZipException;
-
-import static org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteUtil.getRewriteFilterConfig;
-import static org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteUtil.pickFirstRuleWithEqualsIgnoreCasePathMatch;
-
-/**
- *
- */
-public class UrlRewriteResponse extends GatewayResponseWrapper implements Params, ResponseStreamer {
-
- private static final UrlRewriteMessages LOG = MessagesFactory.get( UrlRewriteMessages.class );
-
- // An 8K buffer better matches the underlying buffer sizes.
- // Testing with 16K made no appreciable difference.
- private static final int STREAM_BUFFER_SIZE = 8 * 1024;
-
- private static final Set<String> IGNORE_HEADER_NAMES = new HashSet<>();
- static {
- IGNORE_HEADER_NAMES.add( "Content-Length" );
- }
-
- private static final String REQUEST_PARAM_PREFIX = "request.";
- private static final String CLUSTER_PARAM_PREFIX = "cluster.";
- private static final String GATEWAY_PARAM_PREFIX = "gateway.";
- public static final String INBOUND_QUERY_PARAM_PREFIX = "query.param.";
-
- private UrlRewriter rewriter;
- private FilterConfig config;
- private HttpServletRequest request;
- private HttpServletResponse response;
- private ServletOutputStream output;
- private String bodyFilterName;
- private String headersFilterName;
- private UrlRewriteFilterContentDescriptor headersFilterConfig;
- private String cookiesFilterName;
- private String xForwardedHostname;
- private String xForwardedPort;
- private String xForwardedScheme;
-
- public UrlRewriteResponse( FilterConfig config, HttpServletRequest request, HttpServletResponse response )
- throws IOException {
- super( response );
- this.rewriter = UrlRewriteServletContextListener.getUrlRewriter( config.getServletContext() );
- this.config = config;
- this.request = request;
- this.response = response;
- this.output = null;
- getXForwardedHeaders();
- this.bodyFilterName = config.getInitParameter( UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM );
- this.headersFilterName = config.getInitParameter( UrlRewriteServletFilter.RESPONSE_HEADERS_FILTER_PARAM );
- this.headersFilterConfig = getRewriteFilterConfig( rewriter.getConfig(), headersFilterName, UrlRewriteServletFilter.HEADERS_MIME_TYPE );
- this.cookiesFilterName = config.getInitParameter( UrlRewriteServletFilter.RESPONSE_COOKIES_FILTER_PARAM );
- }
-
- protected boolean ignoreHeader( String name ) {
- return IGNORE_HEADER_NAMES.contains( name );
- }
-
- private String rewriteValue( String value, String rule ) {
- try {
- Template input = Parser.parseLiteral( value );
- Template output = rewriter.rewrite( this, input, UrlRewriter.Direction.OUT, rule );
- if( output != null ) {
- value = output.toString();
- }
- } catch( URISyntaxException e ) {
- LOG.failedToParseValueForUrlRewrite( value );
- }
- return value;
- }
-
- // Ignore the Content-Length from the dispatch respond since the respond body may be rewritten.
- @Override
- public void setHeader( String name, String value ) {
- if( !ignoreHeader( name) ) {
- value = rewriteValue( value, pickFirstRuleWithEqualsIgnoreCasePathMatch( headersFilterConfig, name ) );
- super.setHeader( name, value );
- }
- }
-
- // Ignore the Content-Length from the dispatch respond since the respond body may be rewritten.
- @Override
- public void addHeader( String name, String value ) {
- if( !ignoreHeader( name ) ) {
- String rule = pickFirstRuleWithEqualsIgnoreCasePathMatch( headersFilterConfig, name );
- value = rewriteValue( value, rule );
- super.addHeader( name, value );
- }
- }
-
- @Override
- public OutputStream getRawOutputStream() throws IOException {
- return response.getOutputStream();
- }
-
- @Override
- public void streamResponse( InputStream input, OutputStream output ) throws IOException {
- InputStream inStream;
- OutputStream outStream;
- boolean isGzip = false;
- BufferedInputStream inBuffer = new BufferedInputStream(input);
- try {
- // Use this way to check whether the input stream is gzip compressed, in case
- // the content encoding header is unknown, as it could be unset in inbound response
- inBuffer.mark(STREAM_BUFFER_SIZE);
- inStream = new GZIPInputStream(inBuffer);
- isGzip = true;
- } catch (ZipException e) {
- inBuffer.reset();
- inStream = inBuffer;
- } catch (IOException e) {
- inBuffer.reset();
- inStream = inBuffer;
- }
-
- MimeType mimeType = getMimeType();
- UrlRewriteFilterContentDescriptor filterContentConfig =
- getRewriteFilterConfig( rewriter.getConfig(), bodyFilterName, mimeType );
- if (filterContentConfig != null) {
- String asType = filterContentConfig.asType();
- if ( asType != null && asType.trim().length() > 0 ) {
- mimeType = MimeTypes.create(asType, getCharacterEncoding());
- }
- }
- InputStream filteredInput = UrlRewriteStreamFilterFactory.create(
- mimeType, null, inStream, rewriter, this, UrlRewriter.Direction.OUT, filterContentConfig );
- outStream = (isGzip) ? new GZIPOutputStream(output) : output;
- IOUtils.copyLarge( filteredInput, outStream, new byte[STREAM_BUFFER_SIZE] );
- //KNOX-685: outStream.flush();
- outStream.close();
- }
-
- //TODO: Need to buffer the output here and when it is closed, rewrite it and then write the result to the stream.
- // This should only happen if the caller isn't using the streaming model.
- @Override
- public ServletOutputStream getOutputStream() throws IOException {
- if( output == null ) {
- output = new UrlRewriteResponseStream( this );
- }
- return output;
- }
-
- @Override
- public Set<String> getNames() {
- return Collections.emptySet();
- }
-
- @Override
- @SuppressWarnings( "unchecked" )
- public List<String> resolve( String name ) {
- if( name.startsWith( REQUEST_PARAM_PREFIX ) ) {
- return Arrays.asList( getRequestParam( name.substring( REQUEST_PARAM_PREFIX.length() ) ) );
- } else if ( name.startsWith( GATEWAY_PARAM_PREFIX ) ) {
- return Arrays.asList( getGatewayParam( name.substring( GATEWAY_PARAM_PREFIX.length() ) ) );
- } else if ( name.startsWith( CLUSTER_PARAM_PREFIX ) ) {
- return Arrays.asList( getClusterParam( name.substring( GATEWAY_PARAM_PREFIX.length() ) ) );
- } else if ( name.startsWith( INBOUND_QUERY_PARAM_PREFIX ) ) {
- return getInboundQueryParam(name.substring(INBOUND_QUERY_PARAM_PREFIX.length()));
- } else {
- return Arrays.asList( config.getInitParameter( name ) );
- }
- }
-
- // KNOX-464: Doing this because Jetty only returns the string version of the IP address for request.getLocalName().
- // Hopefully the local hostname will be cached so this will not be a significant performance hit.
- // Previously this was an inline request.getServerName() but this ended up mixing the hostname from the Host header
- // and the local port which was making load balancer configuration difficult if not impossible.
- private String getRequestLocalHostName() {
- String hostName = request.getLocalName();
- try {
- hostName = InetAddress.getByName( hostName ).getHostName();
- } catch( UnknownHostException e ) {
- // Ignore it and use the original hostname.
- }
- return hostName;
- }
-
- private String getGatewayParam( String name ) {
- if( "url".equals( name ) ) {
- if( xForwardedPort == null ) {
- return xForwardedScheme + "://" + xForwardedHostname + request.getContextPath();
- } else {
- return xForwardedScheme + "://" + xForwardedHostname + ":" + xForwardedPort + request.getContextPath();
- }
- } else if( "scheme".equals( name ) ) {
- return xForwardedScheme;
- } else if( "host".equals( name ) ) {
- return xForwardedHostname;
- } else if( "port".equals( name ) ) {
- return xForwardedPort;
- } else if( "addr".equals( name ) || "address".equals( name ) ) {
- if( xForwardedPort == null ) {
- return xForwardedHostname;
- } else {
- return xForwardedHostname + ":" + xForwardedPort;
- }
- } else if( "path".equals( name ) ) {
- return request.getContextPath();
- } else {
- return null;
- }
- }
-
- private String getClusterParam( String name ) {
- if( "name".equals( name ) ) {
- return config.getServletContext().getServletContextName();
- } else {
- return null;
- }
- }
-
- private List <String> getInboundQueryParam(String name ){
- List <String> inboundHosts = null;
- if( this.request!=null )
- inboundHosts =
- Arrays.asList( this.request.getParameterValues(name));
- return inboundHosts;
- }
-
- private String getRequestParam( String name ) {
- if( "host".equals( name ) ) {
- return request.getServerName();
- } else if ( "port".equals( name ) ) {
- return Integer.toString( request.getLocalPort() );
- } else if ( "scheme".equals( name ) ) {
- return request.getScheme();
- } else if ( "context-path".equals( name ) ) {
- return Urls.stripLeadingSlash( request.getContextPath() );
- } else {
- config.getServletContext().getServletContextName();
- return null;
- }
- }
-
- @SuppressWarnings("deprecation")
- public String encodeUrl( String url ) {
- return this.encodeURL( url );
- }
-
- //TODO: Route these through the rewriter.
- public String encodeURL( String url ) {
- throw new UnsupportedOperationException();
- }
-
- @SuppressWarnings("deprecation")
- public String encodeRedirectUrl( String url ) {
- return this.encodeRedirectURL( url );
- }
-
- //TODO: Route these through the rewriter.
- public String encodeRedirectURL( String url ) {
- throw new UnsupportedOperationException();
- }
-
- private void getXForwardedHeaders() {
- xForwardedHostname = request.getHeader( "X-Forwarded-Host" );
- xForwardedPort = request.getHeader( "X-Forwarded-Port" );
- xForwardedScheme = request.getHeader( "X-Forwarded-Proto" );
- if ( xForwardedScheme == null ) {
- xForwardedScheme = request.getScheme();
- }
- if ( xForwardedHostname != null ) {
- int separator = xForwardedHostname.indexOf( ":" );
- if ( separator > 0 ) {
- //a specific port in the forwarded host wins
- xForwardedPort = xForwardedHostname.substring(separator + 1, xForwardedHostname.length());
- xForwardedHostname = xForwardedHostname.substring( 0, separator );
- }
- } else {
- xForwardedHostname = getRequestLocalHostName();
- xForwardedPort = Integer.toString( request.getLocalPort() );
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponseStream.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponseStream.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponseStream.java
deleted file mode 100644
index 41117bd..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponseStream.java
+++ /dev/null
@@ -1,53 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.GatewayResponse;
-import org.apache.hadoop.gateway.servlet.SynchronousServletOutputStreamAdapter;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-//TODO: This needs to be coded much more efficiently!
-public class UrlRewriteResponseStream extends SynchronousServletOutputStreamAdapter {
-
- private static final int DEFAULT_BUFFER_SIZE = 1024;
-
- private GatewayResponse response;
- private ByteArrayOutputStream buffer;
-
- public UrlRewriteResponseStream( GatewayResponse response ) {
- this.response = response;
- this.buffer = new ByteArrayOutputStream( DEFAULT_BUFFER_SIZE );
- }
-
- @Override
- public void write( int b ) throws IOException {
- buffer.write( b );
- }
-
- @Override
- public void close() throws IOException {
- InputStream stream = new ByteArrayInputStream( buffer.toByteArray() );
- response.streamResponse( stream ) ;
- stream.close();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleDescriptorImpl.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleDescriptorImpl.java
deleted file mode 100644
index c0396a2..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleDescriptorImpl.java
+++ /dev/null
@@ -1,194 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStepDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFlowDescriptorBase;
-import org.apache.hadoop.gateway.util.urltemplate.Parser;
-import org.apache.hadoop.gateway.util.urltemplate.Template;
-
-import java.net.URISyntaxException;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-public class UrlRewriteRuleDescriptorImpl extends UrlRewriteFlowDescriptorBase<UrlRewriteRuleDescriptor> implements UrlRewriteRuleDescriptor {
-
- private String name;
- private String scope;
- private String pattern;
- private Template template;
- private EnumSet<UrlRewriter.Direction> directions;
-
- public UrlRewriteRuleDescriptorImpl() {
- super( "rule" );
- }
-
- @Override
- public String name() {
- return this.name;
- }
-
- @Override
- public UrlRewriteRuleDescriptor name( String name ) {
- this.name = name;
- return this;
- }
-
- public void setName( String name ) {
- name( name );
- }
-
- public String getName() {
- return name;
- }
-
- public String getScope() {
- return scope;
- }
-
- public void setScope(String scope) {
- scope( scope );
- }
-
- @Override
- public String scope() {
- return scope;
- }
-
- @Override
- public UrlRewriteStepDescriptor scope( String scope ) {
- this.scope = scope;
- return this;
- }
-
- @Override
- public EnumSet<UrlRewriter.Direction> directions() {
- return directions;
- }
-
- @Override
- public UrlRewriteRuleDescriptor directions( String directions ) {
- this.directions = parseDirections( directions );
- return this;
- }
-
- public void setDirections( String directions ) {
- directions( directions );
- }
-
- public void setDirection( String directions ) {
- directions( directions );
- }
-
- public void setDir( String directions ) {
- directions( directions );
- }
-
- public String getDir() {
- String s = null;
- if( directions != null ) {
- StringBuilder sb = new StringBuilder();
- for( UrlRewriter.Direction direction: directions ) {
- if( sb.length() > 0 ) {
- sb.append( ',' );
- }
- sb.append( direction.toString() );
- }
- s = sb.toString();
- }
- return s;
- }
-
- @Override
- public UrlRewriteRuleDescriptor directions( UrlRewriter.Direction... directions ) {
- return this;
- }
-
- @Override
- public String pattern() {
- return pattern;
- }
-
- @Override
- public UrlRewriteRuleDescriptor pattern( String pattern ) throws URISyntaxException {
- this.pattern = pattern;
- this.template = Parser.parseTemplate( pattern );
- return this;
- }
-
- public void setPattern( String pattern ) throws URISyntaxException {
- pattern( pattern );
- }
-
- public void setUrl( String pattern ) throws URISyntaxException {
- pattern( pattern );
- }
-
- public String getPattern() {
- return pattern();
- }
-
- @Override
- public Template template() {
- return template;
- }
-
- @Override
- public UrlRewriteRuleDescriptor template( Template template ) {
- this.template = template;
- this.pattern = template.toString();
- return this;
- }
-
- private static EnumSet<UrlRewriter.Direction> parseDirections( String directions ) {
- EnumSet<UrlRewriter.Direction> set = EnumSet.noneOf( UrlRewriter.Direction.class );
- StringTokenizer parser = new StringTokenizer( directions, " ,;:/|+" );
- while( parser.hasMoreTokens() ) {
- UrlRewriter.Direction direction = parseDirection( parser.nextToken() );
- if( direction != null ) {
- set.add( direction );
- }
- }
- return set;
- }
-
- private static UrlRewriter.Direction parseDirection( String direction ) {
- direction = direction.trim().toLowerCase();
- return directionNameMap.get( direction );
- }
-
- private static Map<String,UrlRewriter.Direction> directionNameMap = new HashMap<>();
- static {
- directionNameMap.put( "inbound", UrlRewriter.Direction.IN );
- directionNameMap.put( "in", UrlRewriter.Direction.IN );
- directionNameMap.put( "i", UrlRewriter.Direction.IN );
- directionNameMap.put( "request", UrlRewriter.Direction.IN );
- directionNameMap.put( "req", UrlRewriter.Direction.IN );
-
- directionNameMap.put( "outbound", UrlRewriter.Direction.OUT );
- directionNameMap.put( "out", UrlRewriter.Direction.OUT );
- directionNameMap.put( "o", UrlRewriter.Direction.OUT );
- directionNameMap.put( "response", UrlRewriter.Direction.OUT );
- directionNameMap.put( "res", UrlRewriter.Direction.OUT );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleProcessorHolder.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleProcessorHolder.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleProcessorHolder.java
deleted file mode 100644
index 708fd8c..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleProcessorHolder.java
+++ /dev/null
@@ -1,65 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.config.GatewayConfig;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.ext.ScopedMatcher;
-
-import java.util.List;
-
-public class UrlRewriteRuleProcessorHolder extends UrlRewriteStepProcessorHolder {
-
- private String ruleName;
-
- private String scope;
-
- public void initialize( UrlRewriteEnvironment environment, UrlRewriteRuleDescriptor descriptor ) throws Exception {
- super.initialize( environment, descriptor );
- ruleName = descriptor.name();
- //if a scope is set in the rewrite file, use that
- if (descriptor.scope() != null) {
- scope = descriptor.scope();
- } else {
- //by convention the name of the rules start with ROLENAME/servicename/direction
- //use the first part of the name to determine the scope, therefore setting the scope of a rule to
- //be local to that service
- int slashIndex = ruleName.indexOf('/');
- if (slashIndex > 0) {
- scope = ruleName.substring( 0, slashIndex );
- }
- //check config to see if the is an override configuration for a given service to have all its rules set to global
- GatewayConfig gatewayConfig = environment.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
- if (gatewayConfig != null) {
- List<String> globalRulesServices = gatewayConfig.getGlobalRulesServices();
- if ( globalRulesServices.contains(scope) ) {
- scope = ScopedMatcher.GLOBAL_SCOPE;
- }
- }
- }
- }
-
- public String getRuleName() {
- return ruleName;
- }
-
- public String getScope() {
- return scope;
- }
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleProcessorImpl.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleProcessorImpl.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleProcessorImpl.java
deleted file mode 100644
index a07a9f0..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleProcessorImpl.java
+++ /dev/null
@@ -1,58 +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.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptorExt;
-import org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteMatchProcessorExt;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteStepProcessor;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteStepStatus;
-
-public class UrlRewriteRuleProcessorImpl implements UrlRewriteStepProcessor<UrlRewriteRuleDescriptor> {
-
- private UrlRewriteMatchProcessorExt matchProcessor;
-
- @Override
- public String getType() {
- return "rule";
- }
-
- @Override
- public void initialize( UrlRewriteEnvironment environment, UrlRewriteRuleDescriptor descriptor ) throws Exception {
- UrlRewriteMatchDescriptor matchDescriptor = new UrlRewriteMatchDescriptorExt();
- matchDescriptor.operation( "matches" );
- matchDescriptor.flow( descriptor.flow() );
- matchDescriptor.template( descriptor.template() );
- matchProcessor = new UrlRewriteMatchProcessorExt();
- matchProcessor.initialize( environment, matchDescriptor );
- }
-
- @Override
- public UrlRewriteStepStatus process( UrlRewriteContext context ) throws Exception {
- return matchProcessor.process( context );
- }
-
- @Override
- public void destroy() {
- matchProcessor.destroy();
- }
-
-}