camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/2] camel git commit: CAMEL-8245 Support model reference in CXFRS endpoint with thanks to Sergey
Date Sun, 18 Jan 2015 03:24:38 GMT
Repository: camel
Updated Branches:
  refs/heads/master 53f2df112 -> 1ca7fea70


CAMEL-8245 Support model reference in CXFRS endpoint with thanks to Sergey


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

Branch: refs/heads/master
Commit: 46c5abcb760c4b1bbe5a8de9cff7f97bc4a767cc
Parents: 53f2df1
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Sun Jan 18 11:00:52 2015 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Sun Jan 18 11:13:43 2015 +0800

----------------------------------------------------------------------
 .../component/cxf/jaxrs/CxfRsEndpoint.java      | 12 ++++++-
 .../component/cxf/jaxrs/CxfRsConsumerTest.java  | 37 ++++++++++++--------
 .../testbean/CustomerServiceNoAnnotations.java  | 27 ++++++++++++++
 .../cxf/jaxrs/CustomerServiceModel.xml          | 23 ++++++++++++
 4 files changed, 84 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/46c5abcb/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
index b89eded..b032e1b 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
@@ -116,7 +116,8 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     private long continuationTimeout = 30000;
     @UriParam(defaultValue = "false")
     private boolean isSetDefaultBus;
-    
+    @UriParam
+    private String modelRef;    
     private List<Feature> features = new ModCountCopyOnWriteArrayList<Feature>();
     private InterceptorHolder interceptorHolder = new InterceptorHolder();
     private Map<String, Object> properties;
@@ -213,6 +214,9 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
         if (getAddress() != null) {
             sfb.setAddress(getAddress());
         }
+        if (modelRef != null) {
+            sfb.setModelRef(modelRef);
+        }
         if (getResourceClasses() != null) {
             sfb.setResourceClasses(getResourceClasses());
         }
@@ -234,6 +238,9 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
         if (address != null) {
             cfb.setAddress(address);
         }
+        if (modelRef != null) {
+            cfb.setModelRef(modelRef);
+        }
         if (getResourceClasses() != null && !getResourceClasses().isEmpty()) {
             cfb.setResourceClass(getResourceClasses().get(0));
             cfb.getServiceFactory().setResourceClasses(getResourceClasses());
@@ -351,6 +358,9 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
     public void setAddress(String address) {
         this.address = address;
     }
+    public void setModelRef(String ref) {
+        this.modelRef = ref;
+    }
 
     public String getAddress() {
         return resolvePropertyPlaceholders(address);

http://git-wip-us.apache.org/repos/asf/camel/blob/46c5abcb/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
index b37cefa..fe1071a 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
@@ -48,8 +48,14 @@ public class CxfRsConsumerTest extends CamelTestSupport {
     private static final String PUT_REQUEST = "<Customer><name>Mary</name><id>123</id></Customer>";
     private static final String CXT = CXFTestSupport.getPort1() + "/CxfRsConsumerTest";
     // START SNIPPET: example
-    private static final String CXF_RS_ENDPOINT_URI = "cxfrs://http://localhost:" + CXT +
"/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource";
-    private static final String CXF_RS_ENDPOINT_URI2 = "cxfrs://http://localhost:" + CXT
+ "/rest2?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
+    private static final String CXF_RS_ENDPOINT_URI = 
+            "cxfrs://http://localhost:" + CXT + "/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource";
+    private static final String CXF_RS_ENDPOINT_URI2 = 
+            "cxfrs://http://localhost:" + CXT + "/rest2?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
+    private static final String CXF_RS_ENDPOINT_URI3 = 
+            "cxfrs://http://localhost:" + CXT + "/rest3?"
+            + "resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceNoAnnotations&"
+            + "modelRef=classpath:/org/apache/camel/component/cxf/jaxrs/CustomerServiceModel.xml";
     
     protected RouteBuilder createRouteBuilder() throws Exception {
         final Processor testProcessor = new TestProcessor();
@@ -58,6 +64,7 @@ public class CxfRsConsumerTest extends CamelTestSupport {
                 errorHandler(new NoErrorHandlerBuilder());
                 from(CXF_RS_ENDPOINT_URI).process(testProcessor);
                 from(CXF_RS_ENDPOINT_URI2).process(testProcessor);
+                from(CXF_RS_ENDPOINT_URI3).process(testProcessor);
             }
         };
     }
@@ -79,22 +86,24 @@ public class CxfRsConsumerTest extends CamelTestSupport {
     }
     
     @Test
-    public void testGetCustomer() throws Exception {
-        invokeGetCustomer("http://localhost:" + CXT + "/rest/customerservice/customers/126",
-                          "{\"Customer\":{\"id\":126,\"name\":\"Willem\"}}");
-        invokeGetCustomer("http://localhost:" + CXT + "/rest/customerservice/customers/123",
-                          "customer response back!");
-        invokeGetCustomer("http://localhost:" + CXT + "/rest/customerservice/customers/400",
-            "The remoteAddress is 127.0.0.1");
-        
+    public void testGetCustomerInterface() throws Exception {
+        doTestGetCustomer("rest");
     }
     @Test
-    public void testGetCustomer2() throws Exception {
-        invokeGetCustomer("http://localhost:" + CXT + "/rest2/customerservice/customers/126",
+    public void testGetCustomerImpl() throws Exception {
+        doTestGetCustomer("rest2");
+    }
+    @Test
+    public void testGetCustomerInterfaceAndModel() throws Exception {
+        doTestGetCustomer("rest3");
+    }
+    
+    private void doTestGetCustomer(String contextUri) throws Exception {
+        invokeGetCustomer("http://localhost:" + CXT + "/" + contextUri + "/customerservice/customers/126",
                           "{\"Customer\":{\"id\":126,\"name\":\"Willem\"}}");
-        invokeGetCustomer("http://localhost:" + CXT + "/rest2/customerservice/customers/123",
+        invokeGetCustomer("http://localhost:" + CXT + "/" + contextUri + "/customerservice/customers/123",
                           "customer response back!");
-        invokeGetCustomer("http://localhost:" + CXT + "/rest2/customerservice/customers/400",
+        invokeGetCustomer("http://localhost:" + CXT + "/" + contextUri + "/customerservice/customers/400",
             "The remoteAddress is 127.0.0.1");
         
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/46c5abcb/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceNoAnnotations.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceNoAnnotations.java
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceNoAnnotations.java
new file mode 100644
index 0000000..b8b97ed
--- /dev/null
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceNoAnnotations.java
@@ -0,0 +1,27 @@
+/**
+ * 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.cxf.jaxrs.testbean;
+
+
+
+// START SNIPPET: example
+public interface CustomerServiceNoAnnotations {
+
+    Customer getCustomer(String id);
+
+}
+// END SNIPPET: example

http://git-wip-us.apache.org/repos/asf/camel/blob/46c5abcb/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CustomerServiceModel.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CustomerServiceModel.xml
b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CustomerServiceModel.xml
new file mode 100644
index 0000000..4d4e392
--- /dev/null
+++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CustomerServiceModel.xml
@@ -0,0 +1,23 @@
+<!--
+    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.
+-->
+<model xmlns="http://cxf.apache.org/jaxrs">
+ <resource name="org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceNoAnnotations"
path="customerservice">
+    <operation name="getCustomer" verb="GET" path="/customers/{id}" produces="application/json">
+        <param name="id" type="PATH"/>
+    </operation> 
+ </resource>
+</model>


Mime
View raw message