Can we Set a Send mediator with Xpath expression - wso2

i am trying to send a message to my email for that i am using send mediator as well i setup required configurations in AXIS2 file
is it work for below proxy
if not what is the way to give xpath to send mediator
<proxy xmlns="http://ws.apache.org/ns/synapse" name="mailCheck" transports="http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="Subject" value="Alert Message From WSO2 ESB - Service Down !!!" scope="transport" type="STRING"/>
<property name="messageType" value="text/html" scope="axis2" type="STRING"/>
<property name="ContentType" value="text/html" scope="axis2" type="STRING"/>
<property name="Mail" value="mailto:faisal.shaik#youtility.in" scope="default" type="STRING"/>
<log level="full">
<property name="Mail" value="mailto:faisal.shaik#youtility.in"/>
</log>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint key-expression="get-property('Mail')"/>
</send>
</inSequence>
<outSequence/>
</target>
<description></description>
</proxy>
if need any changes pls let me know

if you want to get the email address from a property value then use the header mediator to set value of "To" to "mailto:faisal.shaik#youtility.in".
You can do that adding the following before the send mediator
<header name="To" expression="fn:concat('mailto:', get-property('Mail'))"/>

You can use this:
<property name="To" expression="get-property('uri.var.to')" scope="transport"/>
<send>
<endpoint>
<address uri="mailto:"/>
</endpoint>
</send>

<send>
<address uri="mailto:xxx#yyy"/>
</send>
key-expression also can be used..

Related

WSO2-how to pass two parameters at a time with WSO2 ESB configuration

I have created a API in API manager. I can invoke it with
http://localhost:6547/generatereports/1.0/Reports/dcuid/vcid
I am passing two parameters with "dcuid and vcid" at a time but not passing.
reportsapi:
<?xml version="1.0" encoding="UTF-8"?>
<api context="generatereports/1.0/Reports" name="reportsdataapi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" protocol="http" uri-template="/{dcuid}/{vcid}">
<inSequence>
<property description="http" name="HTTP_SC" scope="axis2" type="STRING" value="404"/>
<log level="full"/>
<send>
<endpoint key="reportsendpoint"/>
</send>
</inSequence>
<outSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
</log>
<send/>
</case>
<default>
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
<send/>
</outSequence>
<faultSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
</log>
</case>
<default>
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
<send/>
</faultSequence>
</resource>
</api>
wso2 configuration process with to send the response is other than 200 response code
reportsendpoint:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="reporsendpoint" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="http://localhost:6547/generatereports/1.0/Reports/{uri.var.dcuid}/{uri.var.vcid}"/>
</endpoint>
I assume you want to send a mail if the status code is other than 200. Then you can use mailto transport or mail connectors such as gmail connector outlook connector and add the configuration in the default section in the configured switch mediator.

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 we receive the url into wso2 esb proxy service

My aim is i have to receive the url's like www.google.com from client in proxy service and send response back to client.
How can i solve this.Here i am sending my proxy service.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Geturl"
transports="https http"
startOnLoad="true"
trace="enable"
statistics="enable">
<description/>
<target>
<inSequence onError="fault">
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="REQUEST_HOST_HEADER" value="www.google.com" scope="axis2"/>
<property name="querystrings"
expression="get-property('axis2', 'REST_URL_POSTFIX')"/>
<property name="REST_URL_POSTFIX"
expression="get-property('REQUEST_HOST_HEADER')"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<header name="To"
expression="get-property('www.google.com')"/>
<property name="message" value="Response message"/>
<property name="Sender Address" expression="get-property('www.google.com')"/>
<log level="full"/>
<log level="full">
<property name="REQUEST_HOST_HEADER" value="www.wso2.org"/>
</log>
<send/>
</inSequence>
<outSequence onError="fault">
<log level="full"/>
<log level="full">
<property name="REQUEST_HOST_HEADER" value="www.google.com"/>
</log>
<log level="full">
<property name="success" value="success"/>
</log>
<send/>
</outSequence>
</target>
</proxy>
Thanks
In the outSequence of a proxy service, when you call <send/> , the response will be sent back to the client. Try sample proxy service [1], and invoke using Try-It or SOAP UI. You will see that the response comming to the client.
[1]http://docs.wso2.org/wiki/display/ESB460/Sample+150%3A+Introduction+to+Proxy+Services

Is it possible with WSO2ESB to send E-Mail Using Header

i wish to send a e-mail to my client using Header mediator .
Is it possible with that or not
My proxy like this
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Mail"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<log/>
<property name="workpartybranchid"
expression="//workpartybranchid/text()"
scope="default"
type="STRING"/>
<payloadFactory>
<format>
<p:SelectMail_Op xmlns:p="http://ws.wso2.org/dataservice">
<p:workpartybranchid>$1</p:workpartybranchid>
</p:SelectMail_Op>
</format>
<args>
<arg expression="get-property('workpartybranchid')"/>
</args>
</payloadFactory>
<send receive="Mailseq">
<endpoint>
<address uri="http://192.168.1.4:9773/services/muser_DataService/"
format="soap11"/>
</endpoint>
</send>
</inSequence>
</target>
</proxy
and corresponding sequence is
<sequence xmlns="http://ws.apache.org/ns/synapse" name="Mailseq" onError="fault">
<property name="CONTENT_TYPE"
value="application/json"
scope="axis2"
type="STRING"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:s="http://ws.wso2.org/dataservice"
name="primarymail"
expression="//s:primarymail/text()"
scope="axis2"
type="STRING"/>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:s="http://ws.wso2.org/dataservice"
name="primarymail"
expression="//s:primarymail/text()"
scope="axis2"
type="STRING"/>
</log>
<header name="To" expression="fn:concat('mailto:', get-property('primarymail'))"/>
<send/>
<log>
<property name="mail" value="ts working"/></log>
</sequence>
can we send a email like this i have got reference from this
http://docs.wso2.org/wiki/display/ESB460/Sample+256%3A+Proxy+Services+with+the+Mail+Transport
i am posted my requirement in another way also please refer this
Can we send Multiple Mail in wso2esb in same sequence or dynamically set a mail
Just follow the step in below URL ( but rather than header part, use endpoint for this as below.. this worked for me)
http://docs.wso2.org/wiki/display/ESB460/Sample+256%3A+Proxy+Services+with+the+Mail+Transport
Add Send for mail as below...( no need header mediator)
<send> <endpoint>
<address uri="mailto:yourmailaddr#gmail.com" />
</endpoint>
</send>

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>