camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/7] git commit: CAMEL-7899 Fixed the issue that camel-jetty doesn't support multiple http method for the rest service
Date Thu, 09 Oct 2014 08:15:49 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.12.x 92a87937f -> ced67f412
  refs/heads/camel-2.13.x 3580582d4 -> 4ff0ee9f0
  refs/heads/camel-2.14.x 89c2cbbc6 -> 2bcac18c8


CAMEL-7899 Fixed the issue that camel-jetty doesn't support multiple http method for the rest
service


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

Branch: refs/heads/camel-2.14.x
Commit: 020bd1199d3a646cade989765036415cd3493dd2
Parents: 89c2cbb
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Thu Oct 9 15:36:45 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Thu Oct 9 16:14:16 2014 +0800

----------------------------------------------------------------------
 .../camel/component/http/CamelServlet.java      |  4 ++--
 .../HttpServletResolveConsumerStrategy.java     |  6 ++++-
 .../component/jetty/JettyHttpComponent.java     |  5 +++-
 .../jetty/rest/RestJettyPojoInOutTest.java      | 15 ++++++++++++
 .../servlet/rest/RestServletPojoInOutTest.java  | 24 ++++++++++++++++++++
 5 files changed, 50 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/020bd119/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
index f70b57b..b6cece8 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
@@ -179,12 +179,12 @@ public class CamelServlet extends HttpServlet {
 
     public void connect(HttpConsumer consumer) {
         log.debug("Connecting consumer: {}", consumer);
-        consumers.put(consumer.getPath(), consumer);
+        consumers.put(consumer.getEndpoint().getEndpointUri(), consumer);
     }
 
     public void disconnect(HttpConsumer consumer) {
         log.debug("Disconnecting consumer: {}", consumer);
-        consumers.remove(consumer.getPath());
+        consumers.remove(consumer.getEndpoint().getEndpointUri());
     }
 
     public String getServletName() {

http://git-wip-us.apache.org/repos/asf/camel/blob/020bd119/components/camel-http/src/main/java/org/apache/camel/component/http/HttpServletResolveConsumerStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpServletResolveConsumerStrategy.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpServletResolveConsumerStrategy.java
index dee20c3..de7ed4a 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpServletResolveConsumerStrategy.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpServletResolveConsumerStrategy.java
@@ -34,7 +34,11 @@ public class HttpServletResolveConsumerStrategy implements ServletResolveConsume
 
         if (answer == null) {
             for (String key : consumers.keySet()) {
-                if (consumers.get(key).getEndpoint().isMatchOnUriPrefix() && path.startsWith(key))
{
+                //We need to look up the consumer path here
+                String consumerPath = consumers.get(key).getPath();
+                HttpConsumer consumer = consumers.get(key);
+                // Just make sure the we get the right consumer path first
+                if (consumerPath.equals(path) || (consumer.getEndpoint().isMatchOnUriPrefix()
&& path.startsWith(consumerPath))) {
                     answer = consumers.get(key);
                     break;
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/020bd119/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index d006577..750be5d 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -162,7 +162,6 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
         List<Filter> filters = resolveAndRemoveReferenceListParameter(parameters, "filtersRef",
Filter.class);
         Long continuationTimeout = getAndRemoveParameter(parameters, "continuationTimeout",
Long.class);
         Boolean useContinuation = getAndRemoveParameter(parameters, "useContinuation", Boolean.class);
-        String httpMethodRestrict = getAndRemoveParameter(parameters, "httpMethodRestrict",
String.class);
         HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters,
"headerFilterStrategy", HeaderFilterStrategy.class);
         UrlRewrite urlRewrite = resolveAndRemoveReferenceParameter(parameters, "urlRewrite",
UrlRewrite.class);
         SSLContextParameters sslContextParameters = resolveAndRemoveReferenceParameter(parameters,
"sslContextParametersRef", SSLContextParameters.class);
@@ -179,10 +178,14 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
         String address = remaining;
         URI addressUri = new URI(UnsafeUriCharactersEncoder.encodeHttpURI(address));
         URI endpointUri = URISupport.createRemainingURI(addressUri, parameters);
+        // need to keep the httpMethodRestrict parameter for the endpointUri
+        String httpMethodRestrict = getAndRemoveParameter(parameters, "httpMethodRestrict",
String.class);
         // restructure uri to be based on the parameters left as we dont want to include
the Camel internal options
         URI httpUri = URISupport.createRemainingURI(addressUri, parameters);
         // create endpoint after all known parameters have been extracted from parameters
         JettyHttpEndpoint endpoint = new JettyHttpEndpoint(this, endpointUri.toString(),
httpUri);
+        
+        
         if (headerFilterStrategy != null) {
             endpoint.setHeaderFilterStrategy(headerFilterStrategy);
         } else {

http://git-wip-us.apache.org/repos/asf/camel/blob/020bd119/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
index f41dcaa..3f9dd28 100644
--- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
@@ -31,6 +31,14 @@ public class RestJettyPojoInOutTest extends BaseJettyTest {
         assertNotNull(out);
         assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
     }
+    
+    @Test
+    public void testJettyGetRequest() throws Exception {
+        String out = template.requestBody("http://localhost:" + getPort() + "/users/lives",
null, String.class);
+
+        assertNotNull(out);
+        assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
+    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -43,9 +51,16 @@ public class RestJettyPojoInOutTest extends BaseJettyTest {
 
                 // use the rest DSL to define the rest services
                 rest("/users/")
+                    // just return the default country here
+                    .get("lives").to("direct:start")
                     .post("lives").type(UserPojo.class).outType(CountryPojo.class)
                         .route()
                         .bean(new UserService(), "livesWhere");
+                
+                CountryPojo country = new CountryPojo();
+                country.setIso("EN");
+                country.setCountry("England");
+                from("direct:start").transform().constant(country);
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/020bd119/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPojoInOutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPojoInOutTest.java
b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPojoInOutTest.java
index 7ada95a..f9dde3a 100644
--- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPojoInOutTest.java
+++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPojoInOutTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.servlet.rest;
 
 import java.io.ByteArrayInputStream;
 
+import com.meterware.httpunit.GetMethodWebRequest;
 import com.meterware.httpunit.PostMethodWebRequest;
 import com.meterware.httpunit.WebRequest;
 import com.meterware.httpunit.WebResponse;
@@ -44,6 +45,22 @@ public class RestServletPojoInOutTest extends ServletCamelRouterTestSupport
{
         assertNotNull(out);
         assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
     }
+    
+    @Test
+    public void testServletPojoGet() throws Exception {
+        
+        WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users/lives");
+        ServletUnitClient client = newClient();
+        client.setExceptionsThrownOnErrorStatus(false);
+        WebResponse response = client.getResponse(req);
+
+        assertEquals(200, response.getResponseCode());
+
+        String out = response.getText();
+
+        assertNotNull(out);
+        assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
+    }   
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -55,9 +72,16 @@ public class RestServletPojoInOutTest extends ServletCamelRouterTestSupport
{
 
                 // use the rest DSL to define the rest services
                 rest("/users/")
+                    // just return the default country here
+                    .get("lives").to("direct:start")
                     .post("lives").type(UserPojo.class).outType(CountryPojo.class)
                         .route()
                         .bean(new UserService(), "livesWhere");
+                
+                CountryPojo country = new CountryPojo();
+                country.setIso("EN");
+                country.setCountry("England");
+                from("direct:start").transform().constant(country);
             }
         };
     }


Mime
View raw message