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/09/19 07:59:05 UTC
[1/2] git commit: CAMEL-7827 Add possibility to specify parameters to
URLs using http api. For example : have a URI like /service/{id} and have an
array to merge the parameters
Repository: camel
Updated Branches:
refs/heads/master 70a637fb2 -> 828c2b971
CAMEL-7827 Add possibility to specify parameters to URLs using http api. For example : have a URI like /service/{id} and have an array to merge the parameters
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e4b224be
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e4b224be
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e4b224be
Branch: refs/heads/master
Commit: e4b224becaac67381602d7c3d8285e2dca0a900b
Parents: 70a637f
Author: larochef <fl...@gmail.com>
Authored: Tue Sep 16 14:50:03 2014 +0200
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Sep 19 13:51:29 2014 +0800
----------------------------------------------------------------------
.../component/cxf/jaxrs/CxfRsProducer.java | 8 +++++-
.../component/cxf/jaxrs/CxfRsProducerTest.java | 28 ++++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e4b224be/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
index 804a51cf..59390de 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
@@ -139,6 +139,7 @@ public class CxfRsProducer extends DefaultProducer {
String httpMethod = inMessage.getHeader(Exchange.HTTP_METHOD, String.class);
Class<?> responseClass = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Class.class);
Type genericType = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_GENERIC_TYPE, Type.class);
+ Object[] pathValues = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES, Object[].class);
String path = inMessage.getHeader(Exchange.HTTP_PATH, String.class);
if (LOG.isTraceEnabled()) {
@@ -149,7 +150,12 @@ public class CxfRsProducer extends DefaultProducer {
// set the path
if (path != null) {
- client.path(path);
+ if(pathValues != null && pathValues.length > 0) {
+ client.path(path, pathValues);
+ }
+ else {
+ client.path(path);
+ }
}
CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint();
http://git-wip-us.apache.org/repos/asf/camel/blob/e4b224be/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
index af255e9..accb1f0 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
@@ -246,6 +246,34 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
assertEquals("Get a wrong customer name", response.getName(), "John");
assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
}
+
+ @Test
+ public void testGetCustomerWithVariableReplacementAndCxfRsEndpoint() {
+ Exchange exchange
+ = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=true", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.setPattern(ExchangePattern.InOut);
+ Message inMessage = exchange.getIn();
+ // set the Http method
+ inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
+ // set the relative path
+ inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/{customerId}");
+ // Set variables for replacement
+ inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES, new String[] {"123"});
+ // Specify the response class , cxfrs will use InputStream as the response object type
+ inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
+ // since we use the Get method, so we don't need to set the message body
+ inMessage.setBody(null);
+ }
+ });
+
+ // get the response message
+ Customer response = (Customer) exchange.getOut().getBody();
+ assertNotNull("The response should not be null ", response);
+ assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
+ assertEquals("Get a wrong customer name", response.getName(), "John");
+ assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
+ }
@Test
public void testAddCustomerUniqueResponseCodeWithHttpClientAPI() {
[2/2] git commit: CAMEL-7827 Fixed the CS errors.
Posted by ni...@apache.org.
CAMEL-7827 Fixed the CS errors.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/828c2b97
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/828c2b97
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/828c2b97
Branch: refs/heads/master
Commit: 828c2b97186183a33a3d1610b4c4407aa9ffe5cd
Parents: e4b224b
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Sep 19 13:44:48 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Sep 19 13:53:15 2014 +0800
----------------------------------------------------------------------
.../org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java | 6 +++---
.../apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java | 3 +--
2 files changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/828c2b97/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
index 59390de..7d6dec2 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
@@ -38,6 +38,7 @@ import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.LRUSoftCache;
+import org.apache.camel.util.ObjectHelper;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
import org.apache.cxf.jaxrs.client.Client;
@@ -150,10 +151,9 @@ public class CxfRsProducer extends DefaultProducer {
// set the path
if (path != null) {
- if(pathValues != null && pathValues.length > 0) {
+ if (ObjectHelper.isNotEmpty(pathValues) && pathValues.length > 0) {
client.path(path, pathValues);
- }
- else {
+ } else {
client.path(path);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/828c2b97/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
index accb1f0..1ed46a7 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
@@ -249,8 +249,7 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
@Test
public void testGetCustomerWithVariableReplacementAndCxfRsEndpoint() {
- Exchange exchange
- = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=true", new Processor() {
+ Exchange exchange = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=true", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.getIn();