我使用Mule CXF组件从localhost调用Web服务。被调用的Web服务返回SoapResult类型的对象,但Mule在转换它时,将返回类型检测为" [B"。最后选择的JAXBMarshallerTransformer和转换失败了:
org.mule.api.transformer.TransformerException: An invalid return type "class [B" was specified for transformer "JAXBMarshallerTransformer"
at org.mule.module.xml.transformer.jaxb.JAXBMarshallerTransformer.doTransform(JAXBMarshallerTransformer.java:119)
at org.mule.transformer.AbstractTransformer.transform(AbstractTransformer.java:420)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:377)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
My Mule flow:
<http:listener-config name="HTTP_Listener_Configuration_2" host="0.0.0.0" port="5556" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="6543" basePath="ws" doc:name="HTTP Request Configuration"/>
<mulexml:jaxb-context name="JAXB_Context" packageNames="soap.cxf.helloworld" doc:name="JAXB Context"/>
<flow name="helloworldsoapFlow">
<http:listener config-ref="HTTP_Listener_Configuration_2" path="/hello" doc:name="HTTP"/>
<set-payload value="#[{"David","Rose"}]" doc:name="Set Payload"/>
<cxf:jaxws-client operation="getHelloWorld" serviceClass="soap.cxf.helloworld.IHelloWorld" doc:name="helloWorldSoap"/>
<http:request config-ref="HTTP_Request_Configuration" path="hello" method="POST" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger" message="#[payload]"/>
</flow>
我的WSDL:
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://cxfsoapservice.iais.ir/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://cxfsoapservice.iais.ir/" name="HelloWorldService">
<types>
<xsd:schema>
<xsd:import namespace="http://cxfsoapservice.iais.ir/" schemaLocation="http://localhost:6543/ws/hello?xsd=1"/>
</xsd:schema>
</types>
<message name="getHelloWorld">
<part name="name1" type="xsd:string"/>
<part name="name2" type="xsd:string"/>
</message>
<message name="getHelloWorldResponse">
<part name="return" type="tns:soapResult"/>
</message>
<portType name="IHelloWorld">
<operation name="getHelloWorld" parameterOrder="name1 name2">
<input wsam:Action="http://cxfsoapservice.iais.ir/IHelloWorld/getHelloWorldRequest" message="tns:getHelloWorld"/>
<output wsam:Action="http://cxfsoapservice.iais.ir/IHelloWorld/getHelloWorldResponse" message="tns:getHelloWorldResponse"/>
</operation>
</portType>
<binding name="HelloWorldPortBinding" type="tns:IHelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="getHelloWorld">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://cxfsoapservice.iais.ir/"/>
</input>
<output>
<soap:body use="literal" namespace="http://cxfsoapservice.iais.ir/"/>
</output>
</operation>
</binding>
<service name="HelloWorldService">
<port name="HelloWorldPort" binding="tns:HelloWorldPortBinding">
<soap:address location="http://localhost:6543/ws/hello"/>
</port>
</service>
</definitions>
我的XSD:
<xs:schema xmlns:tns="http://cxfsoapservice.iais.ir/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://cxfsoapservice.iais.ir/">
<xs:element name="soapResult" type="tns:soapResult"/>
<xs:complexType name="soapResult">
<xs:sequence>
<xs:element name="names" type="xs:string" minOccurs="0"/>
<xs:element name="message" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
My Mule Flow图片:
答案 0 :(得分:1)
datamapper转换器仅在企业版中可用,您还可以使用<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
将对象转换为XML。
答案 1 :(得分:0)