You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/10/16 13:45:47 UTC

[1/2] camel git commit: CAMEL-11282 : RestletComponent changed to extend DefaultComponent and implement HeaderFilterStrategyAware. Testcase added to verify that HeaderFiltering

Repository: camel
Updated Branches:
  refs/heads/master 4e3e06e99 -> c0f063c76


CAMEL-11282 : RestletComponent changed to extend DefaultComponent and implement HeaderFilterStrategyAware. Testcase added to verify that HeaderFiltering


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/420f06e6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/420f06e6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/420f06e6

Branch: refs/heads/master
Commit: 420f06e6fc0c70d26b19e183e96d696c4114ffc6
Parents: 4e3e06e
Author: Dennis Bohnstedt Hansen <mi...@gmail.com>
Authored: Mon Oct 16 14:00:42 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Oct 16 15:42:23 2017 +0200

----------------------------------------------------------------------
 .../src/main/docs/restlet-component.adoc        |  2 +-
 .../component/restlet/RestletComponent.java     | 32 +++++++-
 .../RestletHeaderFilterStrategyTest.java        | 80 ++++++++++++++++++++
 3 files changed, 109 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/420f06e6/components/camel-restlet/src/main/docs/restlet-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/docs/restlet-component.adoc b/components/camel-restlet/src/main/docs/restlet-component.adoc
index 1cb071b..b22f9ff 100644
--- a/components/camel-restlet/src/main/docs/restlet-component.adoc
+++ b/components/camel-restlet/src/main/docs/restlet-component.adoc
@@ -71,6 +71,7 @@ The Restlet component supports 22 options which are listed below.
 | Name | Description | Default | Type
 | *controllerDaemon* (consumer) | Indicates if the controller thread should be a daemon (not blocking JVM exit). |  | Boolean
 | *controllerSleepTimeMs* (consumer) | Time for the controller thread to sleep between each control. |  | Integer
+| *headerFilterStrategy* (filter) | Custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. |  | HeaderFilterStrategy
 | *inboundBufferSize* (consumer) | The size of the buffer when reading messages. |  | Integer
 | *maxConnectionsPerHost* (common) | Maximum number of concurrent connections per host (IP address). |  | Integer
 | *maxThreads* (consumer) | Maximum threads that will service requests. |  | Integer
@@ -89,7 +90,6 @@ The Restlet component supports 22 options which are listed below.
 | *synchronous* (producer) | Whether to use synchronous Restlet Client for the producer. Setting this option to true can yield faster performance as it seems the Restlet synchronous Client works better. |  | Boolean
 | *enabledConverters* (advanced) | A list of converters to enable as full class name or simple class name. All the converters automatically registered are enabled if empty or null |  | List
 | *useGlobalSslContext Parameters* (security) | Enable usage of global SSL context parameters. | false | boolean
-| *headerFilterStrategy* (filter) | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. |  | HeaderFilterStrategy
 | *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
 |===
 // component options: END

http://git-wip-us.apache.org/repos/asf/camel/blob/420f06e6/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
index c01a1ea..1671dfa 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
@@ -37,7 +37,9 @@ import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.SSLContextParametersAware;
 import org.apache.camel.component.restlet.converter.RestletConverter;
-import org.apache.camel.impl.HeaderFilterStrategyComponent;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.spi.HeaderFilterStrategyAware;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.RestApiConsumerFactory;
 import org.apache.camel.spi.RestConfiguration;
@@ -68,7 +70,7 @@ import org.slf4j.LoggerFactory;
  *
  * @version
  */
-public class RestletComponent extends HeaderFilterStrategyComponent implements RestConsumerFactory, RestApiConsumerFactory, RestProducerFactory, SSLContextParametersAware {
+public class RestletComponent extends DefaultComponent implements RestConsumerFactory, RestApiConsumerFactory, RestProducerFactory, SSLContextParametersAware, HeaderFilterStrategyAware {
     private static final Logger LOG = LoggerFactory.getLogger(RestletComponent.class);
     private static final Object LOCK = new Object();
 
@@ -117,6 +119,11 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R
     private List<String> enabledConverters;
     @Metadata(label = "security", defaultValue = "false")
     private boolean useGlobalSslContextParameters;
+    @Metadata(
+            label = "filter",
+            description = "To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message."
+    )
+    private HeaderFilterStrategy headerFilterStrategy;
 
     public RestletComponent() {
         this(new Component());
@@ -125,7 +132,7 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R
     public RestletComponent(Component component) {
         // Allow the Component to be injected, so that the RestletServlet may be
         // configured within a webapp
-        super(RestletEndpoint.class);
+        super();
         this.component = component;
     }
 
@@ -535,7 +542,7 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R
     public Integer getControllerSleepTimeMs() {
         return controllerSleepTimeMs;
     }
-
+    
     /**
      * Time for the controller thread to sleep between each control.
      */
@@ -543,6 +550,17 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R
         this.controllerSleepTimeMs = controllerSleepTimeMs;
     }
 
+    public HeaderFilterStrategy getHeaderFilterStrategy() {
+        return this.headerFilterStrategy;
+    }
+
+    /**
+     * Custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message.
+     */
+    public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
+        this.headerFilterStrategy = strategy;
+    }
+
     public Integer getInboundBufferSize() {
         return inboundBufferSize;
     }
@@ -930,4 +948,10 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R
             }
         }
     }
+
+    public void setEndpointHeaderFilterStrategy(Endpoint endpoint) {
+        if (this.headerFilterStrategy != null && endpoint instanceof HeaderFilterStrategyAware) {
+            ((HeaderFilterStrategyAware)endpoint).setHeaderFilterStrategy(this.headerFilterStrategy);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/420f06e6/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletHeaderFilterStrategyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletHeaderFilterStrategyTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletHeaderFilterStrategyTest.java
new file mode 100644
index 0000000..d2e0649
--- /dev/null
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletHeaderFilterStrategyTest.java
@@ -0,0 +1,80 @@
+/**
+ * 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.camel.component.restlet;
+
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultHeaderFilterStrategy;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class RestletHeaderFilterStrategyTest extends RestletTestSupport {
+
+    private static final String HEADER_FILTER = "filter";
+
+    @Test
+    public void testRestletProducerInFilterAllowedHeader() throws Exception {
+        String acceptedHeaderKey = "dontFilter";
+        MockEndpoint mock = getMockEndpoint("mock:out");
+        mock.expectedHeaderReceived(acceptedHeaderKey, "any value");
+        String out = template.requestBodyAndHeader("direct:start", null, acceptedHeaderKey, "any value", String.class);
+        mock.assertIsSatisfied();
+    }
+
+    @Test
+    public void testRestletProducerInFilterNotAllowedHeader() throws Exception {
+        String notAcceptedHeaderKey = HEADER_FILTER + "ThisHeader";
+        MockEndpoint mock = getMockEndpoint("mock:out");
+        mock.whenAnyExchangeReceived(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                String notValidHeader = exchange.getIn().getHeader(notAcceptedHeaderKey, String.class);
+                Map<String, Object> headers = exchange.getIn().getHeaders();
+                for (String key : headers.keySet()) {
+                    assertFalse("Header should have been filtered: " + key, key.startsWith(HEADER_FILTER));
+                }
+            }
+        });
+        template.requestBodyAndHeader("direct:start", null, notAcceptedHeaderKey, "any value", String.class);
+        mock.assertIsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // force synchronous processing using restlet and add filtering
+                DefaultHeaderFilterStrategy strategy = new DefaultHeaderFilterStrategy();
+                strategy.setInFilterPattern(HEADER_FILTER + ".*");
+                strategy.setOutFilterPattern(HEADER_FILTER + ".*");
+
+                RestletComponent restlet = context.getComponent("restlet", RestletComponent.class);
+                restlet.setHeaderFilterStrategy(strategy);
+                restlet.setSynchronous(true);
+
+                from("direct:start").to("restlet:http://localhost:" + portNum + "/users/123/exclude").to("log:reply");
+                from("restlet:http://localhost:" + portNum + "/users/{id}/{filterExcluded}?restletMethods=GET").to("mock:out");
+            }
+        };
+    }
+}


[2/2] camel git commit: CAMEL-11282: Polished. This closes #2042.

Posted by da...@apache.org.
CAMEL-11282: Polished. This closes #2042.


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

Branch: refs/heads/master
Commit: c0f063c763783b67668b366a1ac501df03eb9de3
Parents: 420f06e
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Oct 16 15:45:39 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Oct 16 15:45:39 2017 +0200

----------------------------------------------------------------------
 .../src/main/docs/restlet-component.adoc        |  2 +-
 .../component/restlet/RestletComponent.java     |  7 ++---
 .../RestletComponentConfiguration.java          | 30 ++++++++++----------
 3 files changed, 18 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c0f063c7/components/camel-restlet/src/main/docs/restlet-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/docs/restlet-component.adoc b/components/camel-restlet/src/main/docs/restlet-component.adoc
index b22f9ff..fe3e45f 100644
--- a/components/camel-restlet/src/main/docs/restlet-component.adoc
+++ b/components/camel-restlet/src/main/docs/restlet-component.adoc
@@ -71,7 +71,7 @@ The Restlet component supports 22 options which are listed below.
 | Name | Description | Default | Type
 | *controllerDaemon* (consumer) | Indicates if the controller thread should be a daemon (not blocking JVM exit). |  | Boolean
 | *controllerSleepTimeMs* (consumer) | Time for the controller thread to sleep between each control. |  | Integer
-| *headerFilterStrategy* (filter) | Custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. |  | HeaderFilterStrategy
+| *headerFilterStrategy* (filter) | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. |  | HeaderFilterStrategy
 | *inboundBufferSize* (consumer) | The size of the buffer when reading messages. |  | Integer
 | *maxConnectionsPerHost* (common) | Maximum number of concurrent connections per host (IP address). |  | Integer
 | *maxThreads* (consumer) | Maximum threads that will service requests. |  | Integer

http://git-wip-us.apache.org/repos/asf/camel/blob/c0f063c7/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
index 1671dfa..b308df2 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
@@ -119,10 +119,7 @@ public class RestletComponent extends DefaultComponent implements RestConsumerFa
     private List<String> enabledConverters;
     @Metadata(label = "security", defaultValue = "false")
     private boolean useGlobalSslContextParameters;
-    @Metadata(
-            label = "filter",
-            description = "To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message."
-    )
+    @Metadata(label = "filter", description = "To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message.")
     private HeaderFilterStrategy headerFilterStrategy;
 
     public RestletComponent() {
@@ -555,7 +552,7 @@ public class RestletComponent extends DefaultComponent implements RestConsumerFa
     }
 
     /**
-     * Custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message.
+     * To use a custom {@link org.apache.camel.spi.HeaderFilterStrategy} to filter header to and from Camel message.
      */
     public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
         this.headerFilterStrategy = strategy;

http://git-wip-us.apache.org/repos/asf/camel/blob/c0f063c7/platforms/spring-boot/components-starter/camel-restlet-starter/src/main/java/org/apache/camel/component/restlet/springboot/RestletComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-restlet-starter/src/main/java/org/apache/camel/component/restlet/springboot/RestletComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-restlet-starter/src/main/java/org/apache/camel/component/restlet/springboot/RestletComponentConfiguration.java
index c303d50..9d45988 100644
--- a/platforms/spring-boot/components-starter/camel-restlet-starter/src/main/java/org/apache/camel/component/restlet/springboot/RestletComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-restlet-starter/src/main/java/org/apache/camel/component/restlet/springboot/RestletComponentConfiguration.java
@@ -44,6 +44,12 @@ public class RestletComponentConfiguration
      */
     private Integer controllerSleepTimeMs;
     /**
+     * To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter
+     * header to and from Camel message.
+     */
+    @NestedConfigurationProperty
+    private HeaderFilterStrategy headerFilterStrategy;
+    /**
      * The size of the buffer when reading messages.
      */
     private Integer inboundBufferSize;
@@ -138,12 +144,6 @@ public class RestletComponentConfiguration
      */
     private Boolean useGlobalSslContextParameters = false;
     /**
-     * To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter
-     * header to and from Camel message.
-     */
-    @NestedConfigurationProperty
-    private HeaderFilterStrategy headerFilterStrategy;
-    /**
      * Whether the component should resolve property placeholders on itself when
      * starting. Only properties which are of String type can use property
      * placeholders.
@@ -166,6 +166,15 @@ public class RestletComponentConfiguration
         this.controllerSleepTimeMs = controllerSleepTimeMs;
     }
 
+    public HeaderFilterStrategy getHeaderFilterStrategy() {
+        return headerFilterStrategy;
+    }
+
+    public void setHeaderFilterStrategy(
+            HeaderFilterStrategy headerFilterStrategy) {
+        this.headerFilterStrategy = headerFilterStrategy;
+    }
+
     public Integer getInboundBufferSize() {
         return inboundBufferSize;
     }
@@ -311,15 +320,6 @@ public class RestletComponentConfiguration
         this.useGlobalSslContextParameters = useGlobalSslContextParameters;
     }
 
-    public HeaderFilterStrategy getHeaderFilterStrategy() {
-        return headerFilterStrategy;
-    }
-
-    public void setHeaderFilterStrategy(
-            HeaderFilterStrategy headerFilterStrategy) {
-        this.headerFilterStrategy = headerFilterStrategy;
-    }
-
     public Boolean getResolvePropertyPlaceholders() {
         return resolvePropertyPlaceholders;
     }