camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem jiang <willem.ji...@gmail.com>
Subject Re: CXFRS Producer
Date Tue, 06 Nov 2012 12:15:14 GMT
Hi Martin,

If you don't want to prepare the request message yourself, you can consider to use the ClientProxyAPI
instead of HttpAPI by setting the header inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API,
Boolean.FALSE);

Then you can prepare the request message like this, CXF will send the request as XML or json.


exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.getIn();
// set the operation name 
inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomer");
// using the proxy client API
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE);
// set a customer header
inMessage.setHeader("key", "value");
// set the parameters , if you just have one parameter 
// camel will put this object into an Object[] itself
inMessage.setBody("123");



-- 
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang





On Tuesday, November 6, 2012 at 7:54 PM, martin11 wrote:

> Hello Willem,thank for your answer. Looks that you have right. Let me
> describe my situation. I have XML file which I want to use together with
> freemarker. I already tested my XML to call REST web service from SoapUI
> tool and it works well.*/ws-read.xml/* template:
> &lt;?xml version="1.0" encoding="UTF-8"?&gt; <ws:GetSubjectRequest
> xmlns:ws="http://portal.system.com/ws/WS-READ-1.1">${headers.subject}</ws:GetSubjectRequest>
> How can I use my XML template in Camel? Do I need marshal XML to JSON every
> time before I call CXFRS component? Or is there any way how to use message
> body in XML format?There is my context:
> <camel:camelContext> <camel:dataFormats> <camel:xmljson
> id="xmljson"/> <camel:xmljson id="xmljsonWithOptions"
> forceTopLevelObject="true" trimSpaces="true" rootName="newRoot"
> skipNamespaces="false" removeNamespacePrefixes="false"/> 
> </camel:dataFormats> <camel:route id="timer-to-ws"> <camel:from
> uri="timer://foo?fixedRate=true&amp;amp;period=4s"/> 
> <camel:setExchangePattern pattern="InOut"/> <camel:setHeader
> headerName="subject"> <camel:constant>test</camel:constant> 
> </camel:setHeader> <camel:setHeader
> headerName="CamelCxfRsUsingHttpAPI"> 
> <camel:constant>True</camel:constant> </camel:setHeader> 
> <camel:setHeader headerName="CamelHttpMethod"> 
> <camel:constant>POST</camel:constant> </camel:setHeader> 
> <camel:to uri="freemarker:xml/ws-read.xml"/> <camel:marshal
> ref="xmljsonWithOptions"/> <camel:to
> uri="cxfrs://http://192.168.1.93/system/ws-edit/3/call?httpClientAPI=true&amp;amp;synchronous=true"/>

> <camel:process ref="ldapProcessor"/> </camel:route>
> </camel:camelContext>
> and I got this exception:
> [mel-1) thread #0 - timer://foo] XMLSerializer INFO Using
> default type
> string{"ws:GetSubjectRequest":{"@xmlns:ws":"http://portal.system.com/ws/WS-READ-1.1","#text":"test"}}
> [mel-1) thread #0 - timer://foo] BusApplicationContext INFO 
> Refreshing org.apache.cxf.bus.spring.BusApplicationContext@5d106021: startup
> date [Tue Nov 06 12:38:23 CET 2012]; parent: Root
> WebApplicationContext[mel-1) thread #0 - timer://foo]
> idationXmlBeanDefinitionReader INFO Loading XML bean definitions from class
> path resource [META-INF/cxf/cxf.xml] [mel-1) thread #0 - timer://foo]
> idationXmlBeanDefinitionReader INFO Loading XML bean definitions from class
> path resource [META-INF/cxf/camel/cxf-extension-camel.xml] [mel-1) thread #0
> - timer://foo] DefaultErrorHandler ERROR Failed delivery for
> (MessageId: ID-asgard-57144-1352201886004-0-3 on ExchangeId:
> ID-asgard-57144-1352201886004-0-2). Exhausted after delivery attempt: 1
> caught: *java.lang.ClassCastException: java.util.ArrayList cannot be cast to
> org.apache.cxf.message.MessageContentsList*java.lang.ClassCastException:
> java.util.ArrayList cannot be cast to
> org.apache.cxf.message.MessageContentsList at
> org.apache.camel.component.cxf.jaxrs.DefaultCxfRsBinding.bindCamelMessageBodyToRequestBody(DefaultCxfRsBinding.java:166)[camel-cxf-2.10.2.jar:2.10.2]

> at
> org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeHttpClient(CxfRsProducer.java:143)[camel-cxf-2.10.2.jar:2.10.2]

> at
> org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process(CxfRsProducer.java:87)[camel-cxf-2.10.2.jar:2.10.2]

> at
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[camel-core-2.10.2.jar:2.10.2]

> at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.10.2.jar:2.10.2]

> at
> org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122)[camel-core-2.10.2.jar:2.10.2]

> at
> org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298)[camel-core-2.10.2.jar:2.10.2]

> at
> org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117)[camel-core-2.10.2.jar:2.10.2]

> at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.10.2.jar:2.10.2]

> at
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)[camel-core-2.10.2.jar:2.10.2]
> 
> How should I set message body and in which format?
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/CXFRS-Producer-tp5722162p5722212.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Mime
View raw message