camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject svn commit: r730506 - in /activemq/camel/branches/camel-1.x: ./ apache-camel/ apache-camel/bundle/ components/camel-restlet/src/main/java/org/apache/camel/component/restlet/
Date Thu, 01 Jan 2009 03:47:05 GMT
Author: wtam
Date: Wed Dec 31 19:47:05 2008
New Revision: 730506

URL: http://svn.apache.org/viewvc?rev=730506&view=rev
Log:
Merged revisions 730504 via svnmerge from 
https://svn.apache.org/repos/asf/activemq/camel/trunk

........
  r730504 | wtam | 2008-12-31 21:35:50 -0500 (Wed, 31 Dec 2008) | 1 line
  
  [CAMEL-1203] Add HeaderFilterStrategy mechanism in Restlet component
........

Added:
    activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletHeaderFilterStrategy.java
      - copied unchanged from r730504, activemq/camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletHeaderFilterStrategy.java
Modified:
    activemq/camel/branches/camel-1.x/   (props changed)
    activemq/camel/branches/camel-1.x/apache-camel/bundle/pom.xml
    activemq/camel/branches/camel-1.x/apache-camel/pom.xml
    activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
    activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletBinding.java
    activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
    activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConsumer.java

Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Dec 31 19:47:05 2008
@@ -1 +1 @@
-/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524,719662,719848,719851,719855,719864,719978-719979,720207,720435-720437,720806,721272,721331,721333-721334,721360,721669,721764,721813,721985,722005,722070,722110,722415,722438,722726,722845,722878,723264,723314,723325-723327,723409,723835,723966,724122,724619,724681,725040,725309-725320,725340,725351,725569-725572,725612,725652-725660,725715,725883,726339,726640-726645,726932,727113,727375,727377,727624,727713,727946,729401,729892,730069,730154,730275,730299
+/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524,719662,719848,719851,719855,719864,719978-719979,720207,720435-720437,720806,721272,721331,721333-721334,721360,721669,721764,721813,721985,722005,722070,722110,722415,722438,722726,722845,722878,723264,723314,723325-723327,723409,723835,723966,724122,724619,724681,725040,725309-725320,725340,725351,725569-725572,725612,725652-725660,725715,725883,726339,726640-726645,726932,727113,727375,727377,727624,727713,727946,729401,729892,730069,730154,730275,730299,730504

Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: activemq/camel/branches/camel-1.x/apache-camel/bundle/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/apache-camel/bundle/pom.xml?rev=730506&r1=730505&r2=730506&view=diff
==============================================================================
--- activemq/camel/branches/camel-1.x/apache-camel/bundle/pom.xml (original)
+++ activemq/camel/branches/camel-1.x/apache-camel/bundle/pom.xml Wed Dec 31 19:47:05 2008
@@ -243,6 +243,10 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-xstream</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-restlet</artifactId>
+    </dependency>
         
   </dependencies>
 

Modified: activemq/camel/branches/camel-1.x/apache-camel/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/apache-camel/pom.xml?rev=730506&r1=730505&r2=730506&view=diff
==============================================================================
--- activemq/camel/branches/camel-1.x/apache-camel/pom.xml (original)
+++ activemq/camel/branches/camel-1.x/apache-camel/pom.xml Wed Dec 31 19:47:05 2008
@@ -253,6 +253,10 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-xstream</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-restlet</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>org.apache.camel</groupId>

Modified: activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java?rev=730506&r1=730505&r2=730506&view=diff
==============================================================================
--- activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
(original)
+++ activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
Wed Dec 31 19:47:05 2008
@@ -22,7 +22,10 @@
 import javax.xml.transform.dom.DOMSource;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.HeaderFilterStrategyAware;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.restlet.data.ChallengeResponse;
@@ -37,80 +40,79 @@
  *
  * @version $Revision$
  */
-public class DefaultRestletBinding implements RestletBinding {
+public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrategyAware {
     private static final Log LOG = LogFactory.getLog(DefaultRestletBinding.class);
+    private static final String CAMEL_REQUEST = "camel.request";
+    private HeaderFilterStrategy headerFilterStrategy;
 
     /**
-     * populateExchangeFromRestletRequest
+     * Populate Camel message from Restlet request
+     * 
+     * @param request message to be copied from
+     * @param exchange to be populated
+     * @throws Exception 
      */
     public void populateExchangeFromRestletRequest(Request request,
             Exchange exchange) throws Exception {
 
+        // extract headers from restlet 
         for (Map.Entry<String, Object> entry : request.getAttributes().entrySet())
{
-            if (!entry.getKey().startsWith("org.restlet.")) {
+            if (!headerFilterStrategy.applyFilterToExternalHeaders(entry.getKey(), 
+                    entry.getValue())) {
+                
                 exchange.getIn().setHeader(entry.getKey(), entry.getValue());
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Populate exchange from Restlet request header: " 
                             + entry.getKey() + " value: " + entry.getValue());
                 }
+
             }
         }
-        
-        Form headers = (Form) request.getAttributes().get("org.restlet.http.headers");
-        if (headers != null) {
-            for (Map.Entry<String, String> entry : headers.getValuesMap().entrySet())
{
-                if (!entry.getKey().startsWith("org.restlet.")
-                        && !entry.getKey().equals("Host")
-                        && !entry.getKey().equals("User-Agent")
-                        && !entry.getKey().equals("Content-Length")
-                        && !entry.getKey().equals("Content-Type")
-                        && !entry.getKey().equals("Connection")
-                        && !entry.getKey().equals("Accept")) {
-                    exchange.getIn().setHeader(entry.getKey(), entry.getValue());
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Populate exchange from Restlet request header: " 
-                                + entry.getKey() + " value: " + entry.getValue());
-                    }
-                }
-            }
-        }
+
+        // extract our header and body
         Form form = new Form(request.getEntity());
         if (form != null) {
-            for (Map.Entry<String, String> entry : form.getValuesMap()
-                    .entrySet()) {
-                exchange.getIn().setHeader(entry.getKey(), entry.getValue());
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Populate exchange from Restlet request header: " 
-                            + entry.getKey() + " value: " + entry.getValue());
+            for (Map.Entry<String, String> entry : form.getValuesMap().entrySet())
{
+                if (CAMEL_REQUEST.equals(entry.getKey())) {
+                    exchange.getIn().setBody(entry.getValue());
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Populate exchange from Restlet request body: " + entry.getValue());
+                    }
+                } else {
+                    if (!headerFilterStrategy.applyFilterToExternalHeaders(entry.getKey(),

+                            entry.getValue())) {
+
+                        exchange.getIn().setHeader(entry.getKey(), entry.getValue());
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug("Populate exchange from Restlet request user header:
" 
+                                    + entry.getKey() + " value: " + entry.getValue());
+                        }
+                    }
                 }
             }
         }
-        
-        Object body = form.getValuesMap().get("camel.body");
-        exchange.getIn().setBody(body);
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Populate exchange from Restlet request body: " + body);
-        }
-    }
+    }   
 
     /**
-     * populateRestletRequestFromExchange
+     * Populate Restlet Request from Camel message
+     * 
+     * @param request to be populated
+     * @param exchange message to be copied from
      */
     public void populateRestletRequestFromExchange(Request request,
             Exchange exchange) {
         request.setReferrerRef("camel-restlet");
         String body = exchange.getIn().getBody(String.class);
         Form form = new Form();
-        form.add("camel.body", body);
+        form.add(CAMEL_REQUEST, body);
         
         if (LOG.isDebugEnabled()) {
             LOG.debug("Populate Restlet request from exchange body: " + body);
         }
         
-        String login = (String) exchange.getIn().removeHeader(
-                RestletConstants.LOGIN);
-        String password = (String) exchange.getIn().removeHeader(
-                RestletConstants.PASSWORD);
+        // login and password are filtered by header filter strategy
+        String login = (String) exchange.getIn().getHeader(RestletConstants.LOGIN);
+        String password = (String) exchange.getIn().getHeader(RestletConstants.PASSWORD);
           
         if (login != null && password != null) {
             ChallengeResponse authentication = new ChallengeResponse(
@@ -122,25 +124,30 @@
         }
         
         for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet())
{
-            form.add(entry.getKey(), entry.getValue().toString());
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Populate Restlet request from exchange header: " 
-                        + entry.getKey() + " value: " + entry.getValue());
+            if (!headerFilterStrategy.applyFilterToCamelHeaders(entry.getKey(), 
+                    entry.getValue())) {
+                if (entry.getKey().startsWith("org.restlet.")) {
+                    // put the org.restlet headers in attributes
+                    request.getAttributes().put(entry.getKey(), entry.getValue());
+                } else {
+                    // put the user stuff in the form
+                    form.add(entry.getKey(), entry.getValue().toString());   
+                }
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Populate Restlet request from exchange header: " 
+                            + entry.getKey() + " value: " + entry.getValue());
+                }
             }
         }
         
-        for (Map.Entry<String, Object> entry : exchange.getProperties().entrySet())
{
-            form.add(entry.getKey(), entry.getValue().toString());
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Populate Restlet request from exchange header: " 
-                        + entry.getKey() + " value: " + entry.getValue());
-            }
-        }
         request.setEntity(form.getWebRepresentation());
     }
 
     /**
-     * populateRestletResponseFromExchange
+     * Populate Restlet request from Camel message
+     *  
+     * @param exchange message to be copied from 
+     * @param response to be populated
      */
     public void populateRestletResponseFromExchange(Exchange exchange,
             Response response) {
@@ -151,20 +158,46 @@
         } else if (body instanceof StringSource || body instanceof DOMSource) {
             mediaType = MediaType.TEXT_XML;
         }
+                
+        for (Map.Entry<String, Object> entry : exchange.getOut().getHeaders().entrySet())
{
+            if (!headerFilterStrategy.applyFilterToCamelHeaders(entry.getKey(), 
+                    entry.getValue())) {
+                response.getAttributes().put(entry.getKey(), entry.getValue());
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Populate Restlet response from exchange header: " 
+                            + entry.getKey() + " value: " + entry.getValue());
+                }
+            }
+        }
         
         String text = exchange.getOut().getBody(String.class);
         if (LOG.isDebugEnabled()) {
             LOG.debug("Populate Restlet response from exchange body: " + text);
         }
         response.setEntity(text, mediaType);
-        exchange.getIn().setBody(body);
     }
 
     /**
-     * populateExchangeFromRestletResponse
+     * Populate Camel message from Restlet response
+     * 
+     * @param exchange to be populated
+     * @param response message to be copied from
+     * @throws IOException 
      */
     public void populateExchangeFromRestletResponse(Exchange exchange,
             Response response) throws IOException {
+        
+        for (Map.Entry<String, Object> entry : response.getAttributes().entrySet())
{
+            if (!headerFilterStrategy.applyFilterToExternalHeaders(entry.getKey(), 
+                    entry.getValue())) {
+                exchange.getOut().setHeader(entry.getKey(), entry.getValue());
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Populate exchange from Restlet response header: " 
+                            + entry.getKey() + " value: " + entry.getValue());
+                }
+            }
+        }
+
         String text = response.getEntity().getText();
         if (LOG.isDebugEnabled()) {
             LOG.debug("Populate exchange from Restlet response: " + text);
@@ -173,7 +206,16 @@
         if (exchange.getPattern().isOutCapable()) {
             exchange.getOut().setBody(text);
         } else {
-            LOG.warn("Exchange is incapable of receiving response");
+            throw new RuntimeCamelException("Exchange is incapable of receiving response:
" 
+                    + exchange);
         }
     }
+
+    public HeaderFilterStrategy getHeaderFilterStrategy() {
+        return headerFilterStrategy;
+    }
+
+    public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
+        headerFilterStrategy = strategy;
+    }
 }

Modified: activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletBinding.java?rev=730506&r1=730505&r2=730506&view=diff
==============================================================================
--- activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletBinding.java
(original)
+++ activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletBinding.java
Wed Dec 31 19:47:05 2008
@@ -32,8 +32,8 @@
     /**
      * Populate Restlet request from Camel message
      *  
-     * @param exchange
-     * @param response
+     * @param exchange message to be copied from 
+     * @param response to be populated
      */
     void populateRestletResponseFromExchange(Exchange exchange,
             Response response);
@@ -41,25 +41,26 @@
     /**
      * Populate Camel message from Restlet request
      * 
-     * @param request
-     * @param exchange
+     * @param request message to be copied from
+     * @param exchange to be populated
      * @throws Exception 
      */
-    void populateExchangeFromRestletRequest(Request request, Exchange exchange) throws Exception;
+    void populateExchangeFromRestletRequest(Request request, 
+            Exchange exchange) throws Exception;
 
     /**
      * Populate Restlet Request from Camel message
      * 
-     * @param request
-     * @param exchange
+     * @param request to be populated
+     * @param exchange message to be copied from
      */
     void populateRestletRequestFromExchange(Request request, Exchange exchange);
 
     /**
      * Populate Camel message from Restlet response
      * 
-     * @param exchange
-     * @param response
+     * @param exchange to be populated
+     * @param response message to be copied from
      * @throws IOException 
      */
     void populateExchangeFromRestletResponse(Exchange exchange,

Modified: activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java?rev=730506&r1=730505&r2=730506&view=diff
==============================================================================
--- activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
(original)
+++ activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
Wed Dec 31 19:47:05 2008
@@ -20,7 +20,10 @@
 import java.util.Map;
 
 import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.HeaderFilterStrategyAware;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.util.CamelContextHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -37,13 +40,13 @@
  *
  * @version $Revision$
  */
-public class RestletComponent extends DefaultComponent {
+public class RestletComponent extends DefaultComponent<Exchange> implements HeaderFilterStrategyAware
{
     private static final Log LOG = LogFactory.getLog(RestletComponent.class);
 
     private Map<String, Server> servers = new HashMap<String, Server>();
     private Map<String, MethodBasedRouter> routers = new HashMap<String, MethodBasedRouter>();
-    
     private Component component = new Component();
+    private HeaderFilterStrategy headerFilterStrategy = new RestletHeaderFilterStrategy();
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining,
@@ -55,22 +58,20 @@
         if (ref != null) {
             restletBinding = CamelContextHelper.mandatoryLookup(getCamelContext(), 
                     ref, RestletBinding.class);
-            if (restletBinding == null) {
-                LOG.warn("Binding '" + ref + "' cannot be found in the context");
-            }
         }
         
         if (restletBinding == null) {
             restletBinding = new DefaultRestletBinding();
         }
         
+        if (restletBinding instanceof HeaderFilterStrategyAware) {
+            ((HeaderFilterStrategyAware)restletBinding).setHeaderFilterStrategy(headerFilterStrategy);
+        }
+        
         Map<String, String> realm = null;
         ref = getAndRemoveParameter(parameters, "restletRealmRef", String.class);
         if (ref != null) {
             realm = CamelContextHelper.mandatoryLookup(getCamelContext(), ref, Map.class);
-            if (realm == null) {
-                LOG.warn("Realm '" + ref + "' cannot be found in the context");
-            }
         }
         
         Method method = getAndRemoveParameter(parameters, "restletMethod", Method.class);
@@ -89,21 +90,13 @@
     
     @Override
     protected void doStart() throws Exception {
-        try {
-            super.doStart();
-        } catch (Exception e) {
-            LOG.warn("Failed to stop", e);
-        }
+        super.doStart();
         component.start();
     }
     
     @Override
     protected void doStop() throws Exception {
-        try {
-            component.stop();
-        } catch (Exception e) {
-            LOG.warn("Failed to stop", e);
-        }
+        component.stop();
         super.doStop();
     }
     
@@ -149,6 +142,14 @@
                 + endpoint.getRestletMethod());
     }    
     
+    public HeaderFilterStrategy getHeaderFilterStrategy() {
+        return headerFilterStrategy;
+    }
+
+    public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
+        this.headerFilterStrategy = strategy;
+    }
+    
     private MethodBasedRouter getMethodRouter(String uriPattern) {
         synchronized (routers) {
             MethodBasedRouter result = routers.get(uriPattern);

Modified: activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConsumer.java?rev=730506&r1=730505&r2=730506&view=diff
==============================================================================
--- activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConsumer.java
(original)
+++ activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConsumer.java
Wed Dec 31 19:47:05 2008
@@ -19,8 +19,8 @@
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.impl.DefaultConsumer;
-import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.restlet.Restlet;
@@ -54,8 +54,7 @@
                     getProcessor().process(exchange);
                     binding.populateRestletResponseFromExchange(exchange, response);
                 } catch (Exception e) {
-                    LOG.error(e);
-                    throw ObjectHelper.wrapRuntimeCamelException(e);
+                    throw new RuntimeCamelException(e);
                 }
             }
         };
@@ -68,9 +67,9 @@
     }
 
     @Override
-    public void stop() throws Exception {
+    public void doStop() throws Exception {
         ((RestletEndpoint)getEndpoint()).disconnect(this);
-        super.stop();
+        super.doStop();
     }
 
     public Restlet getRestlet() {



Mime
View raw message