Create Proxy Service which publishes/triggers a topic event and passes data - publish-subscribe

I have an issue which I do not have an idea how to resolve it. I am on WSB2 ESB 4.9.0.
I am trying to call a topic through a proxy using an event. However this never call the proxy subscribed to it.
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="publishSubscribeTest" startOnLoad="true" trace="disable"
transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log level="custom">
<property value="********************* START METHOD *********************" name="publishSubscribeTest"/>
</log>
<event topic="TestTopic"/>
<log level="custom">
<property value="********************* END METHOD *********************" name="publishSubscribeTest"/>
</log>
</inSequence>
<outSequence>
<drop/>
</outSequence>
<faultSequence/>
</target>
</proxy>
The topic has the following details:
Topic Name: TestTopic
Permissions Details: (Everyone has permission to subscribe and publish)
WS Subscription Details: Another custom proxy in WSO2 has been configured as WS Subscription Details.
So when first proxy calls the topic, it should call the proxy subscribed to that topic. However it is never called.
This is the proxy called by topic:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="proxyCalledByTopic" startOnLoad="true" trace="disable"
transports="https http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log level="custom">
<property value="********************* START METHOD *********************" name="proxyCalledByTopic"/>
</log>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
So the log should be something like:
publishSubscribeTest = ********************* END METHOD
********************* proxyCalledByTopic = ********************* START METHOD ********************* publishSubscribeTest =
********************* START METHOD *********************
However it is like:
publishSubscribeTest = ********************* END METHOD
********************* publishSubscribeTest = ********************* START METHOD *********************
So I understand that the proxy called by the topic in the subscription is not called.
Any suggestion? Any help?

After some try outs, the issue why the pub sub was not triggering the event was due to the fact that content-type header needs was not populated appropriately from the incoming request to the proxy service. The same can be achieved from setting up an POST api.
Once the content-type header is populated with either of the below values, the pub/sub events started working.
Content-Type: application/json
Content-Type: application/xml
Sample Posts:
XML
POST /TriggerTopic HTTP/1.1
Host: 10.224.234.34:8280
Content-Type: application/xml
Cache-Control: no-cache
Postman-Token: f60c206c-a38e-ed2d-46a0-b051304247be
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Dont forget me this weekend from postman via API</body>
</note>
Sample Post JSON
POST /TriggerTopic HTTP/1.1
Host: 10.224.234.34:8280
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 3453ddc5-a279-203a-fecf-38e81bd3ba8b
{"value":"some value"}

Related

WSO2 ESB 5.0 How to recover value xml element into cdata section?

Hello WSO2 ESB community,
We are new in WSO2. We need help to resolve this question.
We've developed a proxy which receives a soap message like this.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:es="http://es.ata">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<es:rc>
<es:xml><![CDATA[<message date="2017-03-02" id="ATA001">.....</message>]]></es:xml>
<es:rc>
</soapenv:Body>
</soapenv:Envelope>
How can we recover the attribute value "id"??
Anyone can help us??
Thanks in advance.
Extract es:xml content in a property type OM (XML) and use XPath inside this content.
Send your payload to this sample proxy and have a look to wso2-esb-service.log, you will find "id = ATA001"
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestSOF" transports="http" startOnLoad="true" trace="disable">
<description/>
<target>
<inSequence>
<property xmlns:es="http://es.ata" name="CDATAPAYLOAD" expression="$body/es:rc/es:xml" type="OM"/>
<property name="ID_VALUE" expression="get-property('CDATAPAYLOAD')/#id"/>
<log level="custom">
<property name="id" expression="get-property('ID_VALUE')"/>
</log>
</inSequence>
</target>
</proxy>

Rest Service on WSO2 ESB API with a Mal Formed XML request

I have created an api proxy to call my rest service, but when I send in a Mal formed XML request, I only receive an HTTP status code 202.
I have coded my service to handle this mal formed xml, and I just want the ESB to pass through the request.
Here is the code to my ESB API:
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="myApi" context="/restService">
<resource methods="POST">
<inSequence>
<send>
<endpoint>
<address uri="http://myserver/MyRestService"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
Thanks
In this case, ESB should be able to successfully send the message to the backend. By enabling wire logs you can make sure message sending correctly to the backend.
If you are not expecting any response from your backend, Please set out_only property in your inseqeunce

WSO2 CEP fire BPS over SOAP failed

I want to invoke a BPS process from CEP through SOAP method, but got an exception in BPS side.
the event output formatter such as:
<?xml version="1.0" encoding="UTF-8"?>
<eventFormatter name="output_formatter" statistics="disable"
trace="enable" xmlns="http://wso2.org/carbon/eventformatter">
<from streamName="output" version="1.0.0"/>
<mapping customMapping="enable" type="xml">
<inline>
<TestEchoRequest>
<input>{{meta_output}}</input>
</TestEchoRequest>
</inline>
</mapping>
<to eventAdaptorName="outputadapter" eventAdaptorType="soap">
<property name="headers">SOAPAction:"http://wso2.org/bps/sample/process" </property>
<property name="username">admin#carbon.super</property>
<property name="password">admin</property>
<property name="url">http://192.168.20.213:9767/services/TestEcho/</property>
</to>
</eventFormatter>
but from the view of Enter Event Formatter Details, the headers property was mismatch to the XML version, lost the bottom half of "SOAPAction".
if fire the event from Event Stream Simulator, the BPS got an exception:
TID[-1234] [BPS] [2015-08-27 09:51:08,064] ERROR {org.apache.axis2.engine.AxisEngine} - The endpoint reference (EPR) for the Operation not found is http://192.168.11.250:9767/services/TestEcho/ and the WSA Action = . If this EPR was previously reachable, please contact the server administrator.
the message sent by CEP is just like this, it seems that the SOAPAction header is lost:
POST / HTTP/1.1
Content-Type: text/xml; charset=UTF-8
SOAPAction: ""
User-Agent: Axis2
Host: 192.168.20.213:9767
Transfer-Encoding: chunked
400
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1"><wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-71"><wsu:Created>2015-08-28T05:14:09.554Z</wsu:Created><wsu:Expires>2015-08-28T05:19:09.554Z</wsu:Expires></wsu:Timestamp><wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-72"><wsse:Username>admin</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">admin</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><event xmlns="http://wso2.org/carbon/event"><metaData><im>AAAAAAA</im></metaData></event></soapenv:Body></soapenv:Envelope>
0
Is it a bug or any suggestion ?
Above is a known issue in WSO2 CEP 3.1.0, see [1].. As a workaround can you call the soap12 endpoint of TestEcho service because SOAPAction property is optional in soap12 (Add complete url with soap12 endpoint for url property)..
example,
http://192.168.20.213:9767/services/TestEcho.TestEchoHttpsSoap12Endpoint/
[1] https://wso2.org/jira/browse/CEP-1108

Proxy a RESTful service using SOAP with WSO2 ESB

We want to proxy a RESTful web service with SOAP.
The REST service uses the GET method and accepts inputs via query parameters. It produces a resource of type application/csv.
Does WSO2 ESB/Synapse support such a scenario, and is there an example available?
Example Request
SOAP Proxy Request:
<request>
<fromDate>2012-01-01</fromDate>
<toDate>2012-12-31</toDate>
</request>
REST Endpoint Request:
http://localhost/person?fromDate=2012-01-01&toDate=2012-12-31
Example Response
REST Endpoint Response
"Name","Age","Sex"
"Geoff","22","Male"
SOAP Proxy Response
<person>
<name>Geoff</name>
<age>22</age>
<sex>Male</sex>
<person>
Many thanks.
If I understand you correctly, you want to expose a REST service as a SOAP service, so that SOAP clients can access your REST service through the ESB?
If that is the case, it is possible :) You should check out sample 152 from these: http://docs.wso2.org/wiki/display/ESB451/Proxy+Service+Samples
It'll explain how you take a SOAP request and pass it to a REST backend and then transform the REST response into a SOAP response.
EDIT: Here's a sample configuration on how to do what you asked in the comments, hopefully it will get you started :)
<proxy xmlns="http://ws.apache.org/ns/synapse" name="RESTProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<!-- We set the HTTP Method we want to use to make the REST request here -->
<property name="HTTP_METHOD" value="GET" scope="axis2"/>
<!-- This is where the magic happens, for what you want i.e. mapping SOAP "params" to REST query param's -->
<property name="messageType" value="application/x-www-form-urlencoded" scope="axis2"/>
<send>
<endpoint>
<!-- This is the RESTful URL we are going to query, like the one in the ESB example 152 -->
<address uri="http://localhost/person" />
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<property name="messageType" value="text/xml" scope="axis2"/>
<send/>
</outSequence>
</target>
<description></description>
</proxy>
Then the SOAP request you make to the ESB should be something like:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<person>
<fromDate>2012-01-01</fromDate>
<toDate>2012-12-31</toDate>
</person>
</soapenv:Body>
</soapenv:Envelope>
Hope that helps :)
Hope This will be very helpful you to understand of SOAP Client and REST Service communication
http://docs.wso2.org/display/ESB460/Using+REST+with+a+Proxy+Service#UsingRESTwithaProxyService-SOAPClientandRESTService
You can use class mediator to extract the SOAP parameters using XPATH. Than build the REST URL and send it back to IN sequence flow.
1. you need to get the value from SOAP PROXY
2. you need to store it in a local variable
3. you need to pass the value to the REST SERVICE using Query Parameters
4. you need to format the response from REST Service to an SOAP Format
The SOAP Request will be,
<request>
<fromDate>2012-01-01</fromDate>
<toDate>2012-12-31</toDate>
</request>
You can store the value from SOAP PROXY Request as,
<proxy xmlns="http://ws.apache.org/ns/synapse" name="RESTProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true><target>
<inSequence>
<property name="fromDate" expression="//fromDate" scope="default" type="STRING"/>
<property name="toDate" expression="//toDate" scope="default" type="STRING"/>
Then you can pass the values to the REST Service by,
<send>
<endpoint>
<http method="GET" uri-template="http://localhost/person?fromDate=={get-property('fromDate')}&toDate={get-property('toDate')}"/>
</endpoint>
</send>
</inSequence>
Then You can Format the Response using PayloadFactory mediator,
<outSequence>
<payloadFactory media-type="xml">
<format>
<person>
<Name>$1</Name>
<Age>$2</Age>
<Sex>$3</Sex>
</person>
</format>
<args>
<arg evaluator="json" expression="$.Name"/>
<arg evaluator="json" expression="$.Age"/>
<arg evaluator="json" expression="$.Sex"/>
</args>
</payloadFactory>
<send/>
</outSequence>
</target>
<description/>
</proxy>
So the Response of Proxy will be,
<person>
<name>Geoff</name>
<age>22</age>
<sex>Male</sex>
<person>

WSO2 ESB mediate SOAP services

I am struggling to make work my message flow in the wso2 esb so I would need some help to implement a basic communication:
Service1 wants to receive an integer number
Service2 Generates random numbers
Service1 has InSequence: log, send (to addresspoint specified). OutSequence: log, send
this looks like:
<proxy name="ClientAskNumber" transports="https http" startOnLoad="true"
trace="disable">
<target faultSequence="fault">
<inSequence>
<log level="full">
<property name="Insequence" value="***" />
</log>
<send>
<endpoint>
<address uri="http://localhost:8280/services/RandomNumbers" />
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full">
<property name="Outsequence" value="***" />
</log>
<send />
</outSequence>
</target>
</proxy>
I have this response: <faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: urn:mediate. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()....etc
What it means? Am I missing something else? Please help. Thank you
EDIT:
I am studying the Wso2 ESB and I just need to understand how to make work a message communication, after it I will try to add different kind of mediation. I am just breaking down the problem, because I am new to this technology and as you can see I am really struggling to make it work...
EDIT2:*
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ClientAskNumber" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target endpoint="RandomNumbers">
<inSequence>
<log>
<property name="CLIENTASKS" value="******C_ASKS" />
</log>
<send>
<endpoint key="RandomNumbers" />
</send>
</inSequence>
<outSequence>
<log>
<property name="CLIENTRECEIVES" value="*******C_RECEIVES" />
</log>
</outSequence>
</target>
</proxy>
In the case this helps someone else: the problem with "Server did not recognize the value of HTTP Header SOAPAction: urn:mediate..." is that I needed to add an Header mediator in order to call my webservice method "getNumbers", into my InSequence as follows:
<inSequence>
<log>
<property name="CLIENTASKS" value="******C_ASKS" />
</log>
<header name="Action" value="http://tempuri.org/getNumbers" />
<send>
<endpoint key="RandomNumbers" />
</send>
</inSequence>
and send this request via soapUI:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Numbers xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
I hope this can be useful to other persons who are using .Net Solutions with WSO2ESB (unfortunately there are not many examples out there...)
P.S. thanks to Ratha for his help
This is the flow i can tell you..
You have to point your 2nd service as the endpoint of your fist service..In the above configuration
http://localhost:8280/services/RandomNumbers --->2nd service url
ClientAskNumber -->1st service..
Now you can send the request which is needed to execute the 2nd service(ie:to retrive the random number)
So the proxy will forwrad to that endpoint and return the response to the outsequence..You should see that in the console/log since you used a log mediator.
In the error response you are getting i hope you are getting that from your second service. Check whether you are sending correct request to your endpoint