[ https://issues.apache.org/activemq/browse/CAMEL-2239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=56186#action_56186 ]
Willem Jiang edited comment on CAMEL-2239 at 12/1/09 2:17 AM: -------------------------------------------------------------- if I set the request message header with Response.class, {code} inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Response.class); {code} to invoke the Customer service method with WebClient API: {code} @POST @Path("/customersUniqueResponseCode/") public Response addCustomerUniqueResponseCode(Customer customer) { customer.setId(++currentId); customers.put(customer.getId(), customer); return Response.status(201).entity(customer).build(); } {code} I will get the response entity as an InputStream, not the Customer instance that I want. After digging the WebClient code for a while, I found {code} response = WebClient.invoke(httpMethod, body, responseClass); {code} will use the responseClass to unmarshal the inputStream with Provider. So we need to specify the Response's entity Class for the HttpClient API to get right response entity. For the camel-cxfrs producer, it is not possible to find the entity information from the Response class, so we need to let the user specify the Response's entity class first. I wrote a test case to demonstrate this issue. {code} @Test public void testAddCustomerUniqueResponseCode() { Exchange exchange = template.send("cxfrs://http://localhost:9002?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, "POST"); // set the relative path inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customersUniqueResponseCode"); // put the response's entity into out message body // by specifying the response entity class inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class); // create a new customer object Customer customer = new Customer(); customer.setId(8888); customer.setName("Willem"); inMessage.setBody(customer); } }); // get the response message Customer response = (Customer) exchange.getOut().getBody(); assertNotNull("The response should not be null ", response); assertTrue("Get a wrong customer id ", response.getId() != 8888); assertEquals("Get a wrong customer name", response.getName(), "Willem"); } {code} was (Author: njiang): if I set the request message header with Response.class, {code} inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Response.class); {code} to invoke the Customer service method with WebClient API: {code} @POST @Path("/customersUniqueResponseCode/") public Response addCustomerUniqueResponseCode(Customer customer) { customer.setId(++currentId); customers.put(customer.getId(), customer); return Response.status(201).entity(customer).build(); } {code} I will get the response entity as an InputStream, not the Customer instance that I want. After digging the WebClient code for a while, I found {code} response = WebClient.invoke(httpMethod, body, responseClass); {code} will use the responseClass to unmarshal the inputStream with Provider. So we need to specify the Response's entity Class for the HttpClient API to get right response entity. For the camel-cxfrs producer, it is not possible to find the entity information from the Response class, so we need to let the user specify the Response's entity class first. I wrote a test case to demonstrate this issue. {code} @Test public void testAddCustomerUniqueResponseCode() { Exchange exchange = template.send("cxfrs://http://localhost:9002?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, "POST"); // set the relative path inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customersUniqueResponseCode"); // put the response's entity into out message body // by specifying the response entity class inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class); // create a new customer object Customer customer = new Customer(); customer.setId(8888); customer.setName("Willem"); inMessage.setBody(customer); } }); // get the response message Customer response = (Customer) exchange.getOut().getBody(); assertNotNull("The response should not be null ", response); assertTrue("Get a wrong customer id ", response.getId() != 8888); assertEquals("Get a wrong customer name", response.getName(), "Willem"); } {code} > Cannot determine specific JmsMessage type to use from body class > ---------------------------------------------------------------- > > Key: CAMEL-2239 > URL: https://issues.apache.org/activemq/browse/CAMEL-2239 > Project: Apache Camel > Issue Type: Bug > Components: camel-cxf > Affects Versions: 2.1.0 > Reporter: Charles Moulliard > Assignee: Willem Jiang > Fix For: 2.2.0 > > > Error : Cannot determine specific JmsMessage type to use from body class. > Will use generic JmsMessage. Body class: > org.apache.cxf.jaxrs.impl.ResponseImpl. If you want to send a POJO then your > class might need to implement java.io.Serializable, or you can force a > specific type by setting the jmsMessageType option on the JMS endpoint > is reported with the following camel routing > {code} > <beans xmlns="http://www.springframework.org/schema/beans" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:context="http://www.springframework.org/schema/context" > xmlns:camel="http://camel.apache.org/schema/spring" > xmlns:cxf="http://camel.apache.org/schema/cxf" > xmlns:cxf-core="http://cxf.apache.org/core" > xmlns:jaxrs="http://cxf.apache.org/jaxrs" > xsi:schemaLocation=" > http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans.xsd > http://www.springframework.org/schema/context > http://www.springframework.org/schema/context/spring-context.xsd > http://camel.apache.org/schema/osgi > http://camel.apache.org/schema/osgi/camel-osgi.xsd > http://camel.apache.org/schema/spring > http://camel.apache.org/schema/spring/camel-spring.xsd > http://camel.apache.org/schema/cxf > http://camel.apache.org/schema/cxf/camel-cxf.xsd > http://cxf.apache.org/jaxrs > http://cxf.apache.org/schemas/jaxrs.xsd > http://cxf.apache.org/core > http://cxf.apache.org/schemas/core.xsd"> > <import resource="classpath:META-INF/cxf/cxf.xml" /> > <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> > <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" /> > <import > resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" /> > <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" /> > > <bean id="jms" > class="org.apache.activemq.camel.component.ActiveMQComponent"> > <property name="connectionFactory"> > <bean class="org.apache.activemq.ActiveMQConnectionFactory"> > <property name="brokerURL" > value="vm://localhost?broker.persistent=false"/> > </bean> > </property> > </bean> > <!-- > <jaxrs:features> <cxf-core:logging/> </jaxrs:features> <bean > id="jsonProvider" > class="org.apache.cxf.jaxrs.provider.JSONProvider"/> > --> > <jaxrs:server id="restService" address="/proxy/camel-rest-example/" > staticSubresourceResolution="true"> > <jaxrs:serviceBeans> > <ref bean="reportIncidentService" /> > </jaxrs:serviceBeans> > <!-- <jaxrs:features><cxf-core:logging/></jaxrs:features> --> > </jaxrs:server> > <bean id="reportIncidentService" > class="org.apache.camel.example.reportincident.restful.ReportIncidentService" > /> > > <cxf:rsServer id="rsServer" address="/camel-rest-example/" > > serviceClass="org.apache.camel.example.reportincident.restful.ReportIncidentService" > /> > <cxf:rsClient id="rsClient" address="http://localhost:8181/cxf/proxy/"/> > <camel:camelContext trace="true" > xmlns="http://camel.apache.org/schema/osgi"> > <camel:route> > <camel:from uri="cxfrs:bean:rsServer" /> > <!-- <camel:to > uri="log:org.apache.camel.example.reportIncident?level=DEBUG" /> --> > <camel:to uri="jms:queue:in" /> > </camel:route> > > <camel:route> > <camel:from uri="jms:queue:in"/> > <camel:to uri="cxfrs:bean:rsClient" /> > </camel:route> > </camel:camelContext> > > </beans> > {code} -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.