WSO2 ESB: how to carry a SOAP answer into a file (or DB) using a scheduled task - web-services

I deploy a proxy service in WSO2 ESB that asks a web service for a dataset by a SOAP request and the web service correctly returns the requested dataset. In order to have evidence of the right answer of the web service, how can I do to store this dataset into a generic file during a regular scheduling in a task?

In your proxy def, you can find :
a inSequence executed when a request is sent to this proxy,
a outSequence that receive a response if you send a request from your inSequence (with send mediator)
a faultSequence executed if an error occurs.
So, if you "asks a web service for a dataset" from your inSequence using send mediator, your outSequence receive the response (your "dataset") and you just have to send it to a file :
<!-- name of the file -->
<property name="transport.vfs.ReplyFileName" value="dataset.xml" scope="transport"/>
<!-- OUT_ONLY because we want to use send mediator but don't want a callback waiting for a response -->
<property name="OUT_ONLY" value="true" />
<!-- Send current message (the response from your webService) to the filesystem : test directory must exist on c:\ -->
<send>
<endpoint>
<address uri="vfs:file:///C:/test"/>
</endpoint>
</send>
--> don't forget to activate VFS sender in repository/conf/axis2/axis2.xml : uncomment <transportSender name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportSender"/>

Related

SMS is not received to mobile in SMPP Connector - WSO2 EI 6.5.0

I am using WSO2 SMPP Connector to send SMS to mobile number in WSO2 EI 6.5.0
Pre-requisites:
Setup done by using the same steps mentioned here
I just placed jsmpp-2.1.0-RELEASE.jar into <PRODUCT_HOME>/lib
logica-smpp-sim simulator set up done and it is running with the port 10003 in windows 10
API:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/send" name="SmppTestApi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property expression="json-eval($.distinationAddress)" name="distinationAddress" scope="default" type="STRING"/>
<property expression="json-eval($.message)" name="message" scope="default" type="STRING"/>
<property expression="json-eval($.sourceAddress)" name="sourceAddress" scope="default" type="STRING"/>
<SMPP.init>
<host>localhost</host>
<port>10003</port>
<systemId>justin</systemId>
<password>justin</password>
<systemType>UNKNOWN</systemType>
<addressTon>UNKNOWN</addressTon>
<addressNpi>UNKNOWN</addressNpi>
</SMPP.init>
<SMPP.sendSMS>
<sourceAddress>{$ctx:sourceAddress}</sourceAddress>
<distinationAddress>{$ctx:distinationAddress}</distinationAddress>
<message>{$ctx:message}</message>
</SMPP.sendSMS>
<log level="full">
<property name="Message delivered sucessfully" value="Message delivered sucessfully"/>
</log>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
When I hit API , it is giving proper response as mentioned here
Postman:
Logica-sim log:
03:16:07 [justin] client request: (submit: (pdu: 108 4 0 3) (addr: 0 0 16111) (addr: 0 0 919047878787) (sm: msg: Hi! This is the first test SMS message.) (opt: ) )
03:16:07 [justin] putting message into message store
03:16:07 [justin] server response: (submit_resp: (pdu: 0 80000004 0 3) Smsc2002 )
WSO2 EI Log:
[2022-10-18 15:16:07,349] [] INFO - LogMediator To: /send, MessageID: urn:uuid:052d3fb7-1762-4323-bea1-5302ddc93d36 correlation_id : e5990fb5-fd97-45d2-b971-878d2471d9e5, Direction: request, Message delivered sucessfully = Message delivered sucessfully, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:messageId xmlns:ns="http://org.wso2.esbconnectors.smppConnector">Smsc2002</ns:messageId></soapenv:Body></soapenv:Envelope>
Note: I passed valid Indian Mobile number in the input request field (ie "distinationAddress")
I think SMS is stored in SMSC, But SMPP inbound endpoint will consume SMS from SMSC and send that to WSO2 EI Sequence.
I just want to understand in which stage SMS will send to corresponding mobile number which we passed in API Request.
Even though Received proper response SMS is not received to mentioned mobile.
Do I need to make any other configuration in API SMPP init level to send SMS? Kindly clarify on this.
The document you pointed out has this.
For testing purposes, it is not practical always to connect with a
real SMSC. SMSC Simulator is an application that can act like an SMSC.
Using a simulator we can test our scenario without having access to a
real SMSC. For the real production servers we have to use a real SMSC.
In this example scenario we will be using logica-smpp-sim simulator.
According to the above logica-smpp-sim is just a simulator, which is used to mimic an actual SMSC for testing. So I don't think it would send SMSs. You may have to connect to a real/production grade SMSC/SMPP Provider or an SMS Gateway if you want to send SMS. You can read more about the SMPP protocol and available Gateways from here.

WSO2 ESB: Can we use Call Mediator for Rest Service to post (POST HTTP Method) the xml request?

When I create proxy with send mediator with Rest service Post HTTP Method in HTTP endpoint url. Selected the endpoint as HTTP endpoint on proxy and post the request xml without soap envelop, this perfectly works and get the response in the response window.
But when I use the call mediator with the same HTTP end point url configuration, this does not works. I would like to know can we use call mediator for Post HTTP method? When I use Call mediator for the GET HTTP method which require only query parameters and does not require any request xml this works absolutely fine.
Here is the further information:
However issue is resloved by using the address endpoint in callmediator. When I Invoke the proxy from external Restt client ot Soap UI, it does works. If I use the Try this Service option in wso2 ESB will fail with the results 1. When Soap12 endpoint is selected and 2 when HTTP end point is selected as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="postIDMPCall"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<organizationList xmlns="">
<xml content>
</organizationList>
</format>
<args/>
</payloadFactory>
<header name="_user" scope="transport" value="username"/>
<header name="_password" scope="transport" value="Password"/>
<call blocking="true">
<endpoint>
<address uri="http://<ip-address>:<port>/<resource-path>/UpdateOrganization"
format="rest"/>
</endpoint>
</call>
</inSequence>
</target>
</proxy>
Output: When soap12 endpoint is selected
Though posted the correct xml service does not recorgonize the correct xml format for soap12 endpoint.
FAILURE
Record is not processed successfully. Please Provide valid Request XML
When Http end point is selected
[2016-04-21 12:07:50,179] INFO - HTTPSender Unable to sendViaPost to url[http://://UpdateOrganization/mediate]
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
I think we can't use call mediator for this purpose because call mediator is context unaware mediator.
Your call should already perform a post out the box.
Did you try to set format="pox" if you expect simple xml as a response

How to handle Endpoint warnings in wso2esb

I am using wso2 esb 4.8.1,
I wish to handle warning of endpoints.I am trying to hit CXF services in tomcat server.
If I test with wrong action (Operation/method)name or service name in tomcat.
I am getting this message in SOAP.
<html>
<body>No service was found.</body>
</html>
Where as in my wso2esb not getting logged any error and that particular endpoint failing showing this message.
[2014-11-24 16:57:57,931] WARN - LoadbalanceEndpoint Endpoint [ServiceLEP] Detect a Failure in a child endpoint : Endpoint [EP3]
Since I don't know the CXF I wish to handle this in wso2esb How would I handle this message and send proper error response to client.
Is any one able to help me.
Thanks in advance.
If you are using a mediator, the response will be available in the inSequence. You can log that response with code such as this after your mediator:
<enrich>
<source type="body"/>
<target type="property" action="child" property="response_body"/>
</enrich>
<log level="custom">
<property name="The Response" expression="get-property('response_body')"/>
</log>
Please advise if that works in your scenario.
If your endpoint is suspended, then WSO2 by default initiate fault sequence, you can define your custom message in the fault sequence and then send it back to the client as you want. You can get ERROR_CODE and ERROR_MESSAGE property from WSO2 in Log or Switch mediator where u can check it. In log u can do it as following:
<log level="full" separator="**********Fault Sequence File Processor***********">
<property name="ErrorCode" expression="get-property('ERROR_CODE')"></property>
<property name="ErrorMessage" expression="get-property('ERROR_MESSAGE')"></property>
<property name="ErrorDetail" expression="get-property('ERROR_DETAIL')"></property>
<property name="ErrrorException" expression="get-property('ERROR_EXCEPTION')"></property>
</log>
You can make a check on ERROR_CODE property or ERROR_MESSAGE property in Switch mediator and then with the help of Payload mediator u can define your custom error message.

WSO2 ESB - How to send response to Intermediate sequence from service provider?

i was going through a video about "Webinar - ESB - An answer to Enterprise Service Integration" by WSO2 ESB . i have a doubt regarding the video .
it is said in the video that , always in sequence will receive the request and out sequence will return the response from the service provider . An ESb can have multiple intermediate sequence and we can, set to which intermediate sequence service provider has to send the response .
How is it possible when we do not have any control over the service provider ? are we using some queue in between ESB and service provider to accomplish ?
Inside a sequence, when you send a request to a service, you can choose the response-handling sequence (service chaining) :
<send receive="personInfoSeq">
<endpoint key="PersonInfoEpr"/>
</send>
When the ESB sends the request, a callback is instanciated (a dedicated thread) which will wait for the reply and then execute the 'receive' sequence configured in the 'send' mediator
Inside a sequence, when you are working with a response message, you can change it to a request message (<property name="RESPONSE" value="false"/>) and send it to another service
Inside a "in" sequence (when you are working with a request message), you can generate a response, sample :
<inSequence>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<payloadFactory>
<format>
<ns:getQuoteResponse xmlns:ns="http://services.samples">
<ns:return xmlns:ax21="http://services.samples/xsd">
<ax21:change>4.212070096051944</ax21:change>
<ax21:earnings>-9.567415587431361</ax21:earnings>
<ax21:high>-148.1740146577308</ax21:high>
<ax21:symbol>IBM</ax21:symbol>
</ns:return>
</ns:getQuoteResponse>
</format>
</payloadFactory>
<send/>
</inSequence>

WSO2 ESB message id

Do I have any possibility to find message on WSO2 ESB by MessageId, like urn:uuid:e11893c5-b033-4e99-9473-a43d66b65fbb ? For example if some flow failed and server logged such ID.
Maryan,
ESB itself doesn't log messages anywhere until you tell it to.
a) The first approach is to write incoming and outgoing messages into the log using log mediator:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="YourProxyService" transports="https http" startOnLoad="true">
<target>
<inSequence>
<log level="full">
<property name="MESSAGE_ID" expression="get-property('MessageID')"/>
</log>
...
</inSequence>
<outSequence>
<log level="full">
<property name="MESSAGE_ID" expression="get-property('MessageID')"/>
</log>
...
</outSequence>
</target>
</proxy>
Then you'll be able to find your incoming and outgoing messages in log files as the logs would contains something like following:
INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: http://localhost:9763/services/YourProxyService, From: 127.0.0.1, WSAction: urn:mediate, SOAPAction: urn:mediate, Direction: request, MESSAGE_ID = urn:uuid:e11893c5-b033-4e99-9473-a43d66b65fbb , Envelope: <ENVELOPE_GOES_HERE>
b) Another approach would be to create table in the database and store message id and envelope to it.
Hope this helps.
Vladimir.
UPD: You can also use built in SOAP tracer, but enable it with caution - it hits ESB performance. So I suggest use it only for short term debugging activities.
Yes, you can get the message ID using property mediator,
<property name="MessageID" expression="get-property('MessageID')"/>
As others pointed out, you can use log statements in WSO2 ESB to log the messages and search and find later.
But it becomes complex when the message flow fails at some point, as the message IDs will be different across different message flows.
A simple approach would be to read the incoming messagID and use it till the final response message.
Have a look here for detailed explanation.