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:24 UTC
[26/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/xml/XmlUrlRewriteStreamFilter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteStreamFilter.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteStreamFilter.java
deleted file mode 100644
index d1c693e..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteStreamFilter.java
+++ /dev/null
@@ -1,67 +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.xml;
-
-import org.apache.commons.io.input.ReaderInputStream;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteStreamFilter;
-import org.apache.hadoop.gateway.util.urltemplate.Resolver;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.stream.XMLStreamException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-public class XmlUrlRewriteStreamFilter implements UrlRewriteStreamFilter {
-
- private static String[] TYPES = new String[]{ "application/xml", "text/xml", "*/xml" };
- private static String[] NAMES = new String[]{ null };
-
- @Override
- public String[] getTypes() {
- return TYPES;
- }
-
- @Override
- public String[] getNames() {
- return NAMES;
- }
-
- @Override
- public InputStream filter(
- InputStream stream,
- String encoding,
- UrlRewriter rewriter,
- Resolver resolver,
- UrlRewriter.Direction direction,
- UrlRewriteFilterContentDescriptor config )
- throws IOException {
- try {
- return new ReaderInputStream(
- new XmlUrlRewriteFilterReader(
- new InputStreamReader( stream, encoding ), rewriter, resolver, direction, config ), encoding );
- } catch( ParserConfigurationException e ) {
- throw new IOException( e );
- } catch( XMLStreamException e ) {
- throw new IOException( e );
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteActionDescriptorBase.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteActionDescriptorBase.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteActionDescriptorBase.java
deleted file mode 100644
index 27085df..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteActionDescriptorBase.java
+++ /dev/null
@@ -1,83 +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.spi;
-
-import org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteActionDescriptor;
-
-public abstract class UrlRewriteActionDescriptorBase
- extends UrlRewriteStepDescriptorBase<UrlRewriteActionDescriptor>
- implements UrlRewriteActionDescriptor {
-
- private String operation;
- private String parameter;
-
- protected UrlRewriteActionDescriptorBase( String type ) {
- super( type );
- }
-
- @Override
- public String operation() {
- return operation;
- }
-
- @Override
- public UrlRewriteActionDescriptor operation( String operation ) {
- this.operation = operation;
- return this;
- }
-
- public void setOperation( String operation ) {
- operation( operation );
- }
-
- public void setOper( String operation ) {
- operation( operation );
- }
-
- public void setOp( String operation ) {
- operation( operation );
- }
-
- public String getOper() {
- return operation();
- }
-
- @Override
- public String parameter() {
- return parameter;
- }
-
- @Override
- public UrlRewriteActionDescriptor parameter( String parameter ) {
- this.parameter = parameter;
- return this;
- }
-
- public void setParameter( String parameter ) {
- parameter( parameter );
- }
-
- public void setParam( String parameter ) {
- parameter( parameter );
- }
-
- public String getParam() {
- return parameter();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteContext.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteContext.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteContext.java
deleted file mode 100644
index 092a6b0..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteContext.java
+++ /dev/null
@@ -1,45 +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.spi;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import org.apache.hadoop.gateway.util.urltemplate.Evaluator;
-import org.apache.hadoop.gateway.util.urltemplate.Params;
-import org.apache.hadoop.gateway.util.urltemplate.Template;
-
-public interface UrlRewriteContext {
-
- UrlRewriter.Direction getDirection();
-
- Template getOriginalUrl();
-
- Template getCurrentUrl();
-
- void setCurrentUrl( Template url );
-
- /**
- * Adds parameters to the rewrite context and replaces some of them if they already exist
- * @param parameters the parameters to be added or replaced
- */
- void addParameters( Params parameters );
-
- Params getParameters();
-
- Evaluator getEvaluator();
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFlowDescriptorBase.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFlowDescriptorBase.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFlowDescriptorBase.java
deleted file mode 100644
index 97f8c33..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFlowDescriptorBase.java
+++ /dev/null
@@ -1,114 +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.spi;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFlowDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStepDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStepDescriptorFactory;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStepFlow;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public abstract class UrlRewriteFlowDescriptorBase<T> extends UrlRewriteStepDescriptorBase<T> implements UrlRewriteFlowDescriptor<T> {
-
- private UrlRewriteStepFlow flow;
- private List<UrlRewriteStepDescriptor> steps = new ArrayList<UrlRewriteStepDescriptor>();
-
- public UrlRewriteFlowDescriptorBase( String type ) {
- super( type );
- }
-
- @Override
- public UrlRewriteStepFlow flow() {
- return flow;
- }
-
- @SuppressWarnings( "unchecked" )
- @Override
- public <F extends UrlRewriteFlowDescriptor<?>> F flow( String flow ) {
- setFlow( flow );
- return (F)this;
- }
-
- @SuppressWarnings( "unchecked" )
- @Override
- public <F extends UrlRewriteFlowDescriptor<?>> F flow( UrlRewriteStepFlow flow ) {
- setFlow( flow );
- return (F)this;
- }
-
- public void setFlow( UrlRewriteStepFlow flow ) {
- this.flow = flow;
- }
-
- public void setFlow( String flow ) {
- flow = flow.trim().toUpperCase();
- this.flow = Enum.valueOf( UrlRewriteStepFlow.class, flow );
- }
-
- public String getFlow() {
- String str = null;
- if( flow != null ) {
- str = flow.toString();
- }
- return str;
- }
-
- @Override
- public List<UrlRewriteStepDescriptor> steps() {
- return steps;
- }
-
-// @Override
-// public UrlRewriteMatchDescriptor addMatch() {
-// UrlRewriteMatchDescriptor step = new UrlRewriteMatchDescriptorExt();
-// steps.add( step );
-// return step;
-// }
-//
-// @Override
-// public UrlRewriteCheckDescriptor addCheck() {
-// UrlRewriteCheckDescriptor step = new UrlRewriteCheckDescriptorExt();
-// steps.add( step );
-// return step;
-// }
-//
-// @Override
-// public UrlRewriteControlDescriptor addControl() {
-// UrlRewriteControlDescriptor step = new UrlRewriteControlDescriptorExt();
-// steps.add( step );
-// return step;
-// }
-//
-// @Override
-// public UrlRewriteActionDescriptor addAction() {
-// UrlRewriteActionDescriptor step = new UrlRewriteActionDescriptorBase();
-// steps.add( step );
-// return step;
-// }
-
- @SuppressWarnings( "unchecked" )
- @Override
- public <T extends UrlRewriteStepDescriptor<?>> T addStep( String type ) {
- T step = (T)UrlRewriteStepDescriptorFactory.create( type );
- steps.add( step );
- return (T)step;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFunctionProcessor.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFunctionProcessor.java
deleted file mode 100644
index cf5a331..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFunctionProcessor.java
+++ /dev/null
@@ -1,31 +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.spi;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor;
-
-public interface UrlRewriteFunctionProcessor<T extends UrlRewriteFunctionDescriptor> extends UrlRewriteResolver {
-
- String name();
-
- void initialize( UrlRewriteEnvironment environment, T descriptor ) throws Exception;
-
- void destroy() throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFunctionProcessorBase.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFunctionProcessorBase.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFunctionProcessorBase.java
deleted file mode 100644
index 987e889..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteFunctionProcessorBase.java
+++ /dev/null
@@ -1,31 +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.spi;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor;
-
-public abstract class UrlRewriteFunctionProcessorBase<T extends UrlRewriteFunctionDescriptor> implements UrlRewriteFunctionProcessor<T> {
-
- public void initialize( UrlRewriteEnvironment environment, T descriptor ) throws Exception {
- }
-
- public void destroy() throws Exception {
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteResolver.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteResolver.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteResolver.java
deleted file mode 100644
index ec07b5b..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteResolver.java
+++ /dev/null
@@ -1,26 +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.spi;
-
-import java.util.List;
-
-public interface UrlRewriteResolver {
-
- List<String> resolve( UrlRewriteContext context, List<String> parameter ) throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteRulesExporter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteRulesExporter.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteRulesExporter.java
deleted file mode 100644
index b393ce7..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteRulesExporter.java
+++ /dev/null
@@ -1,31 +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.spi;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
-
-import java.io.IOException;
-import java.io.Writer;
-
-public interface UrlRewriteRulesExporter {
-
- String getFormat();
-
- void store( UrlRewriteRulesDescriptor rules, Writer writer ) throws IOException;
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteRulesImporter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteRulesImporter.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteRulesImporter.java
deleted file mode 100644
index d342f15..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteRulesImporter.java
+++ /dev/null
@@ -1,31 +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.spi;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
-
-import java.io.IOException;
-import java.io.Reader;
-
-public interface UrlRewriteRulesImporter {
-
- String getFormat();
-
- UrlRewriteRulesDescriptor load( Reader reader ) throws IOException;
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepDescriptorBase.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepDescriptorBase.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepDescriptorBase.java
deleted file mode 100644
index 4d520fe..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepDescriptorBase.java
+++ /dev/null
@@ -1,46 +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.spi;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStepDescriptor;
-
-public abstract class UrlRewriteStepDescriptorBase<T> implements UrlRewriteStepDescriptor<T> {
-
- private String type;
-
- public UrlRewriteStepDescriptorBase( String type ) {
- this.type = type;
- }
-
- @Override
- public String type() {
- return type;
- }
-
- @Override
- @SuppressWarnings( "unchecked" )
- public T type( String type ) {
- this.type = type;
- return (T)this;
- }
-
- public void setType( String type ) {
- this.type = type;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepProcessor.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepProcessor.java
deleted file mode 100644
index 806ec1f..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepProcessor.java
+++ /dev/null
@@ -1,33 +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.spi;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStepDescriptor;
-
-public interface UrlRewriteStepProcessor<T extends UrlRewriteStepDescriptor> {
-
- String getType();
-
- void initialize( UrlRewriteEnvironment environment, T descriptor ) throws Exception;
-
- UrlRewriteStepStatus process( UrlRewriteContext context ) throws Exception;
-
- void destroy() throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepStatus.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepStatus.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepStatus.java
deleted file mode 100644
index 619652f..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStepStatus.java
+++ /dev/null
@@ -1,20 +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.spi;
-
-public enum UrlRewriteStepStatus { SUCCESS, FAILURE, FINISHED }
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStreamFilter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStreamFilter.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStreamFilter.java
deleted file mode 100644
index 413b94b..0000000
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/spi/UrlRewriteStreamFilter.java
+++ /dev/null
@@ -1,45 +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.spi;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import org.apache.hadoop.gateway.util.urltemplate.Resolver;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import static org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter.Direction;
-
-// The rewriter will try to find either a stream or reader createFilter for the mime/type and name.
-public interface UrlRewriteStreamFilter {
-
- String[] getTypes();
-
- String[] getNames();
-
- InputStream filter(
- InputStream stream,
- String encoding,
- UrlRewriter rewriter,
- Resolver resolver,
- Direction direction,
- UrlRewriteFilterContentDescriptor config )
- throws IOException;
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/CookieScopeServletFilter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/CookieScopeServletFilter.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/CookieScopeServletFilter.java
new file mode 100644
index 0000000..93f2dc8
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/CookieScopeServletFilter.java
@@ -0,0 +1,47 @@
+/**
+ * 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.rewrite.api;
+
+import java.io.IOException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.knox.gateway.filter.AbstractGatewayFilter;
+import org.apache.knox.gateway.filter.rewrite.impl.CookieScopeResponseWrapper;
+
+public class CookieScopeServletFilter extends AbstractGatewayFilter {
+
+ private String gatewayPath;
+
+ @Override
+ public void init( FilterConfig filterConfig ) throws ServletException {
+ super.init( filterConfig );
+ gatewayPath = filterConfig.getInitParameter("gateway.path");
+ }
+
+ @Override
+ protected void doFilter( HttpServletRequest request, HttpServletResponse response, FilterChain chain )
+ throws IOException, ServletException {
+ chain.doFilter( request, new CookieScopeResponseWrapper(response, gatewayPath));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/FrontendFunctionDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/FrontendFunctionDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/FrontendFunctionDescriptor.java
new file mode 100644
index 0000000..c3b63cd
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/FrontendFunctionDescriptor.java
@@ -0,0 +1,31 @@
+/**
+ * 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.rewrite.api;
+
+public class FrontendFunctionDescriptor implements UrlRewriteFunctionDescriptor<FrontendFunctionDescriptor> {
+
+ public static final String FUNCTION_NAME = "frontend";
+
+ public static final String FRONTEND_URI_ATTRIBUTE = "org.apache.knox.gateway.frontend.uri";
+
+ @Override
+ public String name() {
+ return FUNCTION_NAME;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteEnvironment.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteEnvironment.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteEnvironment.java
new file mode 100644
index 0000000..754d752
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteEnvironment.java
@@ -0,0 +1,31 @@
+/**
+ * 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.rewrite.api;
+
+import org.apache.knox.gateway.util.urltemplate.Resolver;
+
+import java.io.IOException;
+import java.net.URL;
+
+public interface UrlRewriteEnvironment extends Resolver {
+
+ URL getResource( String name ) throws IOException;
+
+ <T> T getAttribute( String name );
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterApplyDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterApplyDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterApplyDescriptor.java
new file mode 100644
index 0000000..4722322
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterApplyDescriptor.java
@@ -0,0 +1,27 @@
+/**
+ * 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.rewrite.api;
+
+public interface UrlRewriteFilterApplyDescriptor
+ extends UrlRewriteFilterPathDescriptor<UrlRewriteFilterApplyDescriptor> {
+
+ String rule();
+
+ UrlRewriteFilterApplyDescriptor rule( String rule );
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterBufferDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterBufferDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterBufferDescriptor.java
new file mode 100644
index 0000000..f67cd83
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterBufferDescriptor.java
@@ -0,0 +1,25 @@
+/**
+ * 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.rewrite.api;
+
+public interface UrlRewriteFilterBufferDescriptor
+ extends UrlRewriteFilterPathDescriptor, UrlRewriteFilterGroupDescriptor {
+
+ public UrlRewriteFilterDetectDescriptor addDetect( String path, String value );
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterContentDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterContentDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterContentDescriptor.java
new file mode 100644
index 0000000..84b22eb
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterContentDescriptor.java
@@ -0,0 +1,32 @@
+/**
+ * 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.rewrite.api;
+
+public interface UrlRewriteFilterContentDescriptor extends UrlRewriteFilterGroupDescriptor {
+
+ String type();
+
+ String asType();
+
+ UrlRewriteFilterContentDescriptor type( String type );
+
+ UrlRewriteFilterContentDescriptor asType( String type );
+
+ UrlRewriteFilterBufferDescriptor addBuffer( String path );
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterDescriptor.java
new file mode 100644
index 0000000..3d9db56
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterDescriptor.java
@@ -0,0 +1,37 @@
+/**
+ * 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.rewrite.api;
+
+import javax.activation.MimeType;
+import java.util.List;
+
+public interface UrlRewriteFilterDescriptor {
+
+ String name();
+
+ UrlRewriteFilterDescriptor name( String name );
+
+ List<UrlRewriteFilterContentDescriptor> getContents();
+
+ UrlRewriteFilterContentDescriptor getContent( String type );
+
+ UrlRewriteFilterContentDescriptor getContent( MimeType type );
+
+ UrlRewriteFilterContentDescriptor addContent( String type );
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterDetectDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterDetectDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterDetectDescriptor.java
new file mode 100644
index 0000000..e2dec91
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterDetectDescriptor.java
@@ -0,0 +1,33 @@
+/**
+ * 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.rewrite.api;
+
+public interface UrlRewriteFilterDetectDescriptor
+ extends UrlRewriteFilterPathDescriptor, UrlRewriteFilterGroupDescriptor {
+
+ String value();
+
+ UrlRewriteFilterDetectDescriptor value( String value );
+
+ <C> C compiledValue();
+
+ UrlRewriteFilterDetectDescriptor compiledValue( String compiledValue );
+
+ <C> C compiledValue( Compiler<C> compiler );
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterGroupDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterGroupDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterGroupDescriptor.java
new file mode 100644
index 0000000..49064e7
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterGroupDescriptor.java
@@ -0,0 +1,30 @@
+/**
+ * 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.rewrite.api;
+
+import java.util.List;
+
+public interface UrlRewriteFilterGroupDescriptor extends UrlRewriteFilterPathDescriptor {
+
+ public List<UrlRewriteFilterPathDescriptor> getSelectors();
+
+ public void addSelector( UrlRewriteFilterPathDescriptor selector );
+
+ UrlRewriteFilterApplyDescriptor addApply( String path, String rule );
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterPathDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterPathDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterPathDescriptor.java
new file mode 100644
index 0000000..d94e288
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterPathDescriptor.java
@@ -0,0 +1,39 @@
+/**
+ * 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.rewrite.api;
+
+public interface UrlRewriteFilterPathDescriptor<T> {
+
+ String path();
+
+ T path( String path );
+
+ <C> C compiledPath();
+
+ T compiledPath( Object compilePath );
+
+ <C> C compiledPath( Compiler<C> compiler );
+
+ interface Compiler<C> {
+ // The returned compiled version of the expression must be thread safe.
+ // The compiled param will be the result of the last successful call to this method for this instance of
+ // the descriptor node.
+ C compile( String expression, C compiled );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterScopeDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterScopeDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterScopeDescriptor.java
new file mode 100644
index 0000000..5058dbf
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFilterScopeDescriptor.java
@@ -0,0 +1,22 @@
+/**
+ * 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.rewrite.api;
+
+public interface UrlRewriteFilterScopeDescriptor
+ extends UrlRewriteFilterPathDescriptor, UrlRewriteFilterGroupDescriptor {
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFlowDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFlowDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFlowDescriptor.java
new file mode 100644
index 0000000..7d48916
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFlowDescriptor.java
@@ -0,0 +1,42 @@
+/**
+ * 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.rewrite.api;
+
+import java.util.List;
+
+public interface UrlRewriteFlowDescriptor<T> extends UrlRewriteStepDescriptor<T> {
+
+ UrlRewriteStepFlow flow();
+
+ <F extends UrlRewriteFlowDescriptor<?>> F flow( String flow );
+
+ <F extends UrlRewriteFlowDescriptor<?>> F flow( UrlRewriteStepFlow flow );
+
+ List<UrlRewriteStepDescriptor> steps();
+
+// UrlRewriteMatchDescriptor addMatch();
+//
+// UrlRewriteCheckDescriptor addCheck();
+//
+// UrlRewriteActionDescriptor addAction();
+//
+// UrlRewriteControlDescriptor addControl();
+
+ <T extends UrlRewriteStepDescriptor<?>> T addStep( String type );
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFunctionDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFunctionDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFunctionDescriptor.java
new file mode 100644
index 0000000..4d7591a
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFunctionDescriptor.java
@@ -0,0 +1,24 @@
+/**
+ * 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.rewrite.api;
+
+public interface UrlRewriteFunctionDescriptor<T> {
+
+ String name();
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFunctionDescriptorFactory.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFunctionDescriptorFactory.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFunctionDescriptorFactory.java
new file mode 100644
index 0000000..c9f33f5
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteFunctionDescriptorFactory.java
@@ -0,0 +1,61 @@
+/**
+ * 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.rewrite.api;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.Set;
+
+public abstract class UrlRewriteFunctionDescriptorFactory {
+
+ private static Map<String,Class<? extends UrlRewriteFunctionDescriptor>> MAP
+ = (Map<String, Class<? extends UrlRewriteFunctionDescriptor>>)loadDescriptors();
+
+ private UrlRewriteFunctionDescriptorFactory() {
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends UrlRewriteFunctionDescriptor<?>> T create( String name ) {
+ try {
+ Class<? extends UrlRewriteFunctionDescriptor> descriptorClass = MAP.get( name );
+ return (T)descriptorClass.newInstance();
+ } catch( InstantiationException e ) {
+ throw new IllegalArgumentException( name );
+ } catch( IllegalAccessException e ) {
+ throw new IllegalArgumentException( name );
+ }
+ }
+
+ private static Map<String,Class<? extends UrlRewriteFunctionDescriptor>> loadDescriptors() {
+ Map<String,Class<? extends UrlRewriteFunctionDescriptor>> map
+ = new HashMap<>();
+ ServiceLoader<? extends UrlRewriteFunctionDescriptor> descriptors
+ = ServiceLoader.load( UrlRewriteFunctionDescriptor.class );
+ for( UrlRewriteFunctionDescriptor descriptor : descriptors ) {
+ String functionName = descriptor.name();
+ Class<? extends UrlRewriteFunctionDescriptor> descriptorClass = descriptor.getClass() ;
+ map.put( functionName, descriptorClass );
+ }
+ return map;
+ }
+
+ public static Set<String> getNames() {
+ return MAP.keySet();
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteProcessor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteProcessor.java
new file mode 100644
index 0000000..381af18
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteProcessor.java
@@ -0,0 +1,179 @@
+/**
+ * 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.rewrite.api;
+
+import org.apache.knox.gateway.filter.rewrite.ext.ScopedMatcher;
+import org.apache.knox.gateway.filter.rewrite.i18n.UrlRewriteMessages;
+import org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteContextImpl;
+import org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFunctionProcessorFactory;
+import org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRuleProcessorHolder;
+import org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteStepProcessorHolder;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepStatus;
+import org.apache.knox.gateway.i18n.messages.MessagesFactory;
+import org.apache.knox.gateway.util.urltemplate.Matcher;
+import org.apache.knox.gateway.util.urltemplate.Resolver;
+import org.apache.knox.gateway.util.urltemplate.Template;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class UrlRewriteProcessor implements UrlRewriter {
+
+ private static final UrlRewriteMessages LOG = MessagesFactory.get( UrlRewriteMessages.class );
+
+ UrlRewriteEnvironment environment;
+ UrlRewriteRulesDescriptor descriptor;
+ Map<String,UrlRewriteRuleProcessorHolder> rules = new HashMap<>();
+ ScopedMatcher inbound = new ScopedMatcher();
+ ScopedMatcher outbound = new ScopedMatcher();
+ Map<String,UrlRewriteFunctionProcessor> functions = new HashMap<>();
+
+ public UrlRewriteProcessor() {
+ }
+
+ // Convert the descriptor into processors.
+ public void initialize( UrlRewriteEnvironment environment, UrlRewriteRulesDescriptor descriptor ) {
+ this.environment = environment;
+ this.descriptor = descriptor;
+ initializeFunctions( descriptor );
+ initializeRules( descriptor );
+ }
+
+ public UrlRewriteRulesDescriptor getConfig() {
+ return descriptor;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void initializeFunctions( UrlRewriteRulesDescriptor rules ) {
+ for( String name : UrlRewriteFunctionDescriptorFactory.getNames() ) {
+ try {
+ UrlRewriteFunctionDescriptor descriptor = rules.getFunction( name );
+ UrlRewriteFunctionProcessor processor = UrlRewriteFunctionProcessorFactory.create( name, descriptor );
+ processor.initialize( environment, descriptor );
+ functions.put( name, processor );
+ } catch( Exception e ) {
+ // Ignore it and it won't be available as a function.
+ LOG.failedToInitializeRewriteFunctions( e );
+ }
+ }
+ }
+
+ private void initializeRules( UrlRewriteRulesDescriptor descriptor ) {
+ for( UrlRewriteRuleDescriptor ruleDescriptor : descriptor.getRules() ) {
+ try {
+ UrlRewriteRuleProcessorHolder ruleProcessor = new UrlRewriteRuleProcessorHolder();
+ ruleProcessor.initialize( environment, ruleDescriptor );
+ if( !rules.containsKey( ruleDescriptor.name() ) ) {
+ rules.put( ruleDescriptor.name(), ruleProcessor );
+ }
+ Template template = ruleDescriptor.template();
+ if( template != null ) {
+ EnumSet<Direction> directions = ruleDescriptor.directions();
+ if( directions == null || directions.isEmpty() ) {
+ inbound.add( template, ruleProcessor );
+ outbound.add( template, ruleProcessor );
+ } else if( directions.contains( Direction.IN ) ) {
+ inbound.add( template, ruleProcessor );
+ } else if ( directions.contains( Direction.OUT ) ) {
+ outbound.add( template, ruleProcessor );
+ }
+ }
+ } catch( Exception e ) {
+ LOG.failedToInitializeRewriteRules( e );
+ }
+ }
+ }
+
+ public void destroy() {
+ for( UrlRewriteStepProcessorHolder rule : rules.values() ) {
+ try {
+ rule.destroy();
+ } catch ( Exception e ) {
+ LOG.failedToDestroyRewriteStepProcessor( e );
+ }
+ }
+ for( UrlRewriteFunctionProcessor function : functions.values() ) {
+ try {
+ function.destroy();
+ } catch( Exception e ) {
+ LOG.failedToDestroyRewriteFunctionProcessor( e );
+ }
+ }
+ }
+
+ @Override
+ public Template rewrite( Resolver resolver, Template inputUri, Direction direction, String ruleName ) {
+ Template outputUri = inputUri;
+ String serviceRole = null;
+ if (resolver != null) {
+ List<String> serviceRoles = resolver.resolve("service.role");
+ if ( serviceRoles != null && !serviceRoles.isEmpty() ) {
+ serviceRole = serviceRoles.get(0);
+ }
+ }
+ UrlRewriteStepProcessorHolder stepHolder = null;
+ String effectiveRuleName = null;
+ if( ruleName == null || "*".equals( ruleName ) ) {
+ ruleName = null; // Used for logging later.
+ Matcher<UrlRewriteRuleProcessorHolder>.Match match = null;
+ switch( direction ) {
+ case IN:
+ match = inbound.match( outputUri, serviceRole );
+ break;
+ case OUT:
+ match = outbound.match( outputUri, serviceRole );
+ break;
+ }
+ if( match != null ) {
+ stepHolder = match.getValue();
+ effectiveRuleName = match.getValue().getRuleName();
+ }
+ } else if( !ruleName.isEmpty() ) {
+ stepHolder = rules.get( ruleName );
+ effectiveRuleName = ruleName;
+ }
+ if( stepHolder != null ) {
+ UrlRewriteContext context = new UrlRewriteContextImpl( environment, resolver, functions, direction, inputUri );
+ try {
+ UrlRewriteStepStatus stepStatus = stepHolder.process( context );
+ if( UrlRewriteStepStatus.SUCCESS == stepStatus ) {
+ outputUri = context.getCurrentUrl();
+ if( ruleName == null ) {
+ LOG.rewroteUrlViaImplicitRule( inputUri, direction, effectiveRuleName, outputUri );
+ } else {
+ LOG.rewroteUrlViaExplicitRule( inputUri, direction, effectiveRuleName, outputUri );
+ }
+ } else {
+ LOG.failedToRewriteUrl( inputUri, direction, effectiveRuleName, stepStatus );
+ outputUri = null;
+ }
+ } catch( Exception e ) {
+ LOG.failedToRewriteUrlDueToException( inputUri, direction, effectiveRuleName, e );
+ outputUri = null;
+ }
+ } else {
+ LOG.noRuleMatchingUrl( inputUri, direction );
+ }
+ return outputUri;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRuleDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRuleDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRuleDescriptor.java
new file mode 100644
index 0000000..b65670a
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRuleDescriptor.java
@@ -0,0 +1,52 @@
+/**
+ * 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.rewrite.api;
+
+import org.apache.knox.gateway.util.urltemplate.Template;
+
+import java.net.URISyntaxException;
+import java.util.EnumSet;
+
+/**
+ * <rule name="..." pattern="..." dir="request" flow="and"><match></match></rule>
+ */
+public interface UrlRewriteRuleDescriptor extends UrlRewriteFlowDescriptor<UrlRewriteRuleDescriptor> {
+
+ String name();
+
+ UrlRewriteStepDescriptor name( String name );
+
+ String scope();
+
+ UrlRewriteStepDescriptor scope( String scope );
+
+ EnumSet<UrlRewriter.Direction> directions();
+
+ UrlRewriteRuleDescriptor directions( String directions );
+
+ UrlRewriteRuleDescriptor directions( UrlRewriter.Direction... directions );
+
+ String pattern();
+
+ UrlRewriteRuleDescriptor pattern( String pattern ) throws URISyntaxException;
+
+ Template template();
+
+ UrlRewriteRuleDescriptor template( Template pattern );
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptor.java
new file mode 100644
index 0000000..f046921
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptor.java
@@ -0,0 +1,57 @@
+/**
+ * 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.rewrite.api;
+
+import java.util.List;
+
+/**
+ * <rules><rule></rule></rules>
+ */
+public interface UrlRewriteRulesDescriptor {
+
+ void addRules( UrlRewriteRulesDescriptor rules );
+
+ List<UrlRewriteFunctionDescriptor> getFunctions();
+
+ <T extends UrlRewriteFunctionDescriptor<?>> T getFunction( String name );
+
+ <T extends UrlRewriteFunctionDescriptor<?>> T addFunction( String name );
+
+
+ List<UrlRewriteRuleDescriptor> getRules();
+
+ UrlRewriteRuleDescriptor getRule( String name );
+
+ UrlRewriteRuleDescriptor newRule();
+
+ UrlRewriteRuleDescriptor addRule( String name );
+
+ void addRule( UrlRewriteRuleDescriptor rule );
+
+
+ List<UrlRewriteFilterDescriptor> getFilters();
+
+ UrlRewriteFilterDescriptor getFilter( String name );
+
+ UrlRewriteFilterDescriptor newFilter();
+
+ UrlRewriteFilterDescriptor addFilter( String name );
+
+ void addFilter( UrlRewriteFilterDescriptor filter );
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactory.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactory.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactory.java
new file mode 100644
index 0000000..c529809
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactory.java
@@ -0,0 +1,76 @@
+/**
+ * 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.rewrite.api;
+
+import org.apache.knox.gateway.filter.rewrite.i18n.UrlRewriteResources;
+import org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRulesDescriptorImpl;
+import org.apache.knox.gateway.filter.rewrite.impl.xml.XmlUrlRewriteRulesExporter;
+import org.apache.knox.gateway.filter.rewrite.impl.xml.XmlUrlRewriteRulesImporter;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteRulesExporter;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteRulesImporter;
+import org.apache.knox.gateway.i18n.resources.ResourcesFactory;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public abstract class UrlRewriteRulesDescriptorFactory {
+
+ private static UrlRewriteResources RES = ResourcesFactory.get( UrlRewriteResources.class );
+
+ private static Map<String, UrlRewriteRulesImporter> IMPORTERS = loadImporters();
+ private static Map<String, UrlRewriteRulesExporter> EXPORTERS = loadExporters();
+
+ private UrlRewriteRulesDescriptorFactory() {
+ }
+
+ public static UrlRewriteRulesDescriptor create() {
+ return new UrlRewriteRulesDescriptorImpl();
+ }
+
+ public static UrlRewriteRulesDescriptor load( String format, Reader reader ) throws IOException {
+ UrlRewriteRulesImporter importer = IMPORTERS.get( format );
+ if( importer == null ) {
+ throw new IllegalArgumentException( RES.noImporterForFormat( format ) );
+ }
+ return importer.load( reader );
+ }
+
+ public static void store( UrlRewriteRulesDescriptor descriptor, String format, Writer writer ) throws IOException {
+ UrlRewriteRulesExporter exporter = EXPORTERS.get( format );
+ if( exporter == null ) {
+ throw new IllegalArgumentException( RES.noExporterForFormat( format ) );
+ }
+ exporter.store( descriptor, writer );
+ }
+
+ private static Map<String, UrlRewriteRulesImporter> loadImporters() {
+ Map<String, UrlRewriteRulesImporter> map = new ConcurrentHashMap<String, UrlRewriteRulesImporter>();
+ map.put( "xml", new XmlUrlRewriteRulesImporter() );
+ return map;
+ }
+
+ private static Map<String, UrlRewriteRulesExporter> loadExporters() {
+ Map<String, UrlRewriteRulesExporter> map = new ConcurrentHashMap<String, UrlRewriteRulesExporter>();
+ map.put( "xml", new XmlUrlRewriteRulesExporter() );
+ return map;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletContextListener.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletContextListener.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletContextListener.java
new file mode 100644
index 0000000..cce33b2
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletContextListener.java
@@ -0,0 +1,106 @@
+/**
+ * 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.rewrite.api;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.knox.gateway.filter.rewrite.i18n.UrlRewriteMessages;
+import org.apache.knox.gateway.i18n.messages.MessagesFactory;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+public class UrlRewriteServletContextListener implements ServletContextListener {
+
+ public static final String PROCESSOR_ATTRIBUTE_NAME = UrlRewriteProcessor.class.getName();
+ public static final String DESCRIPTOR_LOCATION_INIT_PARAM_NAME = "rewriteDescriptorLocation";
+ public static final String DESCRIPTOR_DEFAULT_FILE_NAME = "rewrite.xml";
+ public static final String DESCRIPTOR_DEFAULT_LOCATION = "/WEB-INF/" + DESCRIPTOR_DEFAULT_FILE_NAME;
+ private static final UrlRewriteMessages LOG = MessagesFactory.get( UrlRewriteMessages.class );
+
+ @Override
+ public void contextInitialized( ServletContextEvent event ) {
+ UrlRewriteRulesDescriptor descriptor = null;
+ try {
+ URL url = locateDescriptor( event.getServletContext() );
+ descriptor = loadDescriptor( url );
+ } catch( IOException e ) {
+ throw new IllegalStateException( e );
+ }
+ ServletContext context = event.getServletContext();
+ UrlRewriteEnvironment environment = new UrlRewriteServletEnvironment( context );
+ UrlRewriteProcessor processor = new UrlRewriteProcessor();
+ processor.initialize( environment, descriptor );
+ event.getServletContext().setAttribute( PROCESSOR_ATTRIBUTE_NAME, processor );
+ }
+
+ @Override
+ public void contextDestroyed( ServletContextEvent event ) {
+ UrlRewriteProcessor processor =
+ (UrlRewriteProcessor)event.getServletContext().getAttribute( PROCESSOR_ATTRIBUTE_NAME );
+ event.getServletContext().removeAttribute( PROCESSOR_ATTRIBUTE_NAME );
+ if( processor != null ) {
+ processor.destroy();
+ }
+ }
+
+ public static UrlRewriter getUrlRewriter( ServletContext context ) {
+ return ((UrlRewriteProcessor)context.getAttribute( PROCESSOR_ATTRIBUTE_NAME ));
+ }
+
+ private static URL locateDescriptor( ServletContext context ) throws IOException {
+ String param = context.getInitParameter( DESCRIPTOR_LOCATION_INIT_PARAM_NAME );
+ if( param == null ) {
+ param = DESCRIPTOR_DEFAULT_LOCATION;
+ }
+ URL url;
+ try {
+ url = context.getResource( param );
+ } catch( MalformedURLException e ) {
+ // Ignore it and try using the value directly as a URL.
+ url = null;
+ }
+ if( url == null ) {
+ url = new URL( param );
+ }
+ if( url == null ) {
+ throw new FileNotFoundException( param );
+ }
+ return url;
+ }
+
+ private static UrlRewriteRulesDescriptor loadDescriptor( URL url ) throws IOException {
+ InputStream stream = url.openStream();
+ Reader reader = new InputStreamReader( stream, "UTF-8" );
+ UrlRewriteRulesDescriptor descriptor = UrlRewriteRulesDescriptorFactory.load( "xml", reader );
+ try {
+ reader.close();
+ } catch( IOException closeException ) {
+ LOG.failedToLoadRewriteRulesDescriptor( closeException );
+ }
+ return descriptor;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletEnvironment.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletEnvironment.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletEnvironment.java
new file mode 100644
index 0000000..074098c
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletEnvironment.java
@@ -0,0 +1,56 @@
+/**
+ * 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.rewrite.api;
+
+import javax.servlet.ServletContext;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+
+public class UrlRewriteServletEnvironment implements UrlRewriteEnvironment {
+
+ private ServletContext context;
+
+ public UrlRewriteServletEnvironment( ServletContext context ) {
+ this.context = context;
+ }
+
+ @Override
+ public URL getResource( String name ) throws MalformedURLException {
+ URL url = context.getResource( name );
+ return url;
+ }
+
+ @Override
+ public <T> T getAttribute( String name ) {
+ T attribute = (T)context.getAttribute( name );
+ return attribute;
+ }
+
+ @Override
+ public List<String> resolve( String name ) {
+ List<String> values = null;
+ String value = context.getInitParameter( name );
+ if( value != null ) {
+ values = Arrays.asList( value );
+ }
+ return values;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletFilter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletFilter.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletFilter.java
new file mode 100644
index 0000000..dc49dbc
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteServletFilter.java
@@ -0,0 +1,63 @@
+/**
+ * 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.rewrite.api;
+
+import org.apache.knox.gateway.filter.AbstractGatewayFilter;
+import org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRequest;
+import org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteResponse;
+import org.apache.knox.gateway.util.MimeTypes;
+
+import javax.activation.MimeType;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ *
+ */
+public class UrlRewriteServletFilter extends AbstractGatewayFilter {
+
+ public static final String REQUEST_URL_RULE_PARAM = "request.url";
+ public static final String REQUEST_HEADERS_FILTER_PARAM = "request.headers";
+ public static final String REQUEST_COOKIES_FILTER_PARAM = "request.cookies";
+ public static final String REQUEST_BODY_FILTER_PARAM = "request.body";
+ public static final String RESPONSE_HEADERS_FILTER_PARAM = "response.headers";
+ public static final String RESPONSE_COOKIES_FILTER_PARAM = "response.cookies";
+ public static final String RESPONSE_BODY_FILTER_PARAM = "response.body";
+
+ public static final MimeType HEADERS_MIME_TYPE = MimeTypes.create( "application/x-http-headers", null );
+ public static final MimeType COOKIES_MIME_TYPE = MimeTypes.create( "application/x-http-cookies", null );
+
+ @Override
+ public void init( FilterConfig filterConfig ) throws ServletException {
+ super.init( filterConfig );
+ }
+
+ @Override
+ protected void doFilter( HttpServletRequest request, HttpServletResponse response, FilterChain chain )
+ throws IOException, ServletException {
+ FilterConfig config = getConfig();
+ UrlRewriteRequest rewriteRequest = new UrlRewriteRequest( config, request );
+ UrlRewriteResponse rewriteResponse = new UrlRewriteResponse( config, rewriteRequest, response );
+ chain.doFilter( rewriteRequest, rewriteResponse );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteStepDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteStepDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteStepDescriptor.java
new file mode 100644
index 0000000..906a3c5
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteStepDescriptor.java
@@ -0,0 +1,26 @@
+/**
+ * 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.rewrite.api;
+
+public interface UrlRewriteStepDescriptor<T> {
+
+ String type();
+
+ T type( String type );
+
+}