WSO2 DataMapper将XML转换为SOAP错误

问题描述 投票:0回答:1

我必须将后端肥皂响应转换为json。为此,我使用datamapper XML到JSON。数据映射器在运行时由于以下错误而失败:

[2019-11-01 14:58:29,805] [micro-integrator] ERROR - DataMapperMediator DataMapper mediator : mapping failed
Error while parsing XML input stream. Current context not Object but root
    at org.wso2.carbon.mediator.datamapper.engine.input.readers.XMLInputReader.read(XMLInputReader.java:124)
    at org.wso2.carbon.mediator.datamapper.engine.input.InputBuilder.buildInputModel(InputBuilder.java:59)
    at org.wso2.carbon.mediator.datamapper.engine.core.mapper.MappingHandler.doMap(MappingHandler.java:90)
    at org.wso2.carbon.mediator.datamapper.DataMapperMediator.transform(DataMapperMediator.java:390)
    at org.wso2.carbon.mediator.datamapper.DataMapperMediator.mediate(DataMapperMediator.java:301)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
    at org.apache.synapse.rest.Resource.process(Resource.java:363)
    at org.apache.synapse.rest.API.process(API.java:370)
    at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:135)
    at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:113)
    at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:58)
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:325)
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:578)
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:195)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
    at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:265)
    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
[2019-11-01 14:58:29,807] [micro-integrator] ERROR - AgendaRestApi DataMapper mediator : mapping failed
Error while parsing XML input stream. Current context not Object but root
    at org.wso2.carbon.mediator.datamapper.engine.input.readers.XMLInputReader.read(XMLInputReader.java:124)
    at org.wso2.carbon.mediator.datamapper.engine.input.InputBuilder.buildInputModel(InputBuilder.java:59)
    at org.wso2.carbon.mediator.datamapper.engine.core.mapper.MappingHandler.doMap(MappingHandler.java:90)
    at org.wso2.carbon.mediator.datamapper.DataMapperMediator.transform(DataMapperMediator.java:390)
    at org.wso2.carbon.mediator.datamapper.DataMapperMediator.mediate(DataMapperMediator.java:301)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
    at org.apache.synapse.rest.Resource.process(Resource.java:363)
    at org.apache.synapse.rest.API.process(API.java:370)
    at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:135)
    at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:113)
    at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:58)
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:325)
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:578)
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:195)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
    at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:265)
    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

用于配置数据映射器的输入和输出样本文件是:输入

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <GetSpecialtiesResponse xmlns="http://agenda/">
         <GetSpecialtiesResult xmlns:a="http://schemas.datacontract.org/2004/07/WsAgenda.DataContracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:Specialty>
               <a:code>cardiology</a:code>
               <a:name>Cardiologie</a:name>
            </a:Specialty>
            <a:Specialty>
               <a:code>neurology</a:code>
               <a:name>Neurologie</a:name>
            </a:Specialty>
         </GetSpecialtiesResult>
      </GetSpecialtiesResponse>
   </s:Body>
</s:Envelope>

输出:

{"Specialties": [
      {
      "id": "cardiology",
      "description": "Cardiologie"
   },
     {
      "id": "cardiology",
      "description": "Cardiologie"
   }
]}

在数据映射器设计器中,似乎一切正常。这是序列代码:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/agenda" name="AgendaRestApi" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" url-mapping="/specialties">
        <inSequence>
            <log/>
            <payloadFactory description="" media-type="xml">
                <format>
                    <soapenv:Envelope xmlns:agen="http://agenda/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                        <soapenv:Header/>
                        <soapenv:Body>
                            <agen:GetSpecialties/>
                        </soapenv:Body>
                    </soapenv:Envelope>
                </format>
                <args/>
            </payloadFactory>
            <header name="soapAction" scope="transport" value="http://agenda/agenda/GetSpecialties"/>
            <send>
                <endpoint key="AgendaEP"/>
            </send>
        </inSequence>
        <outSequence>
            <datamapper config="gov:datamapper/GetSpecialtiesMapping.dmc" inputSchema="gov:datamapper/GetSpecialtiesMapping_inputSchema.json" inputType="XML" outputSchema="gov:datamapper/GetSpecialtiesMapping_outputSchema.json" outputType="JSON" xsltStyleSheet="gov:datamapper/GetSpecialtiesMapping_xsltStyleSheet.xml"/>
            <property name="messageType" scope="axis2" type="STRING" value="application/json"/>
            <respond/>
        </outSequence>
        <faultSequence>
            <log level="full"/>
        </faultSequence>
    </resource>
</api>

欢迎所有可能的解决方案:)

wso2 datamapper
1个回答
0
投票

我遇到了同样的问题,并解决了在datamapper介体之前添加此属性的问题。

<property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
<datamapper config="gov:datamapper/GetSpecialtiesMapping.dmc" inputSchema="gov:datamapper/GetSpecialtiesMapping_inputSchema.json" inputType="XML" outputSchema="gov:datamapper/GetSpecialtiesMapping_outputSchema.json" outputType="JSON" xsltStyleSheet="gov:datamapper/GetSpecialtiesMapping_xsltStyleSheet.xml"/>

希望这会有所帮助,JP

© www.soinside.com 2019 - 2024. All rights reserved.