我有2个Mule流…第一个流公开了执行DB CRUD操作的SOAP Web服务…我的第一个流程是:-
<flow name="ServiceFlow" doc:name="ServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP"/>
<cxf:jaxws-service serviceClass="com.test.services.schema.maindata.v1.MainData" doc:name="SOAP"/>
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl"/>
</flow>
web服务的SOAP请求:-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://services.test.com/schema/MainData/V1">
<soapenv:Header/>
<soapenv:Body>
<v1:insertDataRequest>
<v1:Id>477</v1:Id>
<v1:Name>ttttt</v1:Name>
<v1:Age>56</v1:Age>
<v1:Designation>aaaaaa </v1:Designation>
</v1:insertDataRequest>
</soapenv:Body>
</soapenv:Envelope>
, SOAP响应是:-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<insertDataResponse xmlns="http://services.test.com/schema/MainData/V1">
<Response>Data inserted Successfully</Response>
<Id>0</Id>
<Age>0</Age>
</insertDataResponse>
</soap:Body>
</soap:Envelope>
现在我有另一个流,这是一个客户端流到这个web服务....客户端流程为:-
<flow name="ClientFlow" doc:name="ClientFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8888" path="clientpath" doc:name="HTTP"/>
<set-payload doc:name="Set Payload" value="#[import com.test.services.schema.maindata.v1.*; dRequest = new DataRequest();dRequest.id = 7;dRequest.age = 55;dRequest.name = 'aValue';dRequest.designation = 'hhhhh'; dRequest]"/>
<async doc:name="Async">
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<logger message="payload :- #[message.payload]" level="INFO" doc:name="Logger"/>
</async>
<cxf:jaxws-client doc:name="SOAP" serviceClass="com.test.services.schema.maindata.v1.MainData" operation="insertDataOperation" port="MainDataPort" />
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP" method="POST"/>
</flow>
现在问题是……在这个客户端流程中,我正在设置来自Mule <set-payload
的请求…服务工作正常,来自客户端的请求使用Http出站发布到主服务…但我从回应中得到了例外…我不知道如何设置这里的响应…我需要在http出站后再次使用设置有效载荷吗?如果是……那我怎么设置它??请帮忙……下面是我得到的例外:-
Exception stack is:
1. unable to marshal type "com.test.services.schema.maindata.v1.DataResponse" as an element because it is missing an @XmlRootElement annotation (com.sun.istack.SAXException2)
com.sun.xml.bind.v2.runtime.XMLSerializer:244 (null)
2. null (javax.xml.bind.MarshalException)
com.sun.xml.bind.v2.runtime.MarshallerImpl:328 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/xml/bind/MarshalException.html)
3. failed to mashal objec tto XML (java.io.IOException)
org.mule.module.xml.transformer.jaxb.JAXBMarshallerTransformer$1:110 (null)
4. failed to mashal objec tto XML (java.io.IOException). Message payload is of type: HttpResponse (org.mule.execution.ResponseDispatchException)
org.mule.transport.http.HttpMessageProcessTemplate:141 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/execution/ResponseDispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
com.sun.istack.SAXException2: unable to marshal type "com.test.services.schema.maindata.v1.DataResponse" as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:244)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:303)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:490)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
UPDATED FLOW:-我使用Java组件为客户端流设置响应,它工作正常,没有任何问题…:-
<flow name="ClientFlow" doc:name="ClientFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8888" path="aa" doc:name="HTTP"/>
<set-payload doc:name="Set Payload" value="#[import com.test.services.schema.maindata.v1.*; dRequest = new DataRequest();dRequest.id = 7;dRequest.age = 55;dRequest.name = 'aValue';dRequest.designation = 'hhhhh'; dRequest]"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP">
<cxf:jaxws-client doc:name="SOAP" serviceClass="com.test.services.schema.maindata.v1.MainData" operation="insertDataOperation" port="MainDataPort" />
</http:outbound-endpoint>
<custom-transformer class="com.test.request.ResponseTransformer" doc:name="JavaTransformerForResponse"/> <!-- Response Java Class -->
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<logger message="#[message.payload]" level="INFO" doc:name="JSON Logging"/>
</flow>
现在工作正常,日志中的响应是:-
Now Entering Method:: com.test.services.schema.maindata.v1.Impl.MainDataImpl.insertDataOperation() *****
Data inserted Successfully
[2014-07-31 13:06:23,150] [INFO ] [[SOAPHeaderInterceptor].connector.http.mule.default.receiver.04] <com.test.services.schema.maindata.v1.DataResponse>
<response>Data inserted Successfully</response>
<id>0</id>
<age>0</age>
</com.test.services.schema.maindata.v1.DataResponse>
但是我不想使用Java组件的响应…请建议如何使用setpayload或Expression在Mule…
您可以删除custom-transformer
,因为它确实没有为您做任何有用的事情。
我相信原文:
无法封送类型"com.test.services.schema.maindata.v1 "。DataResponse作为元素,因为它缺少@XmlRootElement注释
问题是由于Mule需要一种方法将DataResponse
对象从cxf:jaxws-client
封送到可以通过HTTP返回给调用者的形式。
mulexml:object-to-xml-transformer
的添加通过提示Mule如何封送解决了这个问题(即不要使用JAXB,因为它根本无法工作,而是使用XStream)。
因此根据David的建议,最终解决方案是使用object-to-json-transformer
或object-to-xml-transformer
或object-to-string-transformer
任何一个都可以在这里用于封送响应对象