Get Text from Envelope - wso2

I want to get text from following Envelope so that I can use it as REST_URL_POSTFIX.
I am sending a plain text message to a JMS queue and following WSO2-ESB proxy service is used as a receiver/listener of JMS queue. I have tried following expressions but they does not work :
$body
$body/text
$body/text()
The SOAP 1.1 or 1.2 body element. For example, the expression
$body/getQuote refers to the first getQuote element in a SOAP body,
regardless of whether the message is SOAP-11 or SOAP-12.
and
//Envelope//Body//text
//Envelope//Body//text()
INFO - (Send
LogMediator To: , MessageID: ID:sunnydyal-K55VM-44230-1439804805911-3:2:1:1:9,
Direction: request, ##### Message = ,
Envelope:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<axis2ns8:text xmlns:axis2ns8="http://ws.apache.org/commons/ns/payload">Test</axis2ns8:text>
</soapenv:Body>
</soapenv:Envelope>
#Proxy Service:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="JmsToRestProxy"
transports="jms"
statistics="enable"
trace="enable"
startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<property name="SOAPAction" scope="default" action="remove"/>
<header name="Action" scope="default" action="remove"/>
<property name="REST_URL_POSTFIX"
expression="//Envelope//Body//text"
scope="axis2"
type="STRING"/>
<switch source="$axis2:HTTP_METHOD">
<case regex="GET">
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
</case>
<case regex="POST">
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
</case>
<default/>
</switch>
<log level="full">
<property name="##### Message" expression="$body/text"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:8080/Rest/rest" format="rest"/>
</endpoint>
</send>
</inSequence>
</target>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>text/plain</default>
</rules>
</parameter>
<description/>
</proxy>

text node belong to a specific namespace "http://ws.apache.org/commons/ns/payload" :
<log level="full">
<property xmlns:syn="http://ws.apache.org/commons/ns/payload" name="##### Message" expression="$body/syn:text/text()"/>
</log>

You can get the body using the $body variable[1]. /text() is trying to access the text element of the body which doesn't exist.
<log level="custom">
<property name="Body" expression="$body" />
</log>
[1] - https://docs.wso2.com/display/ESB481/Synapse+XPath+Variables#SynapseXPathVariables-$body

Related

WSO2 ESB how to sending array list empty error

I Configurate url like:
https://htygnfgvsccl.com:6753/intellige/vehicle/getAlerts
this url some times getting data like
{
"alertsList": [
{
"vehicleNo": "45342",
"alertName": "Stop Skipped",
"depotName": "akividu"
},
{
"vehicleNo": "674894",
"alertName": "Stop Skipped",
"depotName": "guntur"
}
]
}
but some times getting data like
{
"alertsList": []
}
every time response code is 200 but how to send with error message in the case of alertsList empty
vehiclegetAlertsapi
<?xml version="1.0" encoding="UTF-8"?>
<api context="/intellige/vehicle/getAlerts" name="vehiclegetAlertsapi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<property description="http" name="HTTP_SC" scope="axis2" type="STRING" value="404"/>
<log level="full"/>
<send>
<endpoint key="vehiclegetAlertsendpoint"/>
</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>
<clone continueParent="true">
<target>
<sequence>
<sequence key="vehiclegetAlertsmail"/>
</sequence>
</target>
</clone>
<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>
<clone continueParent="true">
<target>
<sequence>
<sequence key="vehiclegetAlertsmail"/>
</sequence>
</target>
</clone>
<send/>
</faultSequence>
</resource>
</api>
vehiclegetAlertsendpoint
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="vehiclegetAlertsendpoint" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="https://htygnfgvsccl.com:6753/intellige/vehicle/getAlerts "/>
</endpoint>
vehiclegetAlertsmail:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="vehiclegetAlertsmail" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="custom">
<property name="status" value=" vehileget alert Details Sending mail"/>
</log>
<property expression="get-property('axis2','HTTP_SC')" name="ErrorMessage" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property name="ContentType" scope="axis2" type="STRING" value="text/plain"/>
<property name="Subject" scope="transport" type="STRING" value="vehileget alert api not working"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<payloadFactory media-type="json">
<format>{"vehileget alert api not working":"$1"}</format>
<args>
<arg evaluator="xml" expression="$ctx:ErrorMessage" xmlns:ns="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
<call>
<endpoint key="vehiclegetAlertsmailid"/>
</call>
<drop/>
</sequence>
vehiclegetAlertsmailid:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="vehiclegetAlertsmailid" xmlns="http://ws.apache.org/ns/synapse">
<recipientlist>
<endpoint>
<address uri="mailto:aisha#gmail.com"/>
</endpoint>
</recipientlist>
</endpoint>
get 200 response code send the data automatically in case if any other reponse to send the mail my mail id ,prsent my problem is my rest url some time total data like alertsList with data comming some times only alertsList comming not comming data that case how to send mail

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.

In wso2 esb i can send but i am not able to listen to websocket

In wso2 ESB, I am able to send data to WebSocket but I am not able to receive data.
I tried this with rest api of wso2 esb.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<log level="full">
<property name="message" value="********************************************input**********************"/>
</log>
<send>
<endpoint>
<http method="post" uri-template="ws://localhost:8080/websocket/server"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
outsequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="outflowDispatchSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="message" value="************************************************"/>
</log>
</sequence>
with the above API, I am able to send data to the server as shown in below image.
Http request from postman.
But as shown in below image of the console, the response which i am getting is empty as no body present.
If I use proxy service with content-type mentioned as in esb documentation(link) in websocket server i am getting exception
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="dispatchSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property name="OUT_ONLY" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<property name="websocket.accept.contenType" scope="axis2" value="text/plain"/>
<send>
<endpoint>
<address uri="ws://localhost:8080/websocket/server"/>
</endpoint>
</send>
</sequence>
axis2.xml websocket configuration is:
<transportSender name="ws" class="org.wso2.carbon.websocket.transport.WebsocketTransportSender">
<parameter name="ws.outflow.dispatch.sequence" locked="false">outflowDispatchSeq</parameter>
<parameter name="ws.outflow.dispatch.fault.sequence" locked="false">outflowFaultSeq</parameter>
</transportSender>
So how to send and receive the data from websocket

WSO2 ESB - Access original message from fault

My goal is to put messages that return a soap error on a queue, in order to retry them later.
I have nearly all working, but the most important part : I can't access the original message from the fault sequence of my proxy :(
I first made a proxy service that returns an error for a given value, or OK for the other values :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxyService" transports="http https" startOnLoad="true" trace="disable">
<target>
<inSequence>
<log level="custom">
<property name="TestProxyService" value="InSequence"/>
</log>
<switch xmlns:bnc="http://bnc.org/" source="//bnc:id">
<case regex="1">
<log level="custom">
<property name="TestProxyService" value="Send Error !"/>
</log>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch"/>
<reason value="ERROR ERROR ERROR"/>
<detail>ERROR</detail>
</makefault>
<respond/>
</case>
<default>
<log level="custom">
<property name="TestProxyService" value="No Error"/>
</log>
<log level="custom">
<property name="id" expression="//bnc:id"/>
</log>
<payloadFactory media-type="xml">
<format>
<bnc:response>OK</bnc:response>
</format>
<args/>
</payloadFactory>
<respond/>
</default>
</switch>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
</proxy>
And it works fine
I then made another proxy, that uses the first one as an endpoint to test the queuing on error :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="QueuingProxyService" transports="https http" startOnLoad="true" trace="disable">
<target>
<inSequence>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
<send>
<endpoint key="TestProxyServiceEndpoint"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence>
<store messageStore="No1MessageStore"/>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch"/>
<reason value="There has been an error"/>
<detail>We will retry later</detail>
</makefault>
<send/>
</faultSequence>
</target>
</proxy>
The message that is stored is the one made by the makefault in the TestProxy
I tried to save the original message in a property (in the inSequence) with
<property name="OriginalBody" expression="$body" scope="axis2" type="OM"/>
but in the faultSequence, when i do this :
<log level="custom">
<property name="OriginalBody" expression="get-property('OriginalBody')"/>
</log>
I got null as a result :(
Does anyone have an idea ?
Thanks !
remove scope "axis2" when defining property "OriginalBody" or explicitely specify scope="default" :
<property name="OriginalBody" expression="$body" type="OM"/>

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