How to Capture web service output in Developer Studio - wso2

We have a web service which is creating a record in a database table and gives response/output as "SUCCESS" after successful insertion in SOAP UI
We have developed a Project in Developer Studio and called this webservice using AddressEndPoint, and deployed CAR file on ESB Server
The webservice is calling successfully via ESB and records are inserting in the tables but we are unable to log "SUCCESS" status anywhere we tried to use log mediator after CALL(AddressEndPoint) Mediator but it is not logging webservice response.
Below is my Source:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="EslSfaOFAOMSOIntegrationPS"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<call>
<endpoint>
<address format="soap11"
uri="http://10.1.6.175:9763/services/EslSfaOMSODataService.SOAP11Endpoint/"/>
</endpoint>
</call>
<log level="full"/>
<datamapper config="gov:datamapper/EslSfaOFAOMSOIntegrationMapping.dmc"
inputSchema="gov:datamapper/EslSfaOFAOMSOIntegrationMapping_inputSchema.json"
inputType="XML"
outputSchema="gov:datamapper/EslSfaOFAOMSOIntegrationMapping_outputSchema.json"
outputType="XML"/>
<log description="" level="full"/>
<header name="Authorization"
scope="transport"
value="Basic cHdjLmV0aXNhbGF0OkZlcmd1c29uMTIz"/>
<log level="full"/>
<call>
<endpoint>
<address format="soap11"
uri="https://eere-test.scm.ap1.oraclecloud.com:443/soa-infra/services/default/DooDecompReceiveOrderExternalComposite/ReceiveOrderRequestService"/>
</endpoint>
</call>
<enrich>
<source clone="true" type="body"/>
<target property="ReceiveOrderServiceResponseMessage" type="property"/>
</enrich>
<log level="custom">
<property expression="get-property('ReceiveOrderServiceResponseMessage')"
name="moidSiddiqui"/>
</log>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
<description/>
</proxy>

I use this property after my call mediator to get the status
<log>
property xmlns:ns="http://org.apache.synapse/xsd" name="Status"
expression="get property('axis2','HTTP_SC')"/>
</log>
You can find more information here
https://docs.wso2.com/display/ESB460/HTTP+Transport+Properties
To obtain the response of the service I use
<enrich>
<source clone="true" type="body"/>
<target property="Ouput_Respose_Service" type="property"/>
</enrich>
<log level="custom" separator=",">
<property expression="get-property('Ouput_Respose_Service')" name="Service_Response"/>
</log>

Related

Can I invoke a web service using call mediator in wso2 esb?

<?xml version="1.0" encoding="UTF-8"?>
<sequence name=SEQUENCE trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<iterate expression=EXPRESSION sequential="true" xmlns:ns="http://org.apache.synapse/xsd">
<target>
<sequence>
<log level="full">
<property expression="$body/*" name="Test within iterate"/>
</log>
<call>
<endpoint>
<http method="POST" uri-template=URI TEMPLATE
</endpoint>
</call>
<log>
<property name="After CALL" value="response"/>
</log>
</sequence>
</target>
</iterate>
<aggregate>
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete expression="$body/*" sequence="OutSequenceforData"
xmlns:ns="http://org.apache.synapse/xsd"
xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s12="http://www.w3.org/2003/05/soap-envelope"/>
</aggregate>
<send/>
<log level="full">
<property expression="$body/*" name="After Aggregate" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
</sequence>
I am trying to invoke a web service using call mediator. But I do not see any log about the call in the wso2 logs. The goal is to display the data from a file in the web service.
Yes you can, after the Call mediator put a Log mediator.
<log level="full" xmlns="http://ws.apache.org/ns/synapse"/>

Unable to return in out sequence while using clone mediator in ESB WSO2

I have taken an example from DZONE blog for the clone mediator but looks like I am making some mistake and unable to return in outsequece to process further.
Can anyone help in this?
<proxy name="DSS_TrainDetailsProxy" transports="http" startOnLoad="true" trace="disable" statistics="enable">
<target inSequence="DSS_TrainDetails_IN" outSequence="DSS_TrainDetails_OUT" faultSequence="CommonFaultHandler"/>
<publishWSDL key="DSS_TrainDetails_wsdl"/>
</proxy>
<localEntry key="DSS_TrainDetails_wsdl" src="file:repository/conf/train/wsdl/TrainDetails.wsdl"/>
<sequence name="DSS_TrainDetails_IN">
<clone>
<target>
<send>
<endpoint key="DSS_TrainDetails_EPR"/>
</send>
</target>
<target>
<send>
<endpoint key="DSS_TrainDetails_EPR"/>
</send>
</target>
<target>
<send>
<endpoint key="DSS_TrainDetails_EPR"/>
</send>
</target>
</clone>
<sequence name="DSS_TrainDetails_OUT">
<aggregate>
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete xmlns:tra="traindetails.co.nz" expression="//tra:TrainDetails">
<log level="custom" separator=",">
<property name="MessageFlow" value="======================= Sending Back the Aggregated Responses. ==============="/>
</log>
<log level="full" separator=","/>
<enrich>
<source xmlns:tra="traindetails.co.nz" clone="true" xpath="//tra:TrainDetails/tra:TrainsDetails"/>
<target type="body" action="child"/>
</enrich>
<send/>
</onComplete>
</aggregate>
</sequence>
Hi just wanted to let you know that Clone mediator worked for me :) I have made changes in IN sequence by below code I have removed "send" keyword from IN sequence :
<sequence name="DSS_TrainDetails_IN">
<clone>
<target>
<endpoint key="DSS_TrainDetails_EPR"/>
</target>
<target>
<endpoint key="DSS_TrainDetails_EPR1"/>
</target>
<target>
<endpoint key="DSS_TrainDetails_EPR2"/>
</target>
</clone>
Try that : remove your outSequence="DSS_TrainDetails_OUT" in your proxy def and inside your clone targets, change <send> to <send receive="DSS_TrainDetails_OUT">

Different behaviors between ESB 4.9.0 and 4.8.1

I have this proxy service in ESB 4.8.1, when I test it with SoapUI 5.2.1. I got this problem:
Does not write the full log in the server console when a timeout rise, but when I change it to custom it works.
Does not return any response to SoapUI (payloadFactory does not work)
When I deploy it in ESB 4.9.0 it works perfectly. Its a bug from the older version? How can I fix it?
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="StockQuoteProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<send>
<endpoint>
<address uri="http://localhost:8089/mockStockQuoteProxySoap11Binding"
format="soap11">
<timeout>
<duration>1000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>101500,101501,101506,101507,101508</errorCodes>
<initialDuration>2000</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>3000</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>101504,101505</errorCodes>
<retriesBeforeSuspension>3</retriesBeforeSuspension>
<retryDelay>1</retryDelay>
</markForSuspension>
</address>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence>
<log level="full">
<property name="FALLO" value="DETALLES DEL ERROR!!"/>
<property name="message" expression="get-property('ERROR_MESSAGE')"/>
<property name="code" expression="get-property('ERROR_CODE')"/>
<property name="detail" expression="get-property('ERROR_DETAIL')"/>
<property name="exception" expression="get-property('ERROR_EXCEPTION')"/>
</log>
<payloadFactory>
<format>
<ns:MyResponse xmlns:ns="http://services.samples">
<ns:Error>Execution Error</ns:Error>
</ns:MyResponse>
</format>
</payloadFactory>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<send/>
</faultSequence>
</target>
<description/>
</proxy>
Thanks in advance.
Try with this fault sequence:
Steps:
Create my response message.
Use the enrich mediator to store the body in property OK.
Create a fault message.
Override the body with the property OK using the enrich mediator.
<payloadFactory>
<format>
<ns:getQuoteResponse xmlns:ns="http://services.samples">
<ns:return xmlns:ax21="http://services.samples/xsd">
<status>ERROR</status>
</ns:return>
</ns:getQuoteResponse>
</format>
</payloadFactory>
<log level="full">
<property name="MESSAGE" value="Mensaje despues del payloadFactory"></property>
</log>
<enrich>
<source clone="true" type="body"></source>
<target action="replace" type="property" property="OK"></target>
</enrich>
<makefault version="soap11">
<code xmlns:soap11Env="schemas.xmlsoap.org/soap/envelope/" value="soap11Env:EdnpointTimeout"/>
<reason value="timeout fault"/>
<role/>
</makefault>
<enrich>
<source type="property" clone="true" property="OK"/>
<target type="body"/>
</enrich>
<log level="full">
<property name="MESSAGE" value="Mensaje despues del enrich"></property>
</log>
<send/>
When I run this proxy this is what I get as the response and the console log. Were you expecting something like this?
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<ns:MyResponse xmlns:ns="http://services.samples">
<ns:Error>Execution Error</ns:Error>
</ns:MyResponse>
</soap:Body>
</soap:Envelope>
INFO - LogMediator To: /services/StockQuoteProxy.StockQuoteProxyHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:44da8426-00fc-442a-b4e9-1a9a1dd948f2, Direction: request, FALLO = DETALLES DEL ERROR!!, message = Error connecting to the back end, code = 101503, detail = Error connecting to the back end, exception = null, Envelope: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body></soap:Body></soap:Envelope>

wso2/synapse service chaining: assign response from SOAP request as intput to another request

My desired sequence is the following:
Read message from queue
Transform
Make an SOAP call
Output SOAP response to another queue
Steps 1,2,3 work fine but when the message sent in Step 4, that I'm intending to contain the SOAP response, is empty. What am I doing wrong?
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="JmsToWsdlJms" transports="https,http,jms" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<enrich>
<source type="body" clone="true"/>
<target type="property" property="jms_body_text"/>
</enrich>
<property name="jms_body_text"
expression="get-property('jms_body_text')"
scope="default"/>
<xslt key="jmsMsgToSoapMsg_xslt">
<property name="jms_text" expression="get-property('jms_body_text')"/>
</xslt>
<log level="full">
<property name="After transformation" value="****"/>
</log>
<send>
<endpoint key="axisStockQuote"/>
</send>
<log level="full">
<property name="After callout" value="****"/>
</log>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint key="jmsQueue2"/>
</send>
</inSequence>
</target>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>text/plain; charset=ISO-8859-1</default>
</rules>
</parameter>
<parameter name="transport.jms.DestinationType">queue</parameter>
<parameter name="transport.jms.Destination">cn=tro_Q_JMS1</parameter>
</proxy>
You can use 'send receive' instead of the send mediator. Something like,
<send receive="jmsQueue2Sequence">
<endpoint key="axisStockQuote"/>
</send>
So that the response of axisStockQuote will be sent to the jmsQueue2Sequence. Refer [1] for more info.
[1] https://docs.wso2.com/display/ESB481/Send+Mediator

wso2 esb - How to handle request in case of mediator returning false

I have custom mediator where we are validating internal authentication system. If authentication fails, mediator return false. Client receiving response as HTTP status code 202. This I want to override with some JSON response like { "authError" : "Authetication failed - TOKEN_INVALID" }. Please let me know how to handle such scenarios.
ESB Version - 4.81.
Here is my proxy configuration -
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="UGCGetJSONFileList"
transports="https,http"
statistics="enable"
trace="disable"
startOnLoad="true">
<target outSequence="WEB_OUT_Sequence">
<inSequence>
<log level="full" separator=","/>
<class name="com.hc.synapse.mediator.HCAuthenticationMediator"/>
<property name="RESPONSE" value="true" scope="axis2"/>
<property name="uri.var.querystrings"
expression="substring-after(get-property('To'), '?')"
scope="axis2"
type="STRING"/>
<log level="full" separator=","/>
<switch source="$axis2:HTTP_METHOD">
<case regex="GET">
<property name="uri.var.querystrings"
expression="substring-after(get-property('To'), '?')"
scope="default"
type="STRING"/>
<log level="full" separator=","/>
<send>
<endpoint>
<http method="get"
uri-template="http://dalx-entsvc-d1:9660/ugc/getJSONFileList?{uri.var.querystrings}"/>
</endpoint>
</send>
</case>
<case regex="POST">
<log level="full" separator=","/>
<send>
<endpoint>
<address uri="http://dalx-entsvc-d1:9660/ugc/getJSONFileList?{uri.var.querystrings};content"
trace="enable"
statistics="enable">
<timeout>
<duration>30000</duration>
<responseAction>discard</responseAction>
</timeout>
<suspendOnFailure>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
</address>
</endpoint>
</send>
</case>
<default/>
</switch>
</inSequence>
<faultSequence>
<log level="full" separator=",">
<property name="trace" expression="get-property('ERROR_MESSAGE')"/>
</log>
<payloadFactory media-type="json">
<format>{ "authError" : "Authetication failed - TOKEN_INVALID" }</format>
<args/>
</payloadFactory>
<property name="RESPONSE" value="true"/>
<header name="To" action="remove"/>
<send/>
</faultSequence>
</target>
<description/>
</proxy>
In your class mediator, you can throw a SynapseException
In this case, inSequence mediation stop and faultSequence will be executed
In the faultSequence, your can use mediator payloadFactory with media-type="json" to build your json message and send it to the client with <send/>