Problem with OutSequence after using <call> - wso2

I'm building a proxy that receives a Base64 stream, saves it to disk and then reads it back to send it as binary to an URL endpoint. Then it has to respond back to the initial message processing the URL endpoint's response.
The resumed proxy looks like this:
<inSequence>
[...]
<payloadFactory>
[...]
</payloadFactory>
[...]
<call>
<endpoint>
<address uri="vfs:file:///somewhere"/>
</endpoint>
</call>
<fileconnector.read>
<source>/somewhere</source>
<contentType>application/pdf</contentType>
</fileconnector.read>
[...]
<send>
<endpoint>
<http method="POST"
uri-template="someURL"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<payloadFactory>
[...]
</payloadFactory>
<send/>
</outSequence>
Everithing works fine but the response from the URL is never processed and the OutSequence never reached (I've set up logs inside to trace it).
What am I doing wrong?

Related

WSO2: Avoid hard-coding URI ports in Address Endpoint

I have configured an offset of '10' to my ESB server on the carbon.xml file. Now all deployed API's are pointing to the port 8290.
In my API I am calling another API via an Http Endpoint. I am setting the URI template manually to: http://localhost:8290/paramAPI, as follows:
<send>
<endpoint>
<http method="get" uri-template="http://localhost:8290/paramAPI"/>
</endpoint>
</send>
However I also want to deploy to other server instances. For example, I would like to deploy to a server with an offset of '20', and therefore the '/paramAPI' would no longer be reachable at port '8290', instead on '8300'.
In this case, the Http endpoint inside the send mediator must become:
<send>
<endpoint>
<http method="get" uri-template="http://localhost:8300/paramAPI"/>
</endpoint>
</send>
I am searching for a method to parameterize the port value.
I have tried to use local entries by defining a string variable on the server by the name APIPort. When referencing it, I modified the HTTP endpoint as follows:
<send>
<endpoint>
<http method="get" uri-template="http://localhost:{APIPort}/paramAPI"/>
</endpoint>
</send>
but I got: java.net.MalformedURLException: For input string: "{APIPort}"
What is the best approach to parameterize URI's? if local entries are used then what is the proper way to use them as parameters and reference them in the URI?
Much appreciated and kind regards,
if I recall correctly you should use uri.var for your uri-template properties. Try to name your property uri.var.APIPort instead.
To be sure I created a simple API , see the following example:
<api xmlns="http://ws.apache.org/ns/synapse" name="testapi" context="/test" version="1" version-type="context">
<resource methods="POST GET">
<inSequence>
<property name="uri.var.version" value="v2"/>
<send>
<endpoint>
<http uri-template="http://mocky.io/{uri.var.version}/5d1dec2a3000006a00d7239d"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
</api>

How to add query params to URL in API in WSO2 ESB

I need to append query params to endpoint URI according to query params in request.
I have an resource API in ESB published like this:
<resource methods="GET" url-mapping="/searchEngine/sortAndFilterVolunteers*">
<inSequence>
<send>
<endpoint>
<address
uri="http://localhost:8080/project-web-services/services/project-rs"></address>
</endpoint>
</send>
</inSequence>
I have to append query params dinamically.
How could I do that?
Following sample API definition may help you.
<api xmlns="http://ws.apache.org/ns/synapse" name="sample" context="/api/sample">
<resource methods="OPTIONS GET" uri-template="/{val1}/groups/{val2}.json?q1={v1}&q2={v2}">
<inSequence>
<property name="uri.var.q1" expression="$url:q1"></property>
<property name="uri.var.q2" expression="$url:q2"></property>
<property name="uri.var.val1" expression="get-property('uri.var.val1')"></property>
<property name="uri.var.val2" expression="get-property('uri.var.val2')"></property>
<send>
<endpoint>
<http method="GET" uri-template=""></http>
</endpoint>
</send>
</inSequence>
<outSequence>
<send></send>
</outSequence>
</resource>
</api>
Add the query parameter to uri-template in resource as below :
<resource methods="GET" uri-template="/getStudents/{id}">
When sending to the endpoint,
<send>
<endpoint>
<http method="get" uri-template="http://studentsapi/student/{uri.var.id}"/>
</endpoint>
</send>
Add the query parameter to url-mapping in resource as below : url-mapping="/*"
*
you can send a request may be server:port/service?q1={q1} and other request may be server:port/service?q2={q2}&q3={q3}.

Adding parameters to the endpoint url wso2 esb

I am new to the WSO2 esb. I want to create a api in which i want to add a dynamic parameter from api Url to endpoint url.
My end point url is like http://example.com/api/sync/{session_id}.json
I tried to create api like
<api name="rest" context="/sync">
<resource methods="GET" uri-template="/{id}">
<inSequence>
<log level="full">
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="get-property('uri.var.id')"
scope="axis2"/>
</log>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<send>
<endpoint name="Mecars">
<http trace="enable"
method="get"
uri-template="http://example.com/sync/{+uri.var.session}.json"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
In log i get the value of uri.var.session But on the endpoint Uri-template it is not appending.
Please guid me how append the {id} value in the api uri-template to end point uri-template?
Check this sample
I recommend you to do string concatenation at property mediator adn use that directly at uri-template, rather adding "variable +.json" at uri-template.
That is;
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="get-property('uri.var.id')"
scope="axis2"/>
In the above for expression do string concatenation to construct full variable with ".json" ending.
Please remove the '+' symbol from your http end point.Its working fine to me
sample API
<api xmlns="http://ws.apache.org/ns/synapse" name="Elastic Search Using NPI" context="/api/npi/professional/npi.json">
<resource methods="OPTIONS GET" uri-template="/{npi}">
<inSequence>
<log level="full">
<property name="uri.var.npi" expression="get-property('uri.var.npi')"></property>
</log>
<send>
<endpoint>
<http method="get" uri-template="example.com/{uri.var.npi}"></http>
</endpoint>
</send>
</inSequence>
</resource>
</api>
Change the http endpoint uri template like follows.
<http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>
Following is the modified api configuration.
<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/sync">
<resource methods="GET" uri-template="/{id}">
<inSequence>
<log level="full">
<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.session" expression="get-property('uri.var.id')"></property>
</log>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
<send>
<endpoint name="Mecars">
<http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>
</endpoint>
</send>
</inSequence>
</resource>
</api>
You can do the string concatenation at the property mediator as follows.
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="fn:concat(get-property('uri.var.id'),'.json')"
scope="axis2"/>

adding post request in my WSO2 proxy service

I have created a proxy service who transform a message using a xslt mediator and then transformed to JSON,
I want now to post the JSON message in a rest web service how i can do that directely in my proxy service?
This is my proxy service :
<proxy xmlns="http://ws.apache.org/ns/synapse" name="CategoryProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="Authorization" expression="fn:concat('Basic ', base64Encode('admin:admin'))" scope="transport" type="STRING"/>
<send>
<endpoint>
<address uri="http://localhost:8068/database/library.author/301"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<xslt key="conf:/ressources/catXsl.xsl"/>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<send/>
</outSequence>
<faultSequence/>
</target>
<description></description>
</proxy>
I want the message sent by this proxy to be post in a rest web ressource, How I can do it in my proxy?
Looks like you are looking for service chaining and you can do that in two ways:
1) Using a receiving sequence
<inSequence>
<property name="Authorization" expression="fn:concat('Basic ', base64Encode('admin:admin'))" scope="transport" type="STRING"/>
<send receive="receivingSeqForChaining">
<endpoint>
<address uri="http://localhost:8068/database/library.author/301"/>
</endpoint>
</send>
</inSequence>
You can define whatever sequence of operations you want in that receiving sequence. Output from this will be handed out to receiving sequence. If you don't want to do any specific action in outSequence for this case you can just add a to that.
2) Using outSequence to trigger other service call
You can also make that http call directly from outSequence something like this:
<outSequence>
<send>
<endpoint>
<http method="get"
uri-template="https://www.abc.com/resource/foo"/>
</endpoint>
</send>
</outSequence>
Hope this helps.

how we can store a data or string in txt file in wso2 esb

my issue is i am getting data or json or string from front end or mobile app which contains details of error i need append the all details in single txt file in my local system
how can i do this we have any mediator for this or may i use vfs trnsport let me knoe i tried with this code giving error
My config is:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="FileWrite" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<log level="custom">
<property name="sequence" value="fileWriteSequence"/>
</log>
<log>
<property name="transport.vfs.ReplyFileName" expression="fn:substring-after(get-property('MessageID'), 'urn:uuid:')"/>
<property name="OUT_ONLY" value="true"/>
</log>
<send>
<endpoint>
<address uri="///home/youtility2/Desktop/Errorlog"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<description></description>
</proxy>
Error throing from esb side
2013-04-01 15:58:04,707] ERROR - ClientUtils The system cannot infer the transport information from the ///home/youtility2/Desktop/Errorlog URL.
[2013-04-01 15:58:04,708] ERROR - Axis2Sender Unexpected error during sending message out
org.apache.axis2.AxisFault: The system cannot infer the transport information from the ///home/youtility2/Desktop/Errorlog URL.
at org.apache.axis2.description.ClientUtils.inferOutTransport(ClientUtils.java:81
) have any refernace let me know.
You need to append the "transport.vfs.Append=true" to out-file URI to append the data in to the existing file... There is a thread regarding this in stackoverflow see the [1]. For more details regarding the VFS please refer the [2].
[1] How to append response message to a text file?
[2] http://docs.wso2.org/wiki/display/ESB403/VFS+Transport
Regards,
Mohan
Sequence Defined inside Log mediator.Define like below
<inSequence>
<log level="full"/>
<property name="sequence" value="fileWriteSequence"/>
<property name="transport.vfs.ReplyFileName" expression="fn:substring-after(get-property('MessageID'), 'urn:uuid:')"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint>
<address uri="///home/youtility2/Desktop/Errorlog"/>
</endpoint>
</send>
</inSequence>