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>
Related
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>
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?
I have a registered onError sequence.
In version 4.8.1 SOAP envelop is available in onError sequence
while in 4.9.0 it is not.
in order to access SOAP message content in 4.9.0 after error (in onError sequence) I always have to copy it to some temp variable initially. it is very inconvenient.
could it be a bug or is it a new "feature" of 4.9.0?
this is my fault sequence. if i remove enrich mediator envelope comes empty from the sequence with an error. Without enrich mediator message contains empty soap envelope. It can be seen in the output of the log mediator and in the message stored in RabbitMQ backend. Actually, it is onError sequence of XXXXNotifySendSequence sequence (I added them both for the reference).
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XXXXNotifyErrorSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="mssg" expression="get-property('mssg')"/>
<property name="retry_count" expression="get-property('retry_count')"/>
</log>
<filter xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xpath="get-property('mssg')">
<then>
<enrich>
<source clone="true" property="mssg" type="property"/>
<target type="envelope"/>
</enrich>
<property name="mssg" action="remove"/>
</then>
<else/>
</filter>
<filter xmlns:ns="http://org.apache.synapse/xsd" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:ns3="http://org.apache.synapse/xsd" xpath="get-property('retry_count')">
<then>
<property name="retry_count" expression="number(get-property('retry_count'))+1" scope="default" type="STRING"/>
<filter xpath="get-property('retry_count') > 5">
<then>
<log>
<property name="Dropping--Count" expression="get-property('retry_count')"/>
</log>
<drop/>
</then>
<else>
<sequence key="XXXXNotifySendSequence"/>
</else>
</filter>
</then>
<else>
<property name="retry_count" value="1" scope="default" type="STRING"/>
<clone continueParent="true">
<target>
<sequence>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch"/>
<reason expression="get-property('ERROR_MESSAGE')"/>
</makefault>
<send/>
</sequence>
</target>
</clone>
</else>
</filter>
<clone>
<target>
<sequence>
<log level="custom">
<property name="STORE" value="store the message"/>
</log>
<store messageStore="XXXXRabbitMQNative"/>
</sequence>
</target>
</clone>
</sequence>
this is the sequence calling onError sequence
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XXXXNotifySendSequence"
onError="XXXXNotifyErrorSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="XXXX" value="request start"/>
</log>
<enrich>
<source clone="true" type="envelope"/>
<target property="mssg" type="property"/>
</enrich>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<call>
<endpoint key="HTTPEndpoint"/>
</call>
<log level="full">
<property name="XXXX" value="request end"/>
</log>
</sequence>
I am not much sure why you written fault sequence in that way. but when i change like bellow its working. no need to enrich and assign to other property
Sequence:(same as yours - untouched)
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XXXXNotifySendSequence"
onError="XXXXNotifyErrorSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="XXXX" value="request start"/>
</log>
<enrich>
<source clone="true" type="envelope"/>
<target action="replace" property="mssg" type="property"/>
</enrich>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<call>
<endpoint key="HTTPEndpoint"/>
</call>
<log level="full">
<property name="XXXX" value="request end"/>
</log>
</sequence>
fault sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XXXXNotifyErrorSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log>
<property expression="get-property('ERROR_CODE')"
name="========error-code=========" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="get-property('ERROR_MESSAGE')"
name="========error-message=========" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<makefault version="soap11">
<code value="soap11Env:VersionMismatch" xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/"/>
<reason expression="get-property('ERROR_MESSAGE')" xmlns:ns="http://org.apache.synapse/xsd"/>
<role>sample</role>
<detail>sample detail</detail>
</makefault>
<send/>
</sequence>
proxy: to call sequence
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="samplecall"
transports="http,https"
statistics="disable"
trace="disable"
startOnLoad="true">
<target inSequence="XXXXNotifySendSequence"/>
<description/>
</proxy>
response: (since end point is not defined)
<soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/">soap11Env:VersionMismatch</faultcode>
<faultstring>Couldn't find the endpoint with the key : HTTPEndpoint</faultstring>
<faultactor>sample</faultactor>
<detail>sample detail</detail>
</soapenv:Fault>
in log:
2015-11-08 17:19:55,250] INFO - LogMediator To: /services/samplecall.samplecallHttpSoap11Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:106d763f-cdc1-43d2-98a9-63d22d17eb81, Direction: request, XXXX = request start, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
[2015-11-08 17:19:55,252] INFO - LogMediator To: /services/samplecall.samplecallHttpSoap11Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:106d763f-cdc1-43d2-98a9-63d22d17eb81, Direction: request, ========error-code========= = 305100, ========error-message========= = Couldn't find the endpoint with the key : HTTPEndpoint
I am working on sample application in WSO2 esb
which connects to Oracle Database and return the response of a query. Below mentioned is my service. Issue I am facing is I am not getting the response back after execution of service.However I am able to see the value returned as a query response, but not able to render it in response document.
Can anybody suggest, what I am missing?
DB credentials fields have been hashed.
Proxy :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="getEmployeeDetails"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true" scope="default" type="BOOLEAN"/>
<log level="full" category="DEBUG"/>
<dblookup>
<connection>
<pool>
<password>****</password>
<user>****</user>
<url>****</url>
<driver>oracle.jdbc.xa.client.OracleXADataSource</driver>
</pool>
</connection>
<statement>
<sql>select firstname from employee where lastname = 'pawar'</sql>
<result name="firstname" column="firstname"/>
</statement>
</dblookup>
<log level="custom">
<property name="firstname" expression="get-property('firstname')"/>
</log>
<payloadFactory media-type="xml">
<format>
<GetEmployeeDetailsResponse xmlns="">
<out>$1</out>
</GetEmployeeDetailsResponse>
</format>
<args>
<arg evaluator="xml" expression="get-property('firstname')"/>
</args>
</payloadFactory>
</inSequence>
<outSequence>
<log level="full" category="DEBUG"/>
</outSequence>
</target>
<publishWSDL uri="file:/development/data/wso2/wsdl/Employee.wsdl"/>
<description/>
</proxy>
You have to send back the message generated by your payloadFactory in your inSequence :
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<send/>
Your mediation is "OUT_ONLY", so, your outSequence will never been executed
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