Chris W
Chris W

Reputation: 21

CXF & Camel : does not support List<Object> as web service parameter

I'm using JBoss Fuse 6.3 to develop a web service using Camel and CXF component (2.17.0). I also use "code first" approach. I find thing goes well with a simple object as the parameter (doSomething method), but fails to work with a List of Objects as the parameter (update method). Here are the findings:

@WebService
public java.util.List<ObjectResponse> update(
    java.util.List<ObjectRequest> arg0
);
public ObjectResponse doSomething(
    Object parameter
);

<cxf:cxfEndpoint

  address="http://...."
  endpointName="ws:MyServicePort" id="MyService"
  loggingFeatureEnabled="true"
  serviceClass="com...MyService"
  <cxf:properties>;
      <entry key="dataFormat" value="POJO"/>
  </cxf:properties>
</cxf:cxfEndpoint>

<to uri="cxf:bean:MyService?defaultOperationName=update"/>

When arg0 contains only one element(ObjectRequest), it doesn't throw error,however the web service request doesn't have content:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:update xmlns:ns2="http://...."/></soap:Body></soap:Envelope>

When arg0 has two elements, it throws following error:

java.lang.IllegalArgumentException: Get the wrong parameter size to invoke the out service, Expect size 1, Parameter size 2. Please check if the message body matches the CXFEndpoint POJO Dataformat request. at org.apache.camel.component.cxf.CxfProducer.checkParameterSize(CxfProducer.java:272)[241:org.apache.camel.camel-cxf:2.17.0.redhat-630187] at org.apache.camel.component.cxf.CxfProducer.getParams(CxfProducer.java:310)[241:org.apache.camel.camel-cxf:2.17.0.redhat-630187] at org.apache.camel.component.cxf.CxfProducer.process(CxfProducer.java:120)[241:org.apache.camel.camel-cxf:2.17.0.redhat-630187] at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]

Upvotes: 0

Views: 777

Answers (1)

Chris W
Chris W

Reputation: 21

The solution is when set the exchange body, wrap the List around an object array, as shown in following

java.util.List arg0 = new ArrayList();

ObjectRequest obj1;//need to be initialized

ObjectRequest obj2;//need to be initialized

arg0.add(obj1);

arg0.add(obj2);

exchange.getIn().setBody(new Object[] {arg0});

Upvotes: 1

Related Questions