WSO2 File download over HTTP and save it to folder - wso2

How to create Proxy Service which is capable to download XML file from specific address and save it to the Folder?
I tried below answer : But it is not working VFS throws error :
<call>
<endpoint>
<address format="soap11"
uri="https://scsanctions.un.org/resources/xml/en/consolidated.xml"/>
</endpoint>
</call>
<property expression="fn:concat('consolidated-', get-property('SYSTEM_DATE', 'yyyy-MM-dd'),'.xml')"
name="transport.vfs.ReplyFileName"
scope="transport"/>
<log level="custom">
<property name="Step 1" value="---------Writing response to file ---------"/>
</log>
<property name="FORCE_SC_ACCEPTED"
scope="axis2"
type="STRING"
value="true"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<call>
<endpoint>
<address uri="vfs:file://C:/output"/>
</endpoint>
</call>
<log level="custom">
<property name="Step 2" value="---------Service is called ---------"/>
</log>
<property expression="fn:concat('treasury-',get-property('SYSTEM_DATE', 'yyyy-MM-dd'), '.xml' )"
name="transport.vfs.ReplyFileName"
scope="transport"/>
<log level="custom">
<property name="Step 2"
value="---------sending request to treasure site ---------"/>
</log>
<call>
<endpoint>
<address format="soap11" uri="https://www.treasury.gov/ofac/downloads/sdn.xml"/>
</endpoint>
</call>
<log level="custom">
<property name="Step 2" value="---------Writing response to file ---------"/>
</log>
<property name="FORCE_SC_ACCEPTED"
scope="axis2"
type="STRING"
value="true"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<call>
<endpoint>
<address uri="vfs:file://C:/output"/>
</endpoint>
</call>
enter code here
WSO2 ESB: How to download a file over HTTP?
Im trying to calling multiple endpoint to receive response which is supposed to be saved in this folder file://C:/output
Regards

Related

AnonymousEndpoint with address {uri.var.apiurl} in WSO2 EI 6.6

I tired to send the request to an endpoint I get the AnonymousEndpoint error and when I hit the endpoint URL with request in the postman it's working fine what should I do to fix this issue.
And I even tired the markForSuspension and suspendOnFailure configuration nothing worked as excepted.
<property name="singleQuote" scope="default" type="STRING" value="'"/>
<property description="AppConfig" expression="evaluate(fn:concat('get-property(',get-property('singleQuote'),'QRSag_iAppraisal_Config_',get-property('clientOrg'),get-property('singleQuote'),')' ))" name="AppConfig" scope="default" type="OM"/>
<property expression="$ctx:AppConfig//*[local-name()='laravel_url']/text()" name="uri.var.apiurl" scope="default" type="STRING"/>
<property expression="$ctx:AppConfig//*[local-name()='authorization']/text()" name="Authorization" scope="transport" type="STRING"/>
<!--
<log level="custom">
<property name="uri.var.apiurl ::::::::::::::::::: " expression="$ctx:uri.var.apiurl"/>
<property name="Authorization ::::::::::::::::::: " expression="$trp:Authorization"/>
</log> -->
<call description="VB iAppraisal Endpoint">
<endpoint>
<http method="post" uri-template="{uri.var.apiurl}"/>
</endpoint>
</call>
<!-- <log level="custom">
<property name="Laravel API Response ::::::::::::::::::: " expression="json-eval($.)"/>
</log> -->

WSO2 EI 6.1.1 post request body not send

I have a problem with wso2 EI 6.1.1. I tried using call mediator to post data to an endpoint, where the data is created via class I've created.
The issue is that the body seems to be always empty. The resulted object from the class is not sent as the body.
<resource methods="POST" url-mapping="/itineraries">
<inSequence>
<property description="baseUrl" expression="get-property('boBaseUrl')" name="uri.var.boBaseUrl" scope="default" type="STRING"/>
<property description="InsiteoClientId" expression="get-property('InsiteoClientID')" name="clientID" scope="default" type="STRING"/>
<property description="appVersion" expression="$trp:X-app-version" name="appVersion" scope="default" type="STRING"/>
<property description="buildingId" expression="$trp:X-current-building-id" name="uri.var.buildingId" scope="default" type="STRING"/>
<property description="wayPoints" expression="json-eval($.)" name="wayPoints" scope="default" type="STRING"/>
<call>
<endpoint>
<http method="get" uri-template="{uri.var.boBaseUrl}/api/v1/buildings/{uri.var.buildingId}"/>
</endpoint>
</call>
<property description="floors" expression="json-eval($.floors)" name="floors" scope="default" type="STRING"/>
<property description="InsiteoSiteId" expression="json-eval($.information.insiteoIDSite)" name="uri.var.insiteoSiteId" scope="default" type="STRING"/>
<class description="ItineraryClass" name="com.capgemini.smartWorkPlace.Itinerary"/>
<log level="full"/>
<header expression="get-property('InsiteoApiKey')" name="Authorization" scope="transport"/>
<call>
<endpoint>
<http method="post" uri-template="http://services.test.insiteo.com/APIV3/{uri.var.insiteoSiteId}/iti/process"/>
</endpoint>
</call>
<log level="full"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
The request status code returns 500 as if no body was ever sent.
I would really appreciate some help.
In your class mediator check if you're setting the created payload to the context body. If its json,
JsonUtil.getNewJsonPayload(axis2MessageContext, jsonPayload.toString(), true, true);

Sending to dynamic address endpoint

How can one send an email to a dynamic address?
Address endpoint's URI seem to be static.
Is there a way to inject a property in a address endpoint ?
Here is what I have so far :
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="sendMail" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="//email" name="email" scope="default" type="STRING"/>
<log level="custom">
<property expression="fn:concat('Sending mail to - ',get-property('mail'))" name="mail"/>
</log>
<property name="messageType" value="text/html" scope="axis2"/>
<property name="ContentType" value="text/html" scope="axis2"/>
<property name="Subject" value="File Received" scope="transport"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint name="mail2user">
<address uri="mailto:username#gmail.com"/>
</endpoint>
</send>
</sequence>
Thanks.
Define header "To" and use send without endpoint :
<header name="To"expression="fn:concat('mailto:', get-property('senderAddress'))"/>
<property name="OUT_ONLY" value="true"/>
<send/>
Don't forget to define transportSender "mailto" with class "org.apache.axis2.transport.mail.MailTransportSender" in axis2.xml
Here is the final code after jean-michel suggestion :
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="sendMail" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="//email" name="mailto" scope="default" type="STRING"/>
<log level="custom">
<property expression="fn:concat('Sending mail to - ',get-property('mailto'))" name="mail"/>
</log>
<property name="messageType" scope="axis2" type="STRING" value="text/html"/>
<property name="ContentType" scope="axis2" type="STRING" value="text/html"/>
<property name="Subject" scope="transport" type="STRING" value="File Received"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<header expression="fn:concat('mailto:', get-property('mailto'))" name="To" scope="default"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<send/>
</sequence>

Add query params dynamically at endpoint API WSO2 ESB

I'm trying to edit an api resource in WSO2 ESB to put query params dinamically in the end of endpoint URL.
At this moment, the resource is like this:
<resource methods="GET" uri-template="/searchEngine/sortAndFilterBeneficiaries*">
<inSequence>
<log level="custom">
<property name="Access token value" expression="$trp:Authorization"/>
</log>
<oauthService remoteServiceUrl="https://server:port/services/" username="admin#wso2.com" password="admin"/>
<header name="Authorization" scope="transport" action="remove"/>
<send>
<endpoint>
<http method="get"
uri-template="http://server:port/project-web-services/services/project-rs/searchEngine/sortAndFilterBeneficiaries?criterioOrdenacion={query.param.criterioOrdenacion}&registrosPorPagina={query.param.registrosPorPagina}&numPagina={query.param.numPagina}&userId={query.param.userId}&serviciosSeleccionados={query.param.serviciosSeleccionados}&fechaRequerida={query.param.fechaRequerida}&limiteInfDias={query.param.limiteInfDias}&limiteSupDias={query.param.limiteSupDias}&ubicacion={query.param.ubicacion}&limiteDistancia={query.param.limiteDistancia}&valoraciones={query.param.valoraciones}&competencias={query.param.competencias}"/>
</endpoint>
</send>
</inSequence>
But, I'm doing this:
<resource methods="GET" url-mapping="/searchEngine/sortAndFilterBeneficiaries*">
<inSequence>
<filter source="$ctx:query.param.criterioOrdenacion" regex="PRODUCTION">
<then>
<property name="REST_URL_POSTFIX" expression="fn:concat(get-property('axis2','REST_URL_POSTFIX'), '&criterioOrdenacion={query.param.type}')" scope="axis2" type="STRING"/>
</then>
</filter>
<log level="custom">
<property name="Access token value" expression="$trp:Authorization"/>
</log>
<oauthService remoteServiceUrl="https://server:port/services/" username="admin#wso2.com" password="admin"/>
<header name="Authorization" scope="transport" action="remove"/>
<send>
<endpoint>
<http method="get"
uri-template="http://server:port/project-web-services/services/project-rs"/>
</endpoint>
</send>
</inSequence>
Is this correct?
This is correct. When you want to change base path only one endpoint will be affected, but in first case you must update all dynamic endpoint.

How can I retrieve HTTP status returned by REST service in WSO2 ESB?

My Proxy Service deployed on ESB is calling another standalone REST service. This service returns HTTP status 200 along with some data in the response body. My question is how I can retrieve HTTP status from response. Here is my configuration:
<proxy name="CQProxy"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<switch source="get-property('Action')">
<case regex="getTaskTicket">
<sequence key="GetTaskTicket"/>
</case>
<default/>
</switch>
</inSequence>
<outSequence>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Status"
expression="get-property('HTTP_SC')"/>
</log>
<send/>
</outSequence>
<faultSequence/>
</target>
<publishWSDL key="gov:/services/cqproxy/CQProxy.wsdl">
<resource location="CQProxy.xsd" key="gov:/services/cqproxy/CQProxy.xsd"/>
</publishWSDL>
</proxy>
<sequence name="GetTaskTicket">
...
<property name="REST_URL_POSTFIX"
value="/16783484?oslc.select=dcterms:title,oslc_cm:status"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="http://.../simpleQuery"
format="rest"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
</sequence>
...
I tried the following code:
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('HTTP_SC')"/>
</log>
And this one too:
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('axis2', 'HTTP_SC')"/>
</log>
But all of them returned null.
After reading WSO2 documentation in more details, I found the right answer:
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="$axis2:HTTP_SC"/>
It is weird that the documented get-property('axis2', 'HTTP_SC') does not work.
Posting the solution that worked for me:
<property scope="default" type="STRING" name="HTTP_STATUS_CODE" expression="get-property('axis2', 'HTTP_SC')"/>
<log level="custom">
<property expression="get-property('HTTP_STATUS_CODE')" name="HTTP status code received: "/>
</log>