CXF&amp; Camel:不支持List <object>作为Web服务参数

时间:2018-05-25 13:03:35

标签: java web-services apache-camel cxf

我正在使用JBoss Fuse 6.3使用Camel和CXF组件(2.17.0)开发Web服务。我也使用“代码优先”的方法。我发现一个简单的对象作为参数(doSomething方法)很顺利,但是无法使用List of Objects作为参数(更新方法)。以下是调查结果:

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

&LT; 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>

&lt; to uri =“cxf:bean:MyService?defaultOperationName = update”/&gt;

当arg0只包含一个元素(ObjectRequest)时,它不会抛出错误,但Web服务请求没有内容:

&lt; soap:Envelope xmlns:soap =“http://schemas.xmlsoap.org/soap/envelope/”&gt;&lt; soap:Body&gt;&lt; ns2:update xmlns:ns2 =“http:// ......“/&GT;&LT; /皂:身体与GT;&LT; /皂:信封&GT;

当arg0有两个元素时,会抛出以下错误:

java.lang.IllegalArgumentException:获取错误的参数大小以调用out服务,Expect size 1,Parameter size 2.请检查消息正文是否与CXFEndpoint POJO Dataformat请求匹配。     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]     在org.apache.camel.component.cxf.CxfProducer.process(CxfProducer.java:120)[241:org.apache.camel.camel-cxf:2.17.0.redhat-630187]     在org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]

1 个答案:

答案 0 :(得分:0)

解决方案是在设置交换体时,将List包裹在一个对象数组周围,如下面的

所示

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

ObjectRequest obj1; //需要初始化

ObjectRequest obj2; //需要初始化

arg0.add(OBJ1);

arg0.add(OBJ2);

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

相关问题