You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by wt...@apache.org on 2009/02/10 06:08:32 UTC

svn commit: r742854 - in /camel/trunk/components/camel-restlet/src: main/java/org/apache/camel/component/restlet/ test/java/org/apache/camel/component/restlet/

Author: wtam
Date: Tue Feb 10 05:08:31 2009
New Revision: 742854

URL: http://svn.apache.org/viewvc?rev=742854&view=rev
Log:
[CAMEL-1329] Restlet default binding to propagate query string to Camel message

Added:
    camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java   (with props)
Modified:
    camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
    camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConstants.java

Modified: camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java?rev=742854&r1=742853&r2=742854&view=diff
==============================================================================
--- camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java (original)
+++ camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java Tue Feb 10 05:08:31 2009
@@ -33,6 +33,7 @@
 import org.restlet.data.ChallengeScheme;
 import org.restlet.data.Form;
 import org.restlet.data.MediaType;
+import org.restlet.data.Parameter;
 import org.restlet.data.Request;
 import org.restlet.data.Response;
 import org.restlet.data.Status;
@@ -56,12 +57,13 @@
     public void populateExchangeFromRestletRequest(Request request,
             Exchange exchange) throws Exception {
 
+        Message inMessage = exchange.getIn();
         // extract headers from restlet 
         for (Map.Entry<String, Object> entry : request.getAttributes().entrySet()) {
             if (!headerFilterStrategy.applyFilterToExternalHeaders(entry.getKey(), 
                     entry.getValue())) {
                 
-                exchange.getIn().setHeader(entry.getKey(), entry.getValue());
+                inMessage.setHeader(entry.getKey(), entry.getValue());
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Populate exchange from Restlet request header: " 
                             + entry.getKey() + " value: " + entry.getValue());
@@ -70,6 +72,12 @@
             }
         }
         
+        // copy query string to header
+        String query = request.getResourceRef().getQuery();
+        if (null != query) {
+            inMessage.setHeader(RestletConstants.QUERY_STRING, query);
+        }
+
         if (!request.isEntityAvailable()) {
             return;
         }
@@ -79,7 +87,7 @@
             for (Map.Entry<String, String> entry : form.getValuesMap().entrySet()) {
                 // extract body added to the form as the key which has null value
                 if (entry.getValue() == null) {
-                    exchange.getIn().setBody(entry.getKey());
+                    inMessage.setBody(entry.getKey());
                     if (LOG.isDebugEnabled()) {
                         LOG.debug("Populate exchange from Restlet request body: " + entry.getValue());
                     }
@@ -87,7 +95,7 @@
                     if (!headerFilterStrategy.applyFilterToExternalHeaders(entry.getKey(), 
                             entry.getValue())) {
 
-                        exchange.getIn().setHeader(entry.getKey(), entry.getValue());
+                        inMessage.setHeader(entry.getKey(), entry.getValue());
                         if (LOG.isDebugEnabled()) {
                             LOG.debug("Populate exchange from Restlet request user header: " 
                                     + entry.getKey() + " value: " + entry.getValue());
@@ -95,8 +103,7 @@
                     }
                 }
             }
-        }
-        
+        }        
     }   
 
     /**

Modified: camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConstants.java?rev=742854&r1=742853&r2=742854&view=diff
==============================================================================
--- camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConstants.java (original)
+++ camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConstants.java Tue Feb 10 05:08:31 2009
@@ -27,6 +27,7 @@
     public static final String PASSWORD = "org.apache.camel.restlet.auth.password";
     public static final String MEDIA_TYPE = "org.apache.camel.restlet.mediaType";
     public static final String RESPONSE_CODE = "org.apache.camel.restlet.responseCode";
+    public static final String QUERY_STRING = "org.apache.camel.restlet.queryString";
 
     private RestletConstants() {
     }

Added: camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java?rev=742854&view=auto
==============================================================================
--- camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java (added)
+++ camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java Tue Feb 10 05:08:31 2009
@@ -0,0 +1,68 @@
+/**
+ * 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 org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+/**
+ *
+ * @version $Revision$
+ */
+public class RestletQueryTest extends ContextTestSupport {
+    private static final String QUERY_STRING = "foo=bar&test=123";
+
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("restlet:http://localhost:9080/users/{username}")
+                    .process(new SetUserProcessor());
+                
+            }
+            
+        };
+    }
+    
+    class SetUserProcessor implements Processor {
+
+        public void process(Exchange exchange) throws Exception {   
+            assertEquals(QUERY_STRING, 
+                    exchange.getProperty(RestletConstants.QUERY_STRING, String.class));
+        }
+        
+    }
+    
+    public void testPostBody() throws Exception {
+        HttpMethod method = new GetMethod("http://localhost:9080/users/homer?" + QUERY_STRING);
+        try {
+            HttpClient client = new HttpClient();
+            assertEquals(200, client.executeMethod(method));
+        } finally {
+            method.releaseConnection();
+        }
+
+    }
+}

Propchange: camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date