Camel CXF:IllegalArgumentException参数应为X类型

时间:2015-12-01 10:20:19

标签: java soap apache-camel cxf

我正在开发一个使用CXF调用服务的Camel项目。 服务是通过wsdl定义的,我无法对其进行修改。 我使用wsdl2java生成了类:我将有许多其他远程服务,它们可能经常更改,所以我希望尽可能多地生成POJO和接口。

我生成的界面如下所示:

@WebService(targetNamespace = "http://service.company.fr", name = "myService")
@XmlSeeAlso({ObjectFactory.class})
public interface MyService {

    @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
    @WebResult(name = "sendMessageResponse", targetNamespace = "http://service.company.fr", partName = "parameters")
    @WebMethod
    SendMessageResponse sendLetter(
            @WebParam(partName = "parameters", name = "sendLetter", targetNamespace = "http://service.company.fr")
            SendLetter parameters
    ) throws MessageServiceException_Exception;

    @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
    @WebResult(name = "sendMessageResponse", targetNamespace = "http://service.company.fr", partName = "parameters")
    @WebMethod
    SendMessageResponse sendWebNotification(
            @WebParam(partName = "parameters", name = "sendWebNotification", targetNamespace = "http://service.company.fr")
            SendWebNotification parameters
    ) throws MessageServiceException_Exception;

    @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
    @WebResult(name = "sendMessageResponse", targetNamespace = "http://service.company.fr", partName = "parameters")
    @WebMethod
    SendMessageResponse sendEmail(
            @WebParam(partName = "parameters", name = "sendEmail", targetNamespace = "http://service.company.fr")
            SendEmail parameters
    ) throws MessageServiceException_Exception;
}

我在XML文件中定义了CXF端点,如下所示:

  <cxf:cxfEndpoint id="serviceEndpoint"
                   address="http://localhost:9081/soap/service"
                   serviceClass="fr.company.service.MyService">
    <cxf:properties>
      <entry key="dataFormat" value="POJO"/>
    </cxf:properties>
  </cxf:cxfEndpoint>

最后,我在Camel路线中调用该服务:

from(URI_SERVICE)
                .process(sendEmailBodyProcessor)
                .to("cxf:bean:serviceEndpoint");

sendEmailBodyProcessor使用SendEmail对象(对应于界面中的第3个服务)设置正文。如果我只留下我在界面中使用的服务,它可以工作,但如果我离开其他服务,我会收到此错误:

java.lang.IllegalArgumentException: Part {http://service.company.fr}parameters should be of type fr.company.service.SendLetter, not fr.company.service.SendEmail
    at org.apache.cxf.jaxb.io.DataWriterImpl.checkPart(DataWriterImpl.java:292)
    at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:220)
    at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:117)
    at org.apache.cxf.wsdl.interceptors.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
    ...

我尝试使用operationNamemethod等标题,但我无法让它发挥作用......

有没有人知道如何让它发挥作用?

非常感谢!

1 个答案:

答案 0 :(得分:2)

我终于找到了解决问题的方法!...

就我而言,operationName还不够,我还需要添加operationNamespace = "http://service.company.fr"