wso2 esb proxy rest service no response - wso2-esb

proxy config:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="person"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<send>
<endpoint>
<address format="pox" uri="http://localhost:8181/person/"/>
</endpoint>
</send>
<log level="full"/>
</inSequence>
<outSequence>
<log level="full"/>
<property name="messageType" scope="axis2" value="text/xml"/>
<send/>
</outSequence>
</target>
<description/>
</proxy>
Request message can not get response message template:
The template:
This is the console log output:

Can you try with this,
<endpoint name="IdentityDSSserviceEP" template="esbendpoint" uri="http://localhost:8181/person/"/>
Template (Sample template)
<template xmlns="http://ws.apache.org/ns/synapse" name="esbendpoint">
<endpoint name="$name">
<address uri="$uri">
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
<timeout>
<duration>60000</duration>
<responseAction>fault</responseAction>
</timeout>
</address>
</endpoint>
</template>

Related

Can someone help me to fix this ESB code?

Encountered this error message below:
org.apache.commons.httpclient.URIException: Invalid query
at org.apache.commons.httpclient.URI.parseUriReference(URI.java:2049)
at org.apache.commons.httpclient.URI.<init>(URI.java:147)
Here are my exact codes below, encountering an issue when calling
<?xml version="1.0" encoding="UTF-8"?>
<api context="/test_api" name="rest" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/hello?name={namVal}">
<inSequence>
<property name="SYSTEM" expression="$url:name"/>
<property name="uri.var.name" expression="$ctx:SYSTEM"/>
<call blocking="true">
<endpoint key="hello_EP"/>
</call>
<payloadFactory media-type="xml">
.....
</payloadFactory>
<respond />
</inSequence>
<outSequence />
<faultSequence />
</resource>
</api>
Here is my EP for reference
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="hello_EP" xmlns="http://ws.apache.org/ns/synapse">
<address uri="http://xxxxxxxxxx:(port)/spring/hello?name={uri.var.fname}" methods="POST"/>
</endpoint>
Query param in the endpoint is {uri.var.fname} but the property name uri.var.name. Therefore change the property name to uri.var.fname.
This can be directly done by a single property instead of having two properties as below,
<property name="uri.var.fname" expression="$url:name"/>
The issue i posted was already fixed yesterday. To fix the issue i need to change the uri-template to url-mapping.
here is my updated code now:
Endpoint:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="hello_EP" xmlns="http://ws.apache.org/ns/synapse">
<address uri="http://xxxxxxxxxxxxxxxxxx:12345/SpringRest/"/>
</endpoint>
API code.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/temp_api" name="springRest" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" url-mapping="/hello">
<inSequence>
<!-- URL Parameters -->
<property expression="$url:name" name="SYSTEM" scope="default" type="STRING"/>
<!-- Logs -->
<log level="custom">
<property expression="$ctx:SYSTEM" name="value-system"/>
</log>
<!-- URL param value passed to endpoint param -->
<property expression="$ctx:SYSTEM" name="uri.var.fname" scope="default" type="STRING"/>
<!-- Call endpoint -->
<call blocking="true">
<endpoint key="hello_EP"/>
</call>
<payloadFactory media-type="xml">
..
..
</payloadFactory>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
output:
<body xmlns="http://ws.apache.org/ns/synapse">
{
"id": 1,
"content": "Hello, world!"
}
</body>

WSO2ESB: How to add <?xml into the message sent to POX endpoint

I'm using wso2ei 6.0.0 and I have a simple task - send specific xml message via POST to the endpoint.
I have API configured like this:
<api xmlns="http://ws.apache.org/ns/synapse" name="glisTest" context="/glisTest">
<resource methods="GET" uri-template="/{sampleid}">
<inSequence>
<property name="PRESERVE_WS_ADDRESSING" value="false"/>
<payloadFactory media-type="xml">
<format>
<register />
</format>
</payloadFactory>
<log level="full"/>
<property name="messageType" value="application/xml" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="post" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="https://localhost/manager" encoding="UTF-8" format="pox"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
</resource>
</api>
But service is expected
<?xml version="1.0" encoding="UTF-8" ?>
to be inserted at the beginning and wso2 do not do it (I just added debug logging for org.apache.synapse.transport.http.wire and I see it simple send
<register/>
As result, it does not recognize message as an xml and returm me error.
Question - how to tell synapse to add this special xml header to the message?

WSO2 ESB: How to write a file from Base64 with VFS?

I have pretty much the same issue as this person:
WSO2 ESB - writing files out of base64
However, in the answer to that question there was no mention of how to decode the Base64 string in JavaScript and attach it to the payload. That's what I'm interested in.
Thanks in advance,
Strainy
Went with a slightly different approach. I created a utility proxy service to re-download the file and then push it into the file system.
utilty_createFile Proxy Service
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="utility_createFile"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target inSequence="utility_createFile_IN" outSequence="utility_createFile_OUT"/>
<description/>
</proxy>
utility_createFile_IN Sequence
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="utility_createFile_IN" onError="fault" xmlns="http://ws.apache.org/ns/synapse">
<property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>
<property expression="//createFile/download_folder"
name="uri.var.download_folder" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="//createFile/url" name="uri.var.download_url" xmlns:ns="http://org.apache.synapse/xsd"/>
<script language="js"><![CDATA[var download_url = mc.getProperty('uri.var.download_url');
download_url = decodeURIComponent(download_url);
mc.setProperty('uri.var.download_url', download_url);]]></script>
<send>
<endpoint>
<http method="GET" uri-template="{uri.var.download_url}"/>
</endpoint>
</send>
</sequence>
utility_createFile_OUT Sequence
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="utility_createFile_IN" onError="fault" xmlns="http://ws.apache.org/ns/synapse">
<property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>
<property expression="//createFile/download_folder"
name="uri.var.download_folder" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="//createFile/url" name="uri.var.download_url" xmlns:ns="http://org.apache.synapse/xsd"/>
<script language="js"><![CDATA[var download_url = mc.getProperty('uri.var.download_url');
download_url = decodeURIComponent(download_url);
mc.setProperty('uri.var.download_url', download_url);]]></script>
<send>
<endpoint>
<http method="GET" uri-template="{uri.var.download_url}"/>
</endpoint>
</send>
</sequence>

WSO2 ESB 4.7.0 API url-mapping

I am trying to make an API at WSO2 ESB 4.7.0 to process requests for a RESTful service. It seems that the URL-Mapping feature is not working or is working just like a filter, choosing what to send to the endpoint and what to drop. I have followed this tutorial: http://wso2.com/library/articles/2012/09/get-cup-coffee-wso2-way/. Here is my API configuration:
<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/rest">
<resource methods="GET" url-mapping="/">
<inSequence>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST"/>
</endpoint>
</send>
</inSequence>
</resource>
<resource methods="GET" url-mapping="/numbers">
<inSequence>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST/allnumbers"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
There are three situations:
This URL works: http://esb/rest
This URL doesn't work: http://esb/rest/numbers
This URL works: http://myserver/REST/allnumbers
In situation 2, I got an Apache Tomcat error:
HTTP Status 404 - Not Found
type Status report
message Not Found
description The requested resource (Not Found) is not available.
Apache Tomcat/6.0.32
But if I try the endpoint address, it works. I thought that the URL-Mapping would route requests for "/numbers" to "/allnumbers". What am I doing wrong?
Solved! I had to remove the REST_URL_POSTFIX before sending to the endpoint:
<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/rest">
<resource methods="GET" url-mapping="/">
<inSequence>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST"/>
</endpoint>
</send>
</inSequence>
</resource>
<resource methods="GET" url-mapping="/numbers">
<inSequence>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST/allnumbers"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
Now, http://esb/rest/numbers works too! :)

Removing SOAP Wrapper From a Message in wso2 ESB

I tried to invoke a web service through WSO2esb.My web service is only accepting a soap message like this.
<?xml version="1.0" encoding="UTF-8"?>
<ns1:Envelope xmlns:ns1="http://www.webserviceX.NET/ConversionRate/Input" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Documents and Settings\RoGulk\Desktop\SPM\Envelope.xsd">
<ns1:Body>
<ns2:ConversionRate xmlns:ns2="http://www.webserviceX.NET/">
<ns2:FromCurrency>USD</ns2:FromCurrency>
<ns2:ToCurrency>USD</ns2:ToCurrency>
</ns2:ConversionRate>
</ns1:Body>
</ns1:Envelope>
But the problem is when I read the input message to the esb, The esb adds a additional wrapper to my meaasage like this
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:Envelope xmlns:ns1="http://www.webserviceX.NET/ConversionRate/Input">
<ns1:Body>
<ns2:ConversionRate xmlns:ns2="http://www.webserviceX.NET/">
<ns2:FromCurrency>INR</ns2:FromCurrency>
<ns2:ToCurrency>NAD</ns2:ToCurrency>
</ns2:ConversionRate>
</ns1:Body>
</ns1:Envelope>
</soapenv:Body>
</soapenv:Envelope>
I think it can be done by using the 'application/XML' message formatter before I call to my endpoint.But the problem is I don't know how to invoke the 'application/XML' message formatter and where to use it.**
Guys please help me, Thanks
EDITED
I thought that adding my proxy service configuration will be helpful.
In this I am not using default out sequance. Instead of that I am using sequance called "currencyFileWriter" which is responsible for writing a file to a output directory.
This is my proxy service
<proxy xmlns="http://ws.apache.org/ns/synapse" name="CurrencyProxy" transports="https,http,vfs" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="messageType" value="application/xml" scope="default" type="STRING"/>
<property name="ContentType" value="application/xml" scope="default"/>
<log level="custom">
<property name="MessageType" expression="$axis2:ContentType"/>
</log>
<log level="full"/>
<log level="custom">
<property name="insequance" value="================================Forwerded to out File writer sequance====================="/>
</log>
<send receive="currencyFileWriter" buildmessage="true">
<endpoint key="CurrencyConverter"/>
</send>
<log level="custom">
<property name="After" value="============================AFTER SEND================"/>
</log>
<log level="full"/>
</inSequence>
</target>
<parameter name="transport.PollInterval">5</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.FileURI">file:///C:/test/Orginal1/</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///C:/test/Pass1/</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///C:/test/Failures1/</parameter>
<parameter name="transport.vfs.FileNamePattern">currencytest.xml</parameter>
<parameter name="transport.vfs.ContentType">application/xml</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<description></description>
</proxy>
And tihs is my CurrencyFilewriter sequance
<sequence xmlns="http://ws.apache.org/ns/synapse" name="currencyFileWriter">
<log level="custom">
<property name="sequance" value="=====================RECIVED TO CURRENCYFILEWRITER=========================="/>
</log>
<log level="full"/>
<property name="transport.vfs.ReplyFileName" value="result.xml" scope="default" type="STRING"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint>
<address uri="vfs:file:///C:/test/Out1"/>
</endpoint>
</send>
</sequence>
I used the following configuration and I got the following results inside of the VFS folder.
Here's what I've done:
Endpoint Configuration:
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="CurrencyConverter">
<address uri="http://www.webservicex.net/CurrencyConvertor.asmx"></address>
</endpoint>
Sequence Configuration:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="currencyFileWriter">
<log level="custom">
<property name="sequance" value="=====================RECIVED TO CURRENCYFILEWRITER=========================="/>
</log>
<log level="full"/>
<property name="transport.vfs.ReplyFileName" value="result.xml" scope="default" type="STRING"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint>
<address uri="vfs:file:///home/ravi/esb/wso2esb-4.5.1/vfs-temp/Out1"/>
</endpoint>
</send>
</sequence>
Proxy Configuration:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="CurrencyProxy" transports="https,http,vfs" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<log level="custom">
<property name="insequance" value="================================Forwerded to out File writer sequance====================="/>
</log>
<send>
<endpoint key="CurrencyConverter"/>
</send>
<log level="custom">
<property name="After" value="============================AFTER SEND================"/>
</log>
<log level="full"/>
</inSequence>
<outSequence>
<sequence key="currencyFileWriter"/>
</outSequence>
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">5</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///home/ravi/esb/wso2esb-4.5.1/vfs-temp/Pass1/</parameter>
<parameter name="transport.vfs.FileURI">file:///home/ravi/esb/wso2esb-4.5.1/vfs-temp/Orginal1/</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///home/ravi/esb/wso2esb-4.5.1/vfs-temp/Failures1/</parameter>
<parameter name="transport.vfs.FileNamePattern">currencytest.xml</parameter>
<parameter name="transport.vfs.ContentType">application/xml</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<description></description>
</proxy>
This is what is passed from the client (SOAP UI in my case) to the ESB - I've used SOAP 1.2 here by pointing the namespace ns1 to http://www.w3.org/2003/05/soap-envelope:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:Envelope xmlns:ns1="http://www.w3.org/2003/05/soap-envelope" xmlns:ns2="http://www.webserviceX.NET/ConversionRate/Input">
<ns1:Body>
<ns2:ConversionRate xmlns:ns2="http://www.webserviceX.NET/">
<ns2:FromCurrency>USD</ns2:FromCurrency>
<ns2:ToCurrency>LKR</ns2:ToCurrency>
</ns2:ConversionRate>
</ns1:Body>
</ns1:Envelope>
This is what the ESB sends to the backend service:
POST /CurrencyConvertor.asmx?WSDL HTTP/1.1
Content-Type: application/soap+xml; charset=UTF-8; action="urn:mediate"
Accept-Encoding: gzip,deflate
Transfer-Encoding: chunked
Host: localhost:5000
Connection: Keep-Alive
User-Agent: Synapse-HttpComponents-NIO
<?xml version='1.0' encoding='UTF-8'?>
<ns1:Envelope xmlns:ns1="http://www.w3.org/2003/05/soap-envelope" xmlns:ns2="http://www.webserviceX.NET/ConversionRate/Input">
<ns1:Body>
<ns2:ConversionRate xmlns:ns2="http://www.webserviceX.NET/">
<ns2:FromCurrency>USD</ns2:FromCurrency>
<ns2:ToCurrency>LKR</ns2:ToCurrency>
</ns2:ConversionRate>
</ns1:Body>
</ns1:Envelope>
This is what the web service returns to the ESB and is also saved in the Out1 file:
Cache-Control: private, max-age=0
Content-Length: 380
Content-Type: application/soap+xml; charset=utf-8
Server: Microsoft-IIS/7.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 23 Jan 2013 15:53:53 GMT
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ConversionRateResponse xmlns="http://www.webserviceX.NET/">
<ConversionRateResult>127.05</ConversionRateResult>
</ConversionRateResponse>
</soap:Body>
</soap:Envelope>
Hope this helps as with this setup I don't seem to be getting the issue you're having - with the ESB re-wrapping the request. :)
You need to add the following property just above the send mediator (before call your endpoint) to remove the additional soap envelope wrapper from the message.
<property name="messageType" value="application/xml" scope="axis2" type="STRING"/>
I tested it with following sample proxy and it worked for me.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="test"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="messageType"
value="application/xml"
scope="axis2"
type="STRING"/>
<log level="full"/>
<send>
<endpoint>
<address uri="http://www.google.com"/>
</endpoint>
</send>
</inSequence>
</target>
<description/>
</proxy>
Thanks