Hi,

The JsonUtil method you are using is used only if a JSON payload comes as a
message Body. If you are not receiving a JSON response from the external
call, you can directly access the SOAPEnvelope from the Message Context
itself with "synCtx.getEnvelope()".

Regards,
Arunan

On Thu, Jul 23, 2020 at 11:31 PM Érico <[email protected]> wrote:

> I have the following API in EI 6.6.0:
> ```
> <?xml version='1.0' encoding='UTF-8'?>
> <api xmlns="http://ws.apache.org/ns/synapse"; name="sample"
> context="/sample">
>    <resource methods="POST">
>       <inSequence>
>          <payloadFactory media-type="xml">
>             <format>
>                <soap:Envelope xmlns:soap="
> http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsd="
> http://www.w3.org/2001/XMLSchema"; xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance";>
>                   <soap:Body>
>                      <P xmlns="http://tempuri.org/";>
>                         <P1>$1</P1>
>                         <P2>$2</P2>
>                         <P3>$3</P3>
>                      </P>
>                   </soap:Body>
>                </soap:Envelope>
>             </format>
>             <args>
>                <arg evaluator="json" expression="$.p1" />
>                <arg evaluator="json" expression="$.p2" />
>                <arg evaluator="json" expression="$.p3" />
>             </args>
>          </payloadFactory>
>          <log level="full" />
>          <property name="Content-Type" value="text/xml;charset=UTF-8"
> scope="axis2"/>
>          <header name="Accept" scope="transport" value="text/xml"/>
>         <call>
>          <endpoint>
>             <wsdl Action="name_of_the_action"
> service="name_of_the_service" port="name_of_soap_port" 
> uri="http://<ip>/path?WSDL"
> />
>          </endpoint>
>         </call>
>
>         <class name="my_mediator_package"></class>
>         <log level="full" />
>         <payloadFactory media-type="xml">
>            <format>
>               <retorno xmlns="">
>                  <msg>$1</msg>
>               </retorno>
>            </format>
>            <args>
>               <arg evaluator="xml"
> expression="get-property('property_set_on_mediator')" />
>            </args>
>         </payloadFactory>
>         <property name="messageType" value="application/xml" scope="axis2"
> type="STRING" />
>         <respond />
>     </inSequence>
>
>     <outSequence>
>       </outSequence>
>
>       <faultSequence>
>          <property name="text" value="An unexpected error occured"/>
>          <property name="message"
> expression="get-property('ERROR_MESSAGE')"/>
>          <payloadFactory media-type="xml">
>             <format>
>                <error xmlns="">
>                   <msg>$1</msg>
>                </error>
>             </format>
>             <args>
>                <arg evaluator="xml"
> expression="get-property('ERROR_MESSAGE')"/>
>             </args>
>          </payloadFactory>
>          <property name="messageType" value="application/json"
> scope="axis2" type="STRING"/>
>          <respond/>
>       </faultSequence>
>    </resource>
> </api>
> ```
>
> my mediate method content:
>
> ```
> public boolean mediate(MessageContext synCtx) {
>         org.apache.axis2.context.MessageContext axis2MessageContext =
> ((Axis2MessageContext) synCtx)
>                 .getAxis2MessageContext();
>         try {
>
>             // Getting the json payload to string
>             String jsonPayloadToString =
> JsonUtil.jsonPayloadToString(((Axis2MessageContext) synCtx)
>                     .getAxis2MessageContext());
>
>             System.out.println("original payload : \n" +
> jsonPayloadToString + "\n");
> ```
>
> I'm not being able to use the return from my SOAP call in my mediator so I
> can work on it.
>
> When I run the API I get the following from my mediator code:
>
> ```
>     original payload:
>     {}
> ```
>
> Is there a way so I can obtain the SOAP call returned envelope and use it
> in my mediator?
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>


-- 
*Sugunakumar Arunan*
Software Engineer | WSO2

Email : [email protected]
Mobile : +94766016272
Web : http://wso2.com
<https://wso2.com/signature>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to