You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/08/12 10:04:34 UTC
[1/2] git commit: CAMEL-7679 Fixed the Second argument is null issue
of camel-cxfrs
Repository: camel
Updated Branches:
refs/heads/camel-2.12.x 4bbd0acc1 -> ef824f2a0
refs/heads/camel-2.13.x 35e23d1ad -> 58c983ecb
CAMEL-7679 Fixed the Second argument is null issue of camel-cxfrs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/58c983ec
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/58c983ec
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/58c983ec
Branch: refs/heads/camel-2.13.x
Commit: 58c983ecb7349706c369969f7fb83655680fe4f7
Parents: 35e23d1
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Aug 12 15:35:03 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue Aug 12 16:03:46 2014 +0800
----------------------------------------------------------------------
.../apache/camel/component/bean/MethodInfo.java | 6 ++
.../cxf/jaxrs/CxfRsConsumerWithBeanTest.java | 70 ++++++++++++++++++++
.../jaxrs/testbean/CustomerServiceResource.java | 11 +++
.../cxf/jaxrs/testbean/ServiceUtil.java | 24 +++++++
4 files changed, 111 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/58c983ec/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java b/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
index 0c22e75..d0686ef 100644
--- a/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
+++ b/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
@@ -430,6 +430,12 @@ public class MethodInfo {
boolean multiParameterArray = false;
if (exchange.getIn().getHeader(Exchange.BEAN_MULTI_PARAMETER_ARRAY) != null) {
multiParameterArray = exchange.getIn().getHeader(Exchange.BEAN_MULTI_PARAMETER_ARRAY, Boolean.class);
+ if (multiParameterArray) {
+ // Just change the message body to an Object array
+ if (!(body instanceof Object[])) {
+ body = exchange.getIn().getBody(Object[].class);
+ }
+ }
}
// if there was an explicit method name to invoke, then we should support using
http://git-wip-us.apache.org/repos/asf/camel/blob/58c983ec/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
new file mode 100644
index 0000000..8d98975
--- /dev/null
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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;
+
+import javax.naming.Context;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.cxf.CXFTestSupport;
+import org.apache.camel.component.cxf.jaxrs.testbean.ServiceUtil;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
+import org.junit.Test;
+
+public class CxfRsConsumerWithBeanTest extends CamelTestSupport {
+ private static final String CXT = CXFTestSupport.getPort1() + "/CxfRsConsumerWithBeanTest";
+ private static final String CXF_RS_ENDPOINT_URI = "cxfrs://http://localhost:" + CXT + "/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource";
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ Context context = super.createJndiContext();
+ context.bind("service", new ServiceUtil());
+ return context;
+ }
+
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from(CXF_RS_ENDPOINT_URI).to("bean://service?multiParameterArray=true");
+ };
+ };
+ }
+
+ @Test
+ public void testPutConsumer() throws Exception {
+
+ HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/c20");
+ StringEntity entity = new StringEntity("string");
+ entity.setContentType("text/plain");
+ put.setEntity(entity);
+ CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+
+ try {
+ HttpResponse response = httpclient.execute(put);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ assertEquals("c20string", EntityUtils.toString(response.getEntity()));
+ } finally {
+ httpclient.close();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/58c983ec/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceResource.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceResource.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceResource.java
index c2e216f..4c69965 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceResource.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceResource.java
@@ -16,10 +16,12 @@
*/
package org.apache.camel.component.cxf.jaxrs.testbean;
+import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@@ -34,5 +36,14 @@ public interface CustomerServiceResource {
@PUT
@Path("/customers/")
Response updateCustomer(Customer customer);
+
+ @Path("/{id}")
+ @PUT()
+ @Consumes({ "application/xml", "text/plain",
+ "application/json" })
+ @Produces({ "application/xml", "text/plain",
+ "application/json" })
+ Object invoke(@PathParam("id") String id,
+ String payload);
}
// END SNIPPET: example
http://git-wip-us.apache.org/repos/asf/camel/blob/58c983ec/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/ServiceUtil.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/ServiceUtil.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/ServiceUtil.java
new file mode 100644
index 0000000..22398e6
--- /dev/null
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/ServiceUtil.java
@@ -0,0 +1,24 @@
+/**
+ * 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;
+
+public class ServiceUtil {
+ public String invoke(String id, String payload) {
+ return id + payload;
+ }
+
+}
[2/2] git commit: CAMEL-7679 Fixed the Second argument is null issue
of camel-cxfrs
Posted by ni...@apache.org.
CAMEL-7679 Fixed the Second argument is null issue of camel-cxfrs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ef824f2a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ef824f2a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ef824f2a
Branch: refs/heads/camel-2.12.x
Commit: ef824f2a0785f349d6b802806d80b167d6992915
Parents: 4bbd0ac
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Aug 12 15:35:03 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue Aug 12 16:04:06 2014 +0800
----------------------------------------------------------------------
.../apache/camel/component/bean/MethodInfo.java | 6 ++
.../cxf/jaxrs/CxfRsConsumerWithBeanTest.java | 70 ++++++++++++++++++++
.../jaxrs/testbean/CustomerServiceResource.java | 11 +++
.../cxf/jaxrs/testbean/ServiceUtil.java | 24 +++++++
4 files changed, 111 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ef824f2a/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java b/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
index 0c22e75..d0686ef 100644
--- a/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
+++ b/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
@@ -430,6 +430,12 @@ public class MethodInfo {
boolean multiParameterArray = false;
if (exchange.getIn().getHeader(Exchange.BEAN_MULTI_PARAMETER_ARRAY) != null) {
multiParameterArray = exchange.getIn().getHeader(Exchange.BEAN_MULTI_PARAMETER_ARRAY, Boolean.class);
+ if (multiParameterArray) {
+ // Just change the message body to an Object array
+ if (!(body instanceof Object[])) {
+ body = exchange.getIn().getBody(Object[].class);
+ }
+ }
}
// if there was an explicit method name to invoke, then we should support using
http://git-wip-us.apache.org/repos/asf/camel/blob/ef824f2a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
new file mode 100644
index 0000000..8d98975
--- /dev/null
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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;
+
+import javax.naming.Context;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.cxf.CXFTestSupport;
+import org.apache.camel.component.cxf.jaxrs.testbean.ServiceUtil;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
+import org.junit.Test;
+
+public class CxfRsConsumerWithBeanTest extends CamelTestSupport {
+ private static final String CXT = CXFTestSupport.getPort1() + "/CxfRsConsumerWithBeanTest";
+ private static final String CXF_RS_ENDPOINT_URI = "cxfrs://http://localhost:" + CXT + "/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource";
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ Context context = super.createJndiContext();
+ context.bind("service", new ServiceUtil());
+ return context;
+ }
+
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from(CXF_RS_ENDPOINT_URI).to("bean://service?multiParameterArray=true");
+ };
+ };
+ }
+
+ @Test
+ public void testPutConsumer() throws Exception {
+
+ HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/c20");
+ StringEntity entity = new StringEntity("string");
+ entity.setContentType("text/plain");
+ put.setEntity(entity);
+ CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+
+ try {
+ HttpResponse response = httpclient.execute(put);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ assertEquals("c20string", EntityUtils.toString(response.getEntity()));
+ } finally {
+ httpclient.close();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/ef824f2a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceResource.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceResource.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceResource.java
index c2e216f..4c69965 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceResource.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceResource.java
@@ -16,10 +16,12 @@
*/
package org.apache.camel.component.cxf.jaxrs.testbean;
+import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@@ -34,5 +36,14 @@ public interface CustomerServiceResource {
@PUT
@Path("/customers/")
Response updateCustomer(Customer customer);
+
+ @Path("/{id}")
+ @PUT()
+ @Consumes({ "application/xml", "text/plain",
+ "application/json" })
+ @Produces({ "application/xml", "text/plain",
+ "application/json" })
+ Object invoke(@PathParam("id") String id,
+ String payload);
}
// END SNIPPET: example
http://git-wip-us.apache.org/repos/asf/camel/blob/ef824f2a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/ServiceUtil.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/ServiceUtil.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/ServiceUtil.java
new file mode 100644
index 0000000..22398e6
--- /dev/null
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/ServiceUtil.java
@@ -0,0 +1,24 @@
+/**
+ * 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;
+
+public class ServiceUtil {
+ public String invoke(String id, String payload) {
+ return id + payload;
+ }
+
+}