Soap Action error in WSO2 ESB Task configuration - web-services

I have deployed a WSO2 ESB Proxy Service that works well: it sends a request for a dataset, in the outSequence of the proxy service I send response in a file (I set a sequence for doing it) and i can also visualize response in SOAP UI (or in the "try this service" page of the ESB).
If I set a scheduled task it doesn't work: i set message (my xml right-working message in SOAP UI), injectTo (proxy), proxyName (my proxy name), format (my format) and SoapAction...
I'm sure that the name of SoapAction is correct, but the response of the server is "HTTP header value is not recognized by the server SOAPAction: xxxx" where xxxx is the right soap action name.
This happens with another task i've tried using another simpler proxy service, everything is correct until I use the proxy service within a scheduled task.
I can't understand.

You must be add "soapAction" header like this:
<property name="Code" value="1234"/>
<header name="soapAction" scope="transport" value="http://tempuri.org/MyService/GetAddress"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:GetAddress>
<tem:Code>$1</tem:Code>
</tem:GetAddress>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('Code')"/>
</args>
</payloadFactory>
<send>
<endpoint>
<address format="soap11" uri="http://192.168.1.1/Services/ShakouriService.svc?wsdl"/>
</endpoint>
</send>

Check whether you receive this error in the insequence or the outsequence..
Plus, when you send a response back are you using <send/> or providing a specific endpoint.

Related

WSO2 PayloadFactory mediator not transforming parameters

I am unable to get PayloadFactory mediator to transform input arguments to what the service expects.
I have a requirement to support legacy APIs by looking at input request and providing default values for new parameters or perform data type transformations at the WSO2 layer. For the purpose of PoC, I am trying to send an input argument val while the service expects value but I do not see the input argument correctly reaching the service. Below is the in sequence I am using:
<definitions xmlns="http://ws.apache.org/ns/synapse" name="sample1">
<sequence name="sample1">
<in>
<!-- using payloadFactory mediator to transform the request message -->
<payloadFactory media-type="xml">
<format>
<tem:GetData xmlns:tem="http://localhost/LegacyService/Service1.svc">
<tem:value>$1</tem:value>
</tem:GetData>
</format>
<args>
<arg xmlns:tem="http://localhost/LegacyService/Service1.svc" expression="//tem:val"/>
</args>
</payloadFactory>
</in>
<send/>
</sequence>
</definitions>
Here is the web request that I am making using SOAPUI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:GetData>
<!--Optional:-->
<tem:val>2000</tem:val>
</tem:GetData>
</soapenv:Body>
</soapenv:Envelope>
How can I troubleshoot this?
The namespace in the request and the namespace in the payloadfactory when looking up the value from the request are different. Therefore your expression is searching an element that does not exist in the request.
xmlns:tem="http://localhost/LegacyService/Service1.svc"(payloadFactory argument)
vs
xmlns:tem="http://tempuri.org/"(request message)
You need to make sure the expression in your argument matches the request message
<args>
<arg xmlns:tem="http://tempuri.org/" expression="//tem:val"/>
</args>

In wso2 esb how to get a single number(integer) value

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

WSO2 ESB not returning payloads

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?

WSO2 ESB: Can we use Call Mediator for Rest Service to post (POST HTTP Method) the xml request?

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

Wso2 file upload. connection reset

I developed a SOAP Web Service and Client for file upload (a base64binary string that i want to write on my database) and everithing works fine. I wrote REST api interface with Wso2 ESB and a Rest Client to use my SOAP services with the JSON to XML conversion provided by Wso2 and i succeeded in most of cases.
The problem occurs when i try to upload a base64binary String, obtained from a file grater than 16385 byte (with smaller files works fine) through REST API interface.
After few seconds the connection is reset by the server (Wso2 i think, since my application server doesn't gets the request) and no error is shown other than connection timeout.
I use Apache cxf2 for web service and client generation, Tomcat 8 as apllication server and Wso2 ESB to comunicate with Tomcat.
Here is my Socket Exception in Rest Client
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:102)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:155)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:284)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at rest.RestClient.main(RestClient.java:190)
and the Rest API interface with some censure:
<resource methods="POST"
protocol="https"
uri-template="/loadDoc?user={user}&pwd={pwd}">
<inSequence>
<header name="Action" value="loadDoc"/>
<payloadFactory media-type="xml">
<format>
<m0:loadDoc xmlns:m0="my service location">
<username xmlns="">$1</username><password xmlns="">$2</password>$3
</m0:loadDoc>
</format>
<args>
<arg evaluator="xml" expression="get-property('uri.var.user')"/>
<arg evaluator="xml" expression="get-property('uri.var.pwd')"/>
<arg evaluator="json" expression="$."/>
</args>
</payloadFactory>
<send>
<endpoint>
<address uri="my wsdl location uri"
format="soap12"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
</outSequence>
WSO2 ESB has a default size of the buffer through which data passes.
This default is 16384 bytes.
Go to WSO2_HOME/repository/conf/passthru-http.properties and adjust io_buffer_size property as you need.