camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject svn commit: r736562 - in /camel/trunk/components/camel-restlet: ./ src/main/java/org/apache/camel/component/restlet/ src/test/java/org/apache/camel/component/restlet/
Date Thu, 22 Jan 2009 04:58:43 GMT
Author: wtam
Date: Wed Jan 21 20:58:43 2009
New Revision: 736562

URL: http://svn.apache.org/viewvc?rev=736562&view=rev
Log:
[CAMEL-1284] Restlet binding does not properly insert/extract Restlet message.

Added:
    camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostContentTest.java
  (with props)
    camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderTest.java
  (contents, props changed)
      - copied, changed from r736198, camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRouteBuilderTest.java
Removed:
    camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRouteBuilderTest.java
Modified:
    camel/trunk/components/camel-restlet/pom.xml
    camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
    camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderAuthTest.java

Modified: camel/trunk/components/camel-restlet/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/pom.xml?rev=736562&r1=736561&r2=736562&view=diff
==============================================================================
--- camel/trunk/components/camel-restlet/pom.xml (original)
+++ camel/trunk/components/camel-restlet/pom.xml Wed Jan 21 20:58:43 2009
@@ -75,6 +75,13 @@
     </dependency>
 
     <dependency>
+      <groupId>commons-httpclient</groupId>
+      <artifactId>commons-httpclient</artifactId>
+      <version>3.1</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
       <scope>test</scope>

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=736562&r1=736561&r2=736562&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
Wed Jan 21 20:58:43 2009
@@ -42,7 +42,6 @@
  */
 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;
 
     /**
@@ -68,13 +67,13 @@
 
             }
         }
-
-        // extract our header and body
+        
         Form form = new Form(request.getEntity());
         if (form != null) {
             for (Map.Entry<String, String> entry : form.getValuesMap().entrySet())
{
-                if (CAMEL_REQUEST.equals(entry.getKey())) {
-                    exchange.getIn().setBody(entry.getValue());
+                // extract body added to the form as the key which has null value
+                if (entry.getValue() == null) {
+                    exchange.getIn().setBody(entry.getKey());
                     if (LOG.isDebugEnabled()) {
                         LOG.debug("Populate exchange from Restlet request body: " + entry.getValue());
                     }
@@ -91,6 +90,7 @@
                 }
             }
         }
+        
     }   
 
     /**
@@ -104,7 +104,8 @@
         request.setReferrerRef("camel-restlet");
         String body = exchange.getIn().getBody(String.class);
         Form form = new Form();
-        form.add(CAMEL_REQUEST, body);
+        // add the body as the key in the form with null value
+        form.add(body, null);
         
         if (LOG.isDebugEnabled()) {
             LOG.debug("Populate Restlet request from exchange body: " + body);

Added: camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostContentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostContentTest.java?rev=736562&view=auto
==============================================================================
--- camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostContentTest.java
(added)
+++ camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostContentTest.java
Wed Jan 21 20:58:43 2009
@@ -0,0 +1,67 @@
+/**
+ * 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.EntityEnclosingMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+
+/**
+ *
+ * @version $Revision$
+ */
+public class RestletPostContentTest extends ContextTestSupport {
+
+    private static final String MSG_BODY = "Hello World!";
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("restlet:http://localhost:8080/users/{username}?restletMethod=POST")
+                    .process(new SetUserProcessor());
+                
+            }
+            
+        };
+    }
+    
+    class SetUserProcessor implements Processor {
+        public void process(Exchange exchange) throws Exception {   
+            assertEquals(MSG_BODY, exchange.getIn().getBody(String.class));
+        }
+        
+    }
+    
+    public void testPostBody() throws Exception {
+        HttpMethod method = new PostMethod("http://localhost:8080/users/homer");
+        RequestEntity requestEntity = new StringRequestEntity(MSG_BODY, null, null);
+        ((EntityEnclosingMethod)method).setRequestEntity(requestEntity);
+        HttpClient client = new HttpClient();
+        assertEquals(200, client.executeMethod(method));
+
+    }
+}

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

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

Modified: camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderAuthTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderAuthTest.java?rev=736562&r1=736561&r2=736562&view=diff
==============================================================================
--- camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderAuthTest.java
(original)
+++ camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderAuthTest.java
Wed Jan 21 20:58:43 2009
@@ -53,6 +53,7 @@
         assertTrue(response.contains("requires user authentication"));
     }
 
+    @Override
     protected ClassPathXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext(
                 "org/apache/camel/component/restlet/camel-context.xml");

Copied: camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderTest.java
(from r736198, camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRouteBuilderTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderTest.java?p2=camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderTest.java&p1=camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRouteBuilderTest.java&r1=736198&r2=736562&rev=736562&view=diff
==============================================================================
--- camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRouteBuilderTest.java
(original)
+++ camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderTest.java
Wed Jan 21 20:58:43 2009
@@ -29,9 +29,10 @@
 import org.restlet.data.Response;
 import org.restlet.data.Status;
 
-public class RestRouteBuilderTest extends ContextTestSupport {
+public class RestletRouteBuilderTest extends ContextTestSupport {
     private static final String ID = "89531";
 
+    @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
@@ -45,7 +46,7 @@
                 from("restlet:http://localhost:8080/orders?restletMethod=post").process(new
Processor() {
                     public void process(Exchange exchange) throws Exception {
                         exchange.getOut().setBody(
-                                "received [" + exchange.getIn().getBody()
+                                "received [" + exchange.getIn().getBody(String.class)
                                 + "] as an order id = "
                                 + exchange.getIn().getHeader("id"));
                     }

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

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

Propchange: camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderTest.java
------------------------------------------------------------------------------
    svn:mergeinfo = 



Mime
View raw message