Author: ningjiang
Date: Fri Aug 24 09:10:40 2012
New Revision: 1376870

URL: http://svn.apache.org/viewvc?rev=1376870&view=rev
Log:
CAMEL-5535 update endpoint uri to support multiple restlet routes of the same 
restlet URI but different VERBs

Added:
    
camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletMultiRoutesEndpointTest.java
Modified:
    
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
    
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java

Modified: 
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java?rev=1376870&r1=1376869&r2=1376870&view=diff
==============================================================================
--- 
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
 (original)
+++ 
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
 Fri Aug 24 09:10:40 2012
@@ -82,6 +82,8 @@ public class RestletComponent extends He
         RestletEndpoint result = new RestletEndpoint(this, remaining);
         setEndpointHeaderFilterStrategy(result);
         setProperties(result, parameters);
+        // set the endpoint uri according to the parameter
+        result.updateEndpointUri();
 
         // construct URI so we can use it to get the splitted information
         URI u = new URI(remaining);

Modified: 
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java?rev=1376870&r1=1376869&r2=1376870&view=diff
==============================================================================
--- 
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java
 (original)
+++ 
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java
 Fri Aug 24 09:10:40 2012
@@ -185,6 +185,24 @@ public class RestletEndpoint extends Def
     public void setThrowExceptionOnFailure(boolean throwExceptionOnFailure) {
         this.throwExceptionOnFailure = throwExceptionOnFailure;
     }
+    
+    // Update the endpointUri with the restlet method information
+    protected void updateEndpointUri() {
+        String endpointUri = getEndpointUri();
+        StringBuffer methods = new StringBuffer();
+        if (getRestletMethods() != null && getRestletMethods().length > 0) {
+            for (Method method : getRestletMethods()) {
+                methods = methods.append(method.getName()).append(',');
+            }
+        } else {
+            Method method = getRestletMethod();
+            methods = methods.append(method.getName());
+        }
+        if (methods != null) {
+            endpointUri = endpointUri + "?restletMethods=" + 
methods.toString();
+            setEndpointUri(endpointUri);
+        }
+    }
 
     @Override
     protected void doStart() throws Exception {

Added: 
camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletMultiRoutesEndpointTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletMultiRoutesEndpointTest.java?rev=1376870&view=auto
==============================================================================
--- 
camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletMultiRoutesEndpointTest.java
 (added)
+++ 
camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletMultiRoutesEndpointTest.java
 Fri Aug 24 09:10:40 2012
@@ -0,0 +1,77 @@
+/**
+ * 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.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.junit.Test;
+
+/**
+ * This unit test verifies a single route can service multiple methods.
+ * 
+ * @version 
+ */
+public class RestletMultiRoutesEndpointTest extends RestletTestSupport {
+
+    @Test
+    public void testPostMethod() throws Exception {
+        HttpResponse response = doExecute(new HttpPost("http://localhost:"; + 
portNum + "/users/homer"));
+
+        assertHttpResponse(response, 200, "text/plain", "POST");
+    }
+
+    @Test
+    public void testPutMethod() throws Exception {
+        HttpResponse response = doExecute(new HttpPut("http://localhost:"; + 
portNum + "/users/homer"));
+
+        assertHttpResponse(response, 200, "text/plain", "result PUT");
+    }
+
+    @Test
+    public void testGetMethod() throws Exception {
+        HttpResponse response = doExecute(new HttpGet("http://localhost:"; + 
portNum + "/users/homer"));
+
+        assertHttpResponse(response, 200, "text/plain", "GET");
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("restlet:http://localhost:"; + portNum + 
"/users/{username}?restletMethods=post,get")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws 
Exception {
+                            
exchange.getOut().setBody(exchange.getIn().getHeader(Exchange.HTTP_METHOD, 
String.class));
+                        }
+                    });
+                
+                from("restlet:http://localhost:"; + portNum + 
"/users/{username}?restletMethods=put")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws 
Exception {
+                            
+                            exchange.getOut().setBody("result " + 
exchange.getIn().getHeader(Exchange.HTTP_METHOD, String.class));
+                        }
+                    });
+            }
+        };
+    }
+}
\ No newline at end of file


Reply via email to