【问题标题】:Camel CXF throws Part{example.com}parameters should be of type X not YCamel CXF 抛出 Part{example.com} 参数应该是 X 类型而不是 Y
【发布时间】:2018-07-06 10:22:43
【问题描述】:

我是 SOAP 新手,不知道问题出在哪里。我看过similar SO post 但不幸的是它没有帮助。 错误信息是:

WARNING: Interceptor for {http://bbbts/Service}Service#{http://bbbts/Service}ConfirmAStatus has thrown exception, unwinding now
IllegalArgumentException: Part {http://bbbts/Service}parameters should be of type package.ConfirmAStatusResponse, not package.ConfirmAStatus

我在 Camel 中配置了如下端点:

    CxfEndpoint cxfEndpoint = new CxfEndpoint();
    cxfEndpoint.setAddress("http://0.0.0.0:8888/aaans/services/Service");
    cxfEndpoint.setWsdlURL("Service.wsdl");
    cxfEndpoint.setCamelContext(camelContext);
    cxfEndpoint.setBus(bus);
    cxfEndpoint.setServiceNameString("bbbts:Service");
    cxfEndpoint.setDefaultOperationName("ConfirmAStatus"); 
    cxfEndpoint.setDefaultOperationNamespace("http://bbbts/Service");

    try { 
    cxfEndpoint.setServiceClass("package.Service"); 
    } catch (ClassNotFoundException e1) { 
    } 
    cxfEndpoint.setDataFormat(DataFormat.POJO);  

我已经通过 cxf-codegen 生成了 Service 类,它看起来像这样:

@WebService(targetNamespace = "http://bbbts/Service", name = "Service")
@XmlSeeAlso({ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface Service {

@WebMethod(operationName = "ConfirmAStatus", action = "http://aaans/2012/nsv1/ConfirmARecallStatus")
@Action(input = "http://aaans/2012/nsv1/ConfirmProductBatchRecallStatus", output = "http://aaans/2012/nsv1/ConfirmAStatusResponse")
@WebResult(name = "ConfirmAStatusResponse", targetNamespace = "http://aaans/2012/", partName = "parameters")
public ConfirmAStatusResponse confirmAStatus(
    @WebParam(partName = "parameters", name = "ConfirmAStatus", targetNamespace = "http://aaans/2012/")
    ConfirmAStatus parameters
);
.... ConfirmBStatusResponse ...

我继承了 WSDL 文件,但我没有任何使用 WSDL 文件的经验,所以请告诉我哪些部分会有所帮助。 这是wsdl文件中的操作:

<wsdl:operation name="ConfirmAStatus">
  <wsdl:input wsaw:Action="http://aaans/2012/nsv1/ConfirmAStatus" message="tns:Service_ConfirmAStatus_InputMessage"/>
  <wsdl:output wsaw:Action="http://aaans/2012/nsv1/ConfirmAStatusResponse" message="tns:Service_ConfirmAStatus_OutputMessage"/>
</wsdl:operation>

我对错误信息一无所知。该函数的参数类型显然是 ConfirmAStatus 类型,而不是错误消息中声称的 ...StatusResponse 类型。我尝试添加其他 SO 帖子中提到的默认操作命名空间,但无济于事。我什至不知道它是否与命名空间有关。如果有人能指出我可以尝试解决这个问题的方向,我将不胜感激。

编辑:添加 wsdl:message 部分

<wsdl:message name="Service_ConfirmAStatus_InputMessage">
  <wsdl:part name="parameters" element="q1:ConfirmAStatus" xmlns:q1="hhttp://aaans/2012/"/>
</wsdl:message>
<wsdl:message name="Service_ConfirmAStatus_OutputMessage">
  <wsdl:part name="parameters" element="q2:ConfirmAStatusResponse" xmlns:q2="http://aaans/2012/"/>
</wsdl:message>

【问题讨论】:

  • 添加整个 WSDL 是可能的。您的响应应该是 ConfirmAStatusResponse 而不是 ConfirmAStatus 这是一个不同的对象。
  • @Namphibian 很遗憾我不能发布整个 wsdl,我可以发布必要的部分

标签: java soap wsdl apache-camel cxf


【解决方案1】:

错误消息说参数parameters 的类型是ConfirmAStatus,但应该是ConfirmAStatusResponse 类型

由于您的实现需要类型 ConfirmAStatus

ConfirmAStatus parameters

我怀疑 WSDL 中输入消息的定义有误,但您的问题中没有包含该部分。

你可能有这样的消息定义

<wsdl:message name="Service_ConfirmAStatus_InputMessage">
    <wsdl:part name="NameOfTheElement" element="ReferenceToTheSchemaElementThatRepresentsThisMessagePart"/>
</wsdl:message>

在此示例中,ReferenceToTheSchemaElementThatRepresentsThisMessagePart 的 XML 模式定义似乎是 ConfirmAStatus 类型,而不是 ConfirmAStatusResponse

【讨论】:

  • 非常感谢!我认为这解决了它。我会将相关的 wsdl 部分添加到原始问题中。现在出现了一个不同的问题:解组错误:“意外元素(uri:”aaans/2012“,local:aaansEnvelope”)。预期的元素是(无)”。你认为我应该发布一个不同的问题还是添加相关信息?我会做更多的测试,然后将答案标记为已解决,当我可以确认它已通过此解决时,再次感谢
  • 不客气。我会创建另一个问题,因为标题会误导(新)问题。
猜你喜欢
  • 2014-02-07
  • 2010-11-05
  • 2021-11-01
  • 1970-01-01
  • 2019-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多