我无法按顺序将SoapFault转换为JSON,请提供帮助。
这是肥皂反应:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>Error en consultar: LA CONSULTA NO ARROJO NINGUN RESULTADO</faultstring>
<detail>
<ns8:consultarFault xmlns:ns8="http://colsanitas.com/Persona/">
<consultarFault>
<ns7:errorCode xmlns:ns7="http://colsanitas.com/osi/comun/nofuncionales">38</ns7:errorCode>
<ns7:errorDesc xmlns:ns7="http://colsanitas.com/osi/comun/nofuncionales">LA CONSULTA NO ARROJO NINGUN RESULTADO</ns7:errorDesc>
</consultarFault>
</ns8:consultarFault>
</detail>
</soapenv:Fault>
这是我的REST API:
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="PersonaOSI" context="/persona">
<resource methods="GET" uri-template="/{documento}?tipo={tipo}">
<inSequence>
<log>
<property name="DOCUMENTO" expression="get-property('uri.var.documento')"/>
<property name="TIPO" expression="get-property('uri.var.tipo')"/>
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:srv="http://colsanitas.com/osi/srv" xmlns:per="http://colsanitas.com/Persona/" xmlns:per1="http://colsanitas.com/osi/comun/persona" xmlns:nof="http://colsanitas.com/osi/comun/nofuncionales">
<soapenv:Body>
<per:ConsultarPersonaEnt>
<consultarPersonaEnt xmlns="">
<srv:consultaPersona>
<srv:identificacion>
<per1:Documento>$1</per1:Documento>
<per1:TipoDocumento>$2</per1:TipoDocumento>
</srv:identificacion>
<srv:aseguradora>?</srv:aseguradora>
</srv:consultaPersona>
</consultarPersonaEnt>
</per:ConsultarPersonaEnt>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('uri.var.documento')"/>
<arg evaluator="xml" expression="get-property('uri.var.tipo')"/>
</args>
</payloadFactory>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
<header name="Action" scope="default" value="http://www.colsanitas.com/Persona/consultar"/>
<send>
<endpoint>
<address uri="https://osiapppre02.colsanitas.com/services/PersonaOSI" format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence>
<payloadFactory media-type="json">
<format>
{"Error" : $1}
</format>
<args>
<arg xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" evaulator="xml" expression="//soapenv:Fault/faultstring"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<send/>
</faultSequence>
</resource>
但我得到一个例外:
org.apache.axiom.om.impl.llom.OMSourcedElementImpl cannot be cast to org.apache.axiom.soap.SOAPFault
答案 0 :(得分:1)
作为一种解决方法,您可以在PayloadFactory介体中使用完整的SOAP信封来克服此错误
E.g
<payloadFactory media-type="xml">
<format>
<Envelope>
<Body>
<response>
<error>$1</error>
</response>
</Body>
</Envelope>
</format>
<args>
<arg xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" evaulator="xml" expression="//soapenv:Fault/faultstring"/>
</args>