Author: ningjiang Date: Tue Mar 22 04:11:01 2011 New Revision: 1084064 URL: http://svn.apache.org/viewvc?rev=1084064&view=rev Log: CAMEL-3796 CxfRsProducer should support invoking methods with no parameters
Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java?rev=1084064&r1=1084063&r2=1084064&view=diff ============================================================================== --- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java (original) +++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java Tue Mar 22 04:11:01 2011 @@ -181,7 +181,11 @@ public class CxfRsProducer extends Defau // find out the method which we want to invoke JAXRSServiceFactoryBean sfb = cfb.getServiceFactory(); sfb.getResourceClasses(); - Object[] parameters = inMessage.getBody(Object[].class); + // check the null body first + Object[] parameters = null; + if (inMessage.getBody() != null) { + parameters = inMessage.getBody(Object[].class); + } // get the method Method method = findRightMethod(sfb.getResourceClasses(), methodName, getParameterTypes(parameters)); // Will send out the message to @@ -219,6 +223,10 @@ public class CxfRsProducer extends Defau } private Class<?>[] getParameterTypes(Object[] objects) { + // We need to handle the void parameter situation. + if (objects == null) { + return new Class[]{}; + } Class<?>[] answer = new Class[objects.length]; int i = 0; for (Object obj : objects) { Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java?rev=1084064&r1=1084063&r2=1084064&view=diff ============================================================================== --- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java (original) +++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java Tue Mar 22 04:11:01 2011 @@ -16,12 +16,15 @@ */ package org.apache.camel.component.cxf.jaxrs; +import java.util.List; + import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; import org.apache.camel.Message; import org.apache.camel.Processor; import org.apache.camel.component.cxf.CxfConstants; import org.apache.camel.component.cxf.jaxrs.testbean.Customer; +import org.junit.Test; import org.springframework.context.support.AbstractXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -63,6 +66,32 @@ public class CxfRsProducerAddressOverrid // END SNIPPET: ProxyExample } + @Test + public void testGetConstumersWithClientProxyAPI() { + Exchange exchange = template.send("direct://proxy", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.setPattern(ExchangePattern.InOut); + Message inMessage = exchange.getIn(); + inMessage.setHeader(Exchange.DESTINATION_OVERRIDE_URL, + "http://localhost:9002"); + // set the operation name + inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomers"); + // using the proxy client API + inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE); + // set the parameters , if you just have one parameter + // camel will put this object into an Object[] itself + inMessage.setBody(null); + } + }); + + // get the response message + List<Customer> response = (List<Customer>) exchange.getOut().getBody(); + + assertNotNull("The response should not be null ", response); + assertEquals("Get a wrong customer id ", String.valueOf(response.get(0).getId()), "113"); + assertEquals("Get a wrong customer name", response.get(0).getName(), "Dan"); + } + @Override public void testGetConstumerWithHttpCentralClientAPI() { // START SNIPPET: HttpExample Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java?rev=1084064&r1=1084063&r2=1084064&view=diff ============================================================================== --- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java (original) +++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java Tue Mar 22 04:11:01 2011 @@ -18,6 +18,7 @@ package org.apache.camel.component.cxf.j import java.io.InputStream; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import org.apache.camel.Exchange; @@ -73,6 +74,30 @@ public class CxfRsProducerTest extends C } @Test + public void testGetConstumersWithClientProxyAPI() { + Exchange exchange = template.send("direct://proxy", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.setPattern(ExchangePattern.InOut); + Message inMessage = exchange.getIn(); + // set the operation name + inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomers"); + // using the proxy client API + inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE); + // set the parameters , if you just have one parameter + // camel will put this object into an Object[] itself + inMessage.setBody(null); + } + }); + + // get the response message + List<Customer> response = (List<Customer>) exchange.getOut().getBody(); + + assertNotNull("The response should not be null ", response); + assertEquals("Get a wrong customer id ", String.valueOf(response.get(0).getId()), "113"); + assertEquals("Get a wrong customer name", response.get(0).getName(), "Dan"); + } + + @Test public void testGetConstumerWithHttpCentralClientAPI() { // START SNIPPET: HttpExample Exchange exchange = template.send("direct://http", new Processor() {