0

以下流程将传入的 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)
-------------------------------------------------------------------------------- 

而将数据映射器放在子流的末尾最终会阻塞响应。

我应该如何改变我的反应?

4

1 回答 1

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您可以在元素之前添加一个吗?

于 2013-05-29T17:39:12.830 回答