Get data response on WSO2 - wso2

I have received an message response in WSO2 from Endpoint when i send the data. Im newbie in WSO2. Can you show me how to get the value of Job tag (00000559) on message?
Below is received message.
Thanks & Regards,
[2013-08-24 13:25:08,295] INFO - LogMediator To: , WSAction: http://www.abc.com/ns/transaction/Post, SOAPAction: http://www.abc.com/ns/transaction/Post,
MessageID: urn:uuid:1e939de3-3ade-4aea-afdf-9e1defcae760, Direction: response, Envelope: <?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:soap="http:/
/schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><PostResponse
xmlns="http://www.syspro.com/ns/transaction/"><PostResult><?xml version="1.0" encoding="Windows-1252"?>
<postjob Language='05' Language2='EN' CssStyle='' DecFormat='1' DateFormat='01' Role='01' Version='6.1.058' OperatorPrimaryRole=' '>
<Item>
<Job>00000559</Job>
<ItemNumber> 1</ItemNumber>
</Item>
<StatusOfItems>
<ItemsProcessed>1</ItemsProcessed>
<ItemsInvalid>0</ItemsInvalid>
</StatusOfItems>
</postjob>
</PostResult></PostResponse></soap:Body></soap:Envelope>

You can use XPATH expressions to get the value of any tag.
If you need to log the value in job tag, use below in the out sequence
<log>
<property name="VM_LOG" expression="//PostResponse//PostResult//postjob//Item/Job"/>
</log>
If you need to send it as the response, you can simply use the payload factory mediator inside the out sequence
<payloadFactory media-type="xml">
<format>
<results xmlns="">$1</results>
</format>
<args>
<arg evaluator="xml" expression="//PostResponse//PostResult//postjob//Item/Job"/>
</args>
</payloadFactory>
Finally you can add the send mediator.
<send/>
Thanks.

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?

What is exactly doing this payloadFactory mediator?

I am absolutly new in WSO2 and I am working on a WSO2 Enterprise Integrator project containing this ESB project section (I think that my question is only related to ESB).
So my doubt is: I have an XML file defining an API. The flow starts with a payloadFactory mediator, something like this:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/xxxTest2" name="xxxTest2" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<!-- Create empty message to get all samples from DSS -->
<!-- Get Sample ID -->
<payloadFactory media-type="xml">
<format>
<body/>
</format>
<args>
<arg evaluator="xml" expression="get-property('uri.var.int_val')" xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
...............................................................
...............................................................
...............................................................
</api>
This API handle request that I can send using CURL:
curl -v http://MY_SERVER_IP:8280/xxxTest2
Reading the official documentation:
https://docs.wso2.com/display/ESB481/PayloadFactory+Mediator
I know that the payload factory is used to create a content message that have to be sent using something that send an HTTP Request (correct me if this is a wrong assertion).
My doubt is:
the content of this message is empty because it is:
<format>
<body/>
</format>
But it contains this argument defined into the args element:
<args>
<arg evaluator="xml" expression="get-property('uri.var.int_val')" xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd"/>
</args>
So I have 2 doubts:
1) Reading the previous documentation this argument should contain the content value of a $1 variable in the previous payload content (the ... element). But it is empty. It doesn't contain any variable. So why I find this argument?
2) The value of the argument is retrieved with an expression:
expression="get-property('uri.var.int_val')"
What exactly does this expression? What is retrieving?
For passing an argument to Payload factory mediator, you must declare it in the part.
Let's say you are passing an argument 'name' to the payload factory mediator, your source should look like
<payloadFactory media-type="xml" xmlns="http://ws.apache.org/ns/synapse">
<format>
<name_of_the_element xmlns="">$1</name_of_the_element>
</format>
<args>
<arg evaluator="xml"
expression="get-property('uri.var.int_val')" literal="false"/>
</args>
Here, the value of uri.var.int_val will be passed to the element $1. PAyload factory mediator uses positional parameters for its arguments i.e., $1,$2,....$N.
If there is no arguments in the payload you create, you can delete the part in the source. So if your payload is just , then your source will look like,
<payloadFactory media-type="xml">
<format>
<body/>
</format>
</payloadFactory>
The expression expression="get-property('uri.var.int_val')" extracts the value of int_val from the URI parameters.
Thanks

Soap Action error in WSO2 ESB Task configuration

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.