I Created the following REST API on WSO2 Integrator 6.4 with the sequences:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/dsb" name="evCaptureJSONProperties"
xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST" uri-template="/api/SendSMS">
<inSequence>
<log description="Entry Confirmation" level="custom">
<property name="message" value="Request Entered the
evCaptureJSONProperties REST API"/>
</log>
<payloadFactory media-type="json">
<format><!-- A json message was here --></format>
<args/>
</payloadFactory>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
And then I posted the request JSON using the following command:
Curl -v -X POST --data #evCaptureJSONProperties.json http://localhost:8280/dsb/api/SendSMS --header "Content-Type:application/json"
But instead of getting back in return the payload an error appeared in the logs and the console:
[2018-12-03 10:23:02,432] [EI-Core] ERROR - RelayUtils Error while building
Passthrough stream
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at org.apache.synapse.commons.builders.XFormURLEncodedBuilder.
extractParametersFromRequest(XFormURLEncodedBuilder.java:223)
at
org.apache.synapse.commons.builders.XFormURLEncodedBuilder.
processDocumentWrapper(XFormURLEncodedBuilder.java:128)
at org.apache.synapse.commons.builders.XFormURLEncodedBuilder.
processDocument(XFormURLEncodedBuilder.java:52)
I humbly request for some assistance. Thank you very much in advance.
Related
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
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"}
I have created a proxy service in wso2, while try accessing the proxy service it shows error as Unsupported Media Type, but I have set Content-Type: application/xml .payload is in xml format, so am setting it to application/xml in the source view ,still am getting the same error, Please help me to resolve this issue
**Proxy Service:**
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="test"
transports="http,https"
statistics="enable"
trace="enable"
startOnLoad="true">
<target>
<outSequence>
<property name="Content-Type" value="application/xml"/>
<send/>
</outSequence>
<endpoint>
<address uri="http://192.35.72.369:8080/ESB_Services/DRAM/service/CreateCustomer"/>
</endpoint>
</target>
<description/>
</proxy>
**Payload:**
<customer>
<name>admin</name>
<email>admin#gmail.com</email>
<mobile_number>9904324234</mobile_number>
<address>Bangalore</address>
<zipcode>574515</zipcode>
</customer>
**ERROR:**
<TryitProxyError h:status="SOAP envelope error" xmlns:h="http://wso2.org/ns/TryitProxy">org.apache.axis2.AxisFault: Transport error: 415 Error: Unsupported Media Type</TryitProxyError>
When you need to choose the appropriate messageFormatter, used to format a message going out from the ESB, you use the property 'messageType' : <property name="messageType" value="application/xml" scope="axis2" />
I'm wondering for solution to my Issue but I didn't find anything that can help me :(
THIS IS MY ISSUE:
I'd like to call a remote REST web service by passing it trought an ESB to log the client call on DB.
I'd like to pass a POST query var to my remote ws too, for example name=value & name2=value2!
I make a proxy service but I don't know how I can append the query variable to IT.
I can contact correctly remote ws with this proxy but I can't pass a POST VAR because I don't know how to do that.
I make a below curl call by client shell:
curl -k -i http://neanb330:8281/services/BioframeProxyService
in my proxy service I have this endpoint :
http://www.ebi.ac.uk/Tools/services/rest/emboss_matcher/run
BUT this service require two params in input and put out a jobid that I want to write in out sequence for client.
Have I to make a REST API?
How I can Log client call on db?
Thanks
This post describes how to process rest requests within WSO2 ESB in detail with examples.
http://wso2.com/library/articles/2012/09/get-cup-coffee-wso2-way/
This is the official documentation that explains rest url mapping
http://docs.wso2.org/display/ESB470/Getting+Started+with+REST+APIs
If your question is how you can send data to your end point using curl then this is the way
curl -v --request POST -d '<Values><name1>ABC</name1><name2>Smith</name2></Values>' -H Content-Type:"text/xml" http://neanb330:8281/services/BioframeProxyService
Then you can get the values to ESB as shown below
<property name="name1" expression="//name1/text()"/>
<property name="name2" expression="//name2/text()"/>
I find a solution for both GET and POST in Rest to rest scenario.
This for POST. I USE a proxy service and a curl call:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="BioframeProxyServiceRunBis"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
<property name="ContentType" value="text/xml" 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>
<send>
<endpoint>
<address uri="http://www.ebi.ac.uk/Tools/services/rest/emboss_matcher/run/"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<description/>
</proxy>
curl -k -X POST https://neanb330:8244/services/BioframeProxyServiceRunBis -d asequence=FASTA -d bsequence=FASTA -d email=maforast#gmail.com -v
I don't find solution for save rest call to DB
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>