骆驼CXF:IllegalArgumentException参数应为X类型 [英] Camel CXF: IllegalArgumentException parameters should be of type X

查看:272
本文介绍了骆驼CXF:IllegalArgumentException参数应为X类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on a Camel project calling services with CXF. The services are defined through a wsdl and which I cannot modify it. I generated classes with wsdl2java: I will have many other remote services, they may change often, so I want to have the POJOs and interfaces to be generated as much as possible.

我生成的界面如下:

@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端点,如下所示:

I defined the CXF Endpoint in an XML file, like this :

  <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>

最后,我以骆驼路线呼叫该服务:

And finally, I am calling the service in a Camel route :

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

sendEmailBodyProcessor使用SendEmail对象设置主体(对应于界面中的第三项服务).如果仅保留我在界面中使用的服务,则可以使用,但是如果保留其他服务,则会出现此错误:

The sendEmailBodyProcessor sets the body with a SendEmail object (corresponding to the 3rd service from the interface). If I leave only the service I use in the interface, it works, but if I leave the other services, I get this error:

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等标题,但无法正常使用...

I tried using headers like operationName or method etc. but I can't get it to work...

有人知道如何使它工作吗?

Has anyone a clue on how I can get it to work?

非常感谢!

推荐答案

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

I finally found how to solve my problem!...

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

In my case, operationName was not enough, I needed to add operationNamespace = "http://service.company.fr" as well!

这篇关于骆驼CXF:IllegalArgumentException参数应为X类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆