camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject camel git commit: CAMEL-9501 Support to setup the filter InitParameters from Jetty URI
Date Sun, 21 Feb 2016 11:09:46 GMT
Repository: camel
Updated Branches:
  refs/heads/master 48020041f -> 2ded240dd


CAMEL-9501 Support to setup the filter InitParameters from Jetty URI


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

Branch: refs/heads/master
Commit: 2ded240ddcb5fc92f6dd56e606e0906e63a21a4e
Parents: 4802004
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Sun Feb 21 18:56:31 2016 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Sun Feb 21 19:09:24 2016 +0800

----------------------------------------------------------------------
 .../org/apache/camel/util/IntrospectionSupport.java  | 15 +++++++++++++++
 .../camel/component/jetty/JettyHttpComponent.java    | 10 +++++++++-
 .../camel/component/jetty/JettyHttpEndpoint.java     | 15 +++++++++++++++
 .../camel/component/jetty/CustomFiltersTest.java     |  9 +++++++--
 4 files changed, 46 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2ded240d/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
index e4a98df..46fd82e 100755
--- a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
@@ -448,6 +448,21 @@ public final class IntrospectionSupport {
         return rc;
     }
 
+    public static Map<String, String> extractStringProperties(Map<String, Object>
properties) {
+        ObjectHelper.notNull(properties, "properties");
+
+        Map<String, String> rc = new LinkedHashMap<String, String>(properties.size());
+
+        for (Iterator<Map.Entry<String, Object>> it = properties.entrySet().iterator();
it.hasNext();) {
+            Map.Entry<String, Object> entry = it.next();
+            String name = entry.getKey();
+            String value = entry.getValue().toString();
+            rc.put(name, value);
+        }
+
+        return rc;
+    }
+
     public static boolean setProperties(CamelContext context, TypeConverter typeConverter,
Object target, Map<String, Object> properties) throws Exception {
         ObjectHelper.notNull(target, "target");
         ObjectHelper.notNull(properties, "properties");

http://git-wip-us.apache.org/repos/asf/camel/blob/2ded240d/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index ca6afc0..5e39a14 100644
--- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -185,6 +185,9 @@ public abstract class JettyHttpComponent extends HttpCommonComponent implements
         // extract httpClient. parameters
         Map<String, Object> httpClientParameters = IntrospectionSupport.extractProperties(parameters,
"httpClient.");
 
+        // extract filterInit. parameters
+        Map<String, String> filterInitParameters =  IntrospectionSupport.extractStringProperties(IntrospectionSupport.extractProperties(parameters,
"filterInit."));
+
         String address = remaining;
         URI addressUri = new URI(UnsafeUriCharactersEncoder.encodeHttpURI(address));
         URI endpointUri = URISupport.createRemainingURI(addressUri, parameters);
@@ -217,10 +220,12 @@ public abstract class JettyHttpComponent extends HttpCommonComponent
implements
         }
         // setup the proxy host and proxy port
         
-
         if (httpClientParameters != null && !httpClientParameters.isEmpty()) {
             endpoint.setHttpClientParameters(httpClientParameters);
         }
+        if (filterInitParameters != null && !filterInitParameters.isEmpty()) {
+            endpoint.setFilterInitParameters(filterInitParameters);
+        }
         if (handlerList.size() > 0) {
             endpoint.setHandlers(handlerList);
         }
@@ -369,6 +374,9 @@ public abstract class JettyHttpComponent extends HttpCommonComponent implements
         List<Filter> filters = endpoint.getFilters();
         for (Filter filter : filters) {
             FilterHolder filterHolder = new FilterHolder();
+            if (endpoint.getFilterInitParameters() != null) {
+                filterHolder.setInitParameters(endpoint.getFilterInitParameters());
+            }
             filterHolder.setFilter(new CamelFilterWrapper(filter));
             String pathSpec = endpoint.getPath();
             if (pathSpec == null || "".equals(pathSpec)) {

http://git-wip-us.apache.org/repos/asf/camel/blob/2ded240d/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
index 81bf601..c5f11e5 100644
--- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
+++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
@@ -95,6 +95,10 @@ public abstract class JettyHttpEndpoint extends HttpCommonEndpoint {
             description = "Allows using a custom filters which is putted into a list and
can be find in the Registry."
             + " Multiple values can be separated by comma.")
     private List<Filter> filters;
+    @UriParam(label = "consumer, advanced", prefix = "filter.", multiValue = true,
+            description = "Configuration of the filter init parameters. These parameters
will be applied to the filter list before starting the jetty server.")
+    private Map<String, String> filterInitParameters;
+
     @UriParam(label = "producer,advanced",
         description = "To use a custom JettyHttpBinding which be used to customize how a
response should be written for the producer.")
     private JettyHttpBinding jettyBinding;
@@ -407,6 +411,17 @@ public abstract class JettyHttpEndpoint extends HttpCommonEndpoint {
         this.httpClientParameters = httpClientParameters;
     }
 
+    public Map<String, String> getFilterInitParameters() {
+        return filterInitParameters;
+    }
+
+    /**
+     *  Configuration of the filter init parameters. These parameters will be applied to
the filter list before starting the jetty server.
+     */
+    public void setFilterInitParameters(Map<String, String> filterInitParameters) {
+        this.filterInitParameters = filterInitParameters;
+    }
+
     public boolean isEnableCORS() {
         return enableCORS;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/2ded240d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/CustomFiltersTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/CustomFiltersTest.java
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/CustomFiltersTest.java
index c60eaa9..c8478b3 100644
--- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/CustomFiltersTest.java
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/CustomFiltersTest.java
@@ -40,16 +40,18 @@ import org.junit.Test;
 public class CustomFiltersTest extends BaseJettyTest {
 
     private static class MyTestFilter implements Filter {
+        private String keyWord;
         @Override
         public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException, ServletException {            
             // set a marker attribute to show that this filter class was used
             ((HttpServletResponse)response).addHeader("MyTestFilter", "true");
+            ((HttpServletResponse)response).setHeader("KeyWord", keyWord);
             chain.doFilter(request , response);
         }
 
         @Override
         public void init(FilterConfig filterConfig) throws ServletException {
-            // do nothing here
+            keyWord = filterConfig.getInitParameter("keyWord");
         }
 
         @Override
@@ -73,6 +75,9 @@ public class CustomFiltersTest extends BaseJettyTest {
         String result = httppost.getResponseBodyAsString();
         assertEquals("Get a wrong result", "This is a test response", result);
         assertNotNull("Did not use custom multipart filter", httppost.getResponseHeader("MyTestFilter"));
+
+        // just make sure the KeyWord header is set
+        assertEquals("Did not set the right KeyWord header", "KEY", httppost.getResponseHeader("KeyWord").getValue());
     }
     
     @Test
@@ -94,7 +99,7 @@ public class CustomFiltersTest extends BaseJettyTest {
             public void configure() throws Exception {
                                 
                 // Test the filter list options
-                from("jetty://http://localhost:{{port}}/testFilters?filtersRef=myFilters").process(new
Processor() {
+                from("jetty://http://localhost:{{port}}/testFilters?filtersRef=myFilters&filterInit.keyWord=KEY").process(new
Processor() {
                     public void process(Exchange exchange) throws Exception {
                         Message in = exchange.getIn();
                         String request = in.getBody(String.class);


Mime
View raw message