以下流程将传入的JSON有效内容转换为SOAP消息,该消息在子流中用于发出Web服务请求。一切正常 - 我能够回复原始(传入)请求的响应,但我想添加最后一步,将SOAP结果转换为JSON,然后再将其发送回客户端。
以下是流程:
<mule ...>
<data-mapper:config name="json2xml_grf" transformationGraphPath="json2xml.grf" doc:name="DataMapper"/>
<flow name="simpleFlow" doc:name="simpleFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<set-property propertyName="Access-Control-Allow-Origin" value="*" doc:name="Property"/>
<choice doc:name="Choice">
<when expression="#[message.inboundProperties['http.method'] != 'OPTIONS']">
<data-mapper:transform config-ref="json2xml_grf" doc:name="DataMapper"/>
<flow-ref name="invokeCalculatorService" doc:name="invokeCalculator"/>
</when>
<otherwise>
<http:response-builder status="200" doc:name="HTTP Response Builder">
...
</http:response-builder>
</otherwise>
</choice>
</flow>
<flow name="invokeService" doc:name="invokeService">
<cxf:proxy-client payload="body" enableMuleSoapHeaders="true" doc:name="Proxy Client">
</cxf:proxy-client>
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="/Users/jsleeuw/MuleStudio/workspace/calc/src/main/resources/transformsoap.xslt" doc:name="XSLT"/>
<http:outbound-endpoint exchange-pattern="request-response" doc:name="CalculatorService" method="POST" host="service-host" port="30001"/>
</flow>
</mule>
将DataMapper放在子流的末尾,如下所示:
...
<flow-ref name="invokeCalculatorService" doc:name="invokeCalculator"/>
<data-mapper:transform config-ref="xml2json_grf" doc:name="DataMapper"/>
...
导致此错误:
********************************************************************************
Message : Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException). Message payload is of type: DepthXMLStreamReader
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Content is not allowed in prolog. (org.xml.sax.SAXParseException)
org.apache.xerces.util.ErrorHandlerWrapper:-1 (null)
2. org.xml.sax.SAXParseException: Content is not allowed in prolog. (net.sf.saxon.trans.DynamicError)
net.sf.saxon.event.Sender:308 (null)
3. XPath evaluation failed (org.jetel.exception.JetelRuntimeException)
org.jetel.component.tree.reader.xml.XmlXPathEvaluator:81 (null)
4. Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException)
com.mulesoft.mule.module.datamapper.impl.DefaultGraphExecutor:83 (null)
5. Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException). Message payload is of type: DepthXMLStreamReader (com.mulesoft.mule.module.datamapper.processors.DataMapperMessageExecutionException)
com.mulesoft.mule.module.datamapper.processors.DataMapperMessageProcessor:135 (null)
--------------------------------------------------------------------------------
将datamapper放在子流的末尾会阻止响应。
我应该如何改变我的回应?
答案 0 :(得分:1)
从Content is not allowed in prolog
例外看来<flow-ref name="invokeCalculatorService" />
似乎没有返回可解析为XML的有效负载。
此子流程返回org.apache.cxf.staxutils.DepthXMLStreamReader
,即javax.xml.stream.XMLStreamReader
。我所知道的唯一可以将此类型反序列化为XML字符串的变换器是:<mulexml:dom-to-xml-transformer />
。
您可以在data-mapper
元素之前添加一个吗?