You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by martin11 <ma...@gmail.com> on 2012/11/05 17:43:46 UTC

CXFRS Producer

Hello,I`m trying call REST web service by using cxfrs component and I got
following exception:
[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-60543-1352132871251-0-1 on ExchangeId:
ID-asgard-60543-1352132871251-0-2). Exhausted after delivery attempt: 1
caught: org.apache.camel.CamelExecutionException: Exception occurred during
execution on the exchange: Exchange[Message: GetSubjectRequest]
org.apache.camel.CamelExecutionException: Exception occurred during
execution on the exchange: Exchange[Message: GetSubjectRequest]    at
org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1286)[camel-core-2.10.2.jar:2.10.2]    
at
org.apache.camel.impl.DefaultExchange.setException(DefaultExchange.java:282)[camel-core-2.10.2.jar:2.10.2]    
at
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:64)[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]
What does mean this exception?Here is my camel context:
<camel:camelContext>     <camel:route id="timer-to-rest">        
<camel:from uri="timer://foo?fixedRate=true&amp;amp;period=5s"/>        
<camel:setExchangePattern pattern="InOut"/>         <camel:setHeader
headerName="CamelCxfRsUsingHttpAPI">           
<camel:constant>True</camel:constant>         </camel:setHeader>        
<camel:setHeader headerName="CamelHttpMethod">            
<camel:constant>POST</camel:constant>         </camel:setHeader>        
<camel:setBody>            
<camel:constant>GetSubjectRequest</camel:constant>         </camel:setBody>       
<camel:to uri="cxfrs://http://192.168.1.93/system/ws-edit/3/call"/>        
<camel:process ref="processor"/>     </camel:route> </camel:camelContext>
What is the problem? How looks correct XML configuration for REST service?



--
View this message in context: http://camel.465427.n5.nabble.com/CXFRS-Producer-tp5722162.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CXFRS Producer

Posted by Willem jiang <wi...@gmail.com>.
CXF doesn't through the detail exception out by default for the security reason.
Aki just contribute a patch[1] last month, if you are using Camel 2.11-SNAPSHOT, 
you should be able to get this kind exception from the client.

[1]https://issues.apache.org/jira/browse/CAMEL-5755

-- 
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 11:21 PM, martin11 wrote:

> Hi,
> 
> finaly I found source of my original exception. I had garbage in my pom.xml*
> <dependency> <groupId>org.apache.cxf</groupId> 
> <artifactId>cxf-rt-transports-http</artifactId> <version>2.6.2</version>
> </dependency>
> But my camel version is *2.10.2* which depends on apache-cxf-api wersion
> 2.6.3 (btw, it is missing in http://mvnrepository.com/)
> 
> I downloaded camel sources and during debug I found exception:
> java.lang.NoClassDefFoundError:
> org/apache/cxf/interceptor/StaxInEndingInterceptor
> I don`t know why camel override this original exception. Maybe it will be
> useful to keep original cause message.
> So, I removed unnecessary dependency from pom.xml and everything works as
> expected. Second solution is change cxf-rt-transports-http to required
> version *2.6.3* instead of 2.6.2.
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/CXFRS-Producer-tp5722162p5722234.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: CXFRS Producer

Posted by martin11 <ma...@gmail.com>.
Hi,

finaly I found source of my original exception. I had garbage in my pom.xml*
<dependency>     <groupId>org.apache.cxf</groupId>    
<artifactId>cxf-rt-transports-http</artifactId>     <version>2.6.2</version>
</dependency>
But my camel version is *2.10.2* which depends on apache-cxf-api wersion
2.6.3 (btw, it is missing in http://mvnrepository.com/)

I downloaded camel sources and during debug I found exception:
java.lang.NoClassDefFoundError:
org/apache/cxf/interceptor/StaxInEndingInterceptor
I don`t know why camel override this original exception. Maybe it will be
useful to keep original cause message.
So, I removed unnecessary dependency from pom.xml and everything works as
expected. Second solution is change cxf-rt-transports-http to required
version *2.6.3* instead of 2.6.2.



--
View this message in context: http://camel.465427.n5.nabble.com/CXFRS-Producer-tp5722162p5722234.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CXFRS Producer

Posted by martin11 <ma...@gmail.com>.
Hi Willem,

thank you for helping me. I`m new to Camel and unfortunately it is not clear
for me.

I don`t want to use ClientProxyAPI becaouse it require a resource class. I
want just:
1) take XML template
2) fill properties in XML by freemarker
3) setup custom value in header of service message
4) call REST web service with prepared XML by CXFRS or ony other component.

That is the way why I want to use httpClientAPI=true.

Thank you for any idea or explanation.



--
View this message in context: http://camel.465427.n5.nabble.com/CXFRS-Producer-tp5722162p5722223.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CXFRS Producer

Posted by Willem jiang <wi...@gmail.com>.
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).




Re: CXFRS Producer

Posted by martin11 <ma...@gmail.com>.
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.

Re: CXFRS Producer

Posted by Willem jiang <wi...@gmail.com>.
Hi,

It looks you didn't setup a right REST service request body. It could be a XML or JSON string.
As you are using CamelCxfRsUsingHttpAPI, you need to build up the request body yourself.

-- 
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 12:43 AM, martin11 wrote:

> Hello,I`m trying call REST web service by using cxfrs component and I got
> following exception:
> [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-60543-1352132871251-0-1 on ExchangeId:
> ID-asgard-60543-1352132871251-0-2). Exhausted after delivery attempt: 1
> caught: org.apache.camel.CamelExecutionException: Exception occurred during
> execution on the exchange: Exchange[Message: GetSubjectRequest]
> org.apache.camel.CamelExecutionException: Exception occurred during
> execution on the exchange: Exchange[Message: GetSubjectRequest] at
> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1286)[camel-core-2.10.2.jar:2.10.2] 
> at
> org.apache.camel.impl.DefaultExchange.setException(DefaultExchange.java:282)[camel-core-2.10.2.jar:2.10.2] 
> at
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:64)[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]
> What does mean this exception?Here is my camel context:
> <camel:camelContext> <camel:route id="timer-to-rest"> 
> <camel:from uri="timer://foo?fixedRate=true&amp;amp;period=5s"/> 
> <camel:setExchangePattern pattern="InOut"/> <camel:setHeader
> headerName="CamelCxfRsUsingHttpAPI"> 
> <camel:constant>True</camel:constant> </camel:setHeader> 
> <camel:setHeader headerName="CamelHttpMethod"> 
> <camel:constant>POST</camel:constant> </camel:setHeader> 
> <camel:setBody> 
> <camel:constant>GetSubjectRequest</camel:constant> </camel:setBody> 
> <camel:to uri="cxfrs://http://192.168.1.93/system/ws-edit/3/call"/> 
> <camel:process ref="processor"/> </camel:route> </camel:camelContext>
> What is the problem? How looks correct XML configuration for REST service?
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/CXFRS-Producer-tp5722162.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).