3
votes

I'm currently trying to get familiar with Servicemix, Camel, CXF, etc. and have basically the same question as somebody had four years ago here: How do I convert my BeanInvocation object in camel to a message body and headers? Unfortunately, the answer there don't help me much. As one of the answers mentions: all examples on the Camel website concern themselves with sending something to a bean from CXF.

I have a bean proxy endpoint that I'm using in a POJO, injected via

@Produce(uri ="direct:start")
MyService producer; //public interface example.MyService { void myMethod(MyObject o);}

When I use another bean endpoint at the other end, implementing a consumer for that interface, this all works fine. What I now would like to do is to use camel-cxf to consume a web service implementing that interface instead. I created a cxfEndpoint via:

<cxf:cxfEndpoint id="cxfEndpoint"
    address="http://localhost:8080/MyService/services/MyService"
    wsdlURL="http://localhost:8080/MyService/services/MyService?wsdl"
    serviceName="s:MyService"
    serviceClass="example.MyService"
    endpointName="s:MyService"
    xmlns:s="http://example" />

What I'm now basically trying to do is, in a RouteBuilder:

 from( "direct:start" ).to( "cxf:bean:cxfEndpoint" );

but get an Exception, when trying invoke something on the proxy object:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Part      
{http://example}o should be of type example.MyObject, not 
org.apache.camel.component.bean.BeanInvocation

From what I understand, the Spring proxy object generates a BeanInvocation object that can be consumed by another bean endpoint, and I have to transform this into a way the cxf can generate a SOAP request out of it (or is there some automatic conversion?).

But I'm kind of stuck doing that: I tried soap marshalling as described at http://camel.apache.org/soap.html or writing my own Processor, but I'm not even sure if I just failed, or if that's not how it's supposed to work. I also tried to set the cxfEndpoint into the different message modes without success.

Any pointers what I should be generally doing would be greatly appreciated!

1

1 Answers

3
votes

So after a week of trial and error, I found that the answer is quite simple. If the cxfEndpoint is set to POJO mode (the default), the solution is to just grab the invocation parameters and stuff them into the message body instead:

from( "direct:start" ).process( new Processor() {
        @Override
        public void process( Exchange e) throws Exception {
            final BeanInvocation bi = e.getIn().getBody( BeanInvocation.class );
            e.getIn().setBody( bi.getArgs() );
        }
    } ).to( "cxf:bean:cxfEndpoint" )

I guess this could be done more elegantly somehow though.