A simple proxy that only adds authentication.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="QueryTestProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Authorization"
expression="fn:concat('Basic ', base64Encode(fn:concat('admin:', wso2:vault-lookup('QueryTest'))))"
scope="transport"
type="STRING"/>
<send>
<endpoint key="conf:/QueryTest"/>
</send>
</inSequence>
<faultSequence>
<send/>
</faultSequence>
</target>
<publishWSDL key="conf:/WSDL/QueryTest.wsdl"/>
<description/>
</proxy>
The endpoint service does a split on CRLF on one of the fields, also the endpoint can not be modified and can't use CDATA.
The problem is that WSO2 ESB always replaces CRLF with LF and the split won't work, does anyone know a way to stop WSO2 ESB to normalize the message?
Axiom uses stax and stax remove those CR in CR-LF
I've had a similar issue when writing text files from a soap message generated like this :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:guid="http://com/cylande/unitedretail/guidedsale/service/common/GuidedSaleManagerService/">
<soapenv:Header/>
<soapenv:Body>
<text xmlns="http://ws.apache.org/commons/ns/payload">my flat datas whith carriage return and line feeds</text>
</soapenv:Body>
</soapenv:Envelope>
We should be able to configure this behavior creating a XMLOutputFactory.properties file inside ESB_HOME, with this content : com.ctc.wstx.outputEscapeCr=false
But in my case, I were not able to start the ESB any more...
(See http://ws.apache.org/axiom/apidocs/org/apache/axiom/om/util/StAXUtils.html for more details)
Here is the javascrip that I've added in my mediation before calling send mediator :
<script language="js"><![CDATA[
try {
var payloadXML = mc.getPayloadXML();
var envelopeXML = mc.getEnvelope();
if (payloadXML != null) {
var text = payloadXML.toString();
if ((envelopeXML != null) && (envelopeXML.getBody() != null) && (envelopeXML.getBody().getFirstElement() != null))
// Do not use mc.setPayloadXML(), it depends on Stax that delete the carriage return we are trying to add...
envelopeXML.getBody().getFirstElement().setText(text.replace(new RegExp('\n','g'),'\r\n'));
}
} catch (e) {
}
]]></script>
Hope you will be able to adapt this script to your need.
ESB's XML parser (AXIOM) is just working according to XML specification
http://www.w3.org/TR/REC-xml/#sec-line-ends
So XML parser must replace CR-LF with LF. This is mentioned in above XML spec .
This is the reason of replacing CRLF with LF in wso2 ESB
Related
In wso2 ESB after calling an endpoint I am getting the response as number(ex: 78) with header application/json, if without processing the response if i send in out sequence it works fine i'll get the same response. But if I include any mediators for processing in between it'll throw exceptions like Could not save JSON payload. Invalid input stream found. A single string or number is not valid in some cases So, it may throwing the exception but this bug is resolved in wso2 EI 6.2.
So now I am able to process the response but if I use script mediator to get that value it shows {}. If i use json-eval($.) then also i am not able to get the value, also with xpath i am not able to get.
So how to get that response(the value in number) for further processing in wso2 ei, by using script mediator or by using json path.
If you are certain that the response only contains a number with the content-type header with application/json. you can take the value to a property as below.
<property name="RESPONSE_NUMBER" expression="//jsonValue" scope="default" type="INTEGER"/>
When you need this value somewhere else in the mediation flow you can take the value from the property(in this case RESPONSE_NUMBER) as below.
$ctx:RESPONSE_NUMBER
Here is a sample API which demonstrates how you can take the response value and use it in the mediation flow.
<api xmlns="http://ws.apache.org/ns/synapse" name="SampleAPI" context="/getNumber">
<resource methods="GET">
<inSequence>
<send>
<endpoint>
<http method="GET" uri-template="http://www.mocky.io/v2/5b02cc2c3000006600cee384"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="RESPONSE_NUMBER" expression="//jsonValue" scope="default" type="INTEGER"/>
<payloadFactory media-type="json">
<format>{"Id": $1}</format>
<args>
<arg evaluator="xml" expression="$ctx:RESPONSE_NUMBER"/>
</args>
</payloadFactory>
<send/>
</outSequence>
</resource>
</api>
You can call the API with below curl command:
curl -v http://localhost:8280/getNumber
We're downgrading our ESB from 5.0.0 to 4.8.1 to match a different development environment and we've hit an unexpected snag: our APIs aren't returning anything.
We were originally using the mediator, which I'm gathering was changed between 4.8.1 and 5.0.0 and cannot in the older version be used as a response so we switched to This is a resource I have set up in an effort to get a smoke test up
<resource methods="GET" uri-template="/StaticTest">
<inSequence>
<log level="full"></log>
<loopback></loopback>
</inSequence>
<outSequence>
<log level="full"></log>
<payloadFactory media-type="json">
<format>{"asdf":"fdsa","blah":3}</format>
<args></args>
</payloadFactory>
<respond></respond>
</outSequence>
</resource>
I know the resource is being hit, because the logging statements make it into the logs. In fact, placing another mediator over the respond tag will display the following
[2017-05-09 15:48:19,968] INFO - LogMediator To: ,
MessageID: urn:uuid:6376072e-d005-497e-b7a1-9f89cff49099,
Direction: response,
Envelope: <?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<jsonObject>
<asdf>fdsa</asdf>
<blah>3</blah>
</jsonObject>
</soapenv:Body>
</soapenv:Envelope>
Which I have taken the liberty of formatting a bit. As you can see a soap envelope has been made matching my static JSON object, but SOAP UI is showing nothing. I get an HTTP 200, but no content. Any idea what could cause this?
When I create proxy with send mediator with Rest service Post HTTP Method in HTTP endpoint url. Selected the endpoint as HTTP endpoint on proxy and post the request xml without soap envelop, this perfectly works and get the response in the response window.
But when I use the call mediator with the same HTTP end point url configuration, this does not works. I would like to know can we use call mediator for Post HTTP method? When I use Call mediator for the GET HTTP method which require only query parameters and does not require any request xml this works absolutely fine.
Here is the further information:
However issue is resloved by using the address endpoint in callmediator. When I Invoke the proxy from external Restt client ot Soap UI, it does works. If I use the Try this Service option in wso2 ESB will fail with the results 1. When Soap12 endpoint is selected and 2 when HTTP end point is selected as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="postIDMPCall"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<organizationList xmlns="">
<xml content>
</organizationList>
</format>
<args/>
</payloadFactory>
<header name="_user" scope="transport" value="username"/>
<header name="_password" scope="transport" value="Password"/>
<call blocking="true">
<endpoint>
<address uri="http://<ip-address>:<port>/<resource-path>/UpdateOrganization"
format="rest"/>
</endpoint>
</call>
</inSequence>
</target>
</proxy>
Output: When soap12 endpoint is selected
Though posted the correct xml service does not recorgonize the correct xml format for soap12 endpoint.
FAILURE
Record is not processed successfully. Please Provide valid Request XML
When Http end point is selected
[2016-04-21 12:07:50,179] INFO - HTTPSender Unable to sendViaPost to url[http://://UpdateOrganization/mediate]
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
I think we can't use call mediator for this purpose because call mediator is context unaware mediator.
Your call should already perform a post out the box.
Did you try to set format="pox" if you expect simple xml as a response
In WSO2 ESB 490 I have wrote the simple API:
<api xmlns="http://ws.apache.org/ns/synapse" name="paramsTest" context="/params">
<resource methods="GET" uri-template="/p?try={params_list}">
<inSequence>
<property name="params_list" expression="get-property('uri.var.params_list')"/>
<log level="full">
<property name="The input params : " expression="get-property('params_list')"/>
</log>
<payloadFactory media-type="json">
<format>{"res_body":"$1"}</format>
<args>
<arg evaluator="xml" expression="get-property('params_list')"/>
</args>
</payloadFactory>
<respond/>
</inSequence>
</resource>
</api>
It work fine when access by URL:
http://localhost:8290/params/p?try=one
and response {"res_body":"one"}
But when access by this URL :
http://localhost:8290/params/p?try=one,two
It response nothing, and it seems ESB didn't process the request because of parameters "try=one,two" separate by comma.
How can make ESB process this URL?(parameters separate by comma)
AFAIK you need to encode the comma with %2C when using with url params.
e.g.
http://localhost:8290/params/p?try=one%2Ctwo
If you get the parameter list via a property you will get %2C encoded values with parameters. Have a look at the working example mentioned below.
<resource methods="POST" uri-template="?sessionId={id}">
<inSequence>
<property name="sessionId" expression="$url:sessionId"/>
Extract parameters one by one as mentioned above.
i have a response from a WS in WSO2 ESB and i write this xml file on a directory on my local machine. I'd like to change the name of the .xml file according to the content. Here is the code of the sequence used for writing file:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="WriteFile">
<property name="transport.vfs.ReplyFileName" value="MyFile.xml" scope="transport"></property>
<property name="OUT_ONLY" value="true"></property>
<send>
<endpoint>
<address uri="vfs:file:///C:\MyFolder"></address>
</endpoint>
</send>
</sequence>
Now i'd like to have MyFile_2.xml if I find "MyFile_2" in a particular tag of the WS response, or MyFile_3.xml if i find "MyFile_3" and so on. I think i must parameterfy my sequence, and particularly value="MyFile.xml" but i don't understand how to do.
EDIT: And what about a SOAP response? I have a SOAP answer like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap..............>
<soap:Body>
<QueryStructureResponse xmlns="..........>
<QueryStructureResult>
<RegistryInterface xmlns="ht............>
<Header>
<ID>IT1001</ID>
<Test>true</Test>
<Name xml:lang="en">MY_FILENAME</Name>
............
I tried in a similar way, but something goes wrong when i want to call my file with MY_FILENAME inside.
Previous REST response manipulation is ok, great answer Jean-Michel .
<property name="transport.vfs.ReplyFileName"
expression="concat('MyFile_',$body/root/child/text(),'.xml')" scope="transport"/>
where $body/root/child/text() is the XPath used to find your particular tag