WSO2 ESB payload factory XML Exception - wso2

Lately any attempt to call API resources on my ESB has resulted in an XML exception (stack trace below) when run by the payloadFactory. Removing the payloadFactory in its entirety seems to be the only way to resolve this. I can have no args, empty format, or completely static args and format in ways that should work, and did work yesterday!
The build is on ESB 5.0.0 and an example of such a resource looks like this:
<resource methods="POST" uri-template="/someUrl">
<inSequence>
<property name="acceptedRoles" value="RMD" scope="default" type="STRING/>
<property name="myProp" value="json-eval($)" scope="default" type="STRING"/>
<Package.ConnectorOne/>
<Package.ConnectorTwo/>
<loopback/>
</inSequence>
<outSequence>
<payloadFactory media-type="json">
<format>{"statusCode":$1,"errorMessage":"$2","errors":$3}</format>
<args>
<arg evaluator="xml" expression="get-property('statusCode')/>
<arg evaluator="xml" expression="get-property('errorMessage')/>
<arg evaluator="xml" expression="get-property('errors')/>
</args>
<payloadFactory>
<send/>
</outSequence>
<faultSequence/>
</resource>
Exception stack traces:
TID[-1234] [ESB] [2017-03-21 19:22:33,024] ERROR
{API_LOGGER.FleetManagement} - javax.xml.stream.XMLStreamException:
Unexpected symbol: START_OBJECT
org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
org.apache.axiom.om.impl.llom.OMElementImpl.buildNext(OMElementImpl.java:653
)
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.buildNext(OMSourcedElemen
tImpl.java:880)
org.apache.axiom.om.impl.llom.OMNodeImpl.getNextOMSibling(OMNodeImpl.java:12
2)
org.apache.axiom.om.impl.llom.OMElementImpl.getNextOMSibling(OMElementImpl.j
ava:343)
org.apache.axiom.om.impl.traverse.OMChildrenIterator.getNextNode(OMChildrenI
terator.java:36)
org.apache.axiom.om.impl.traverse.OMAbstractIterator.hasNext(OMAbstractItera
tor.java:58)
org.apache.synapse.commons.json.JsonUtil.removeIndentations(JsonUtil.java:41
8)
org.apache.synapse.commons.json.JsonUtil.removeIndentations(JsonUtil.java:42
5)
org.apache.synapse.commons.json.JsonUtil.getNewJsonPayload(JsonUtil.java:587
)
org.apache.synapse.commons.json.JsonUtil.getNewJsonPayload(JsonUtil.java:654
)
org.apache.synapse.mediators.transform.PayloadFactoryMediator.mediate(Payloa
dFactoryMediator.java:173)
org.apache.synapse.mediators.transform.PayloadFactoryMediator.mediate(Payloa
dFactoryMediator.java:104)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:97)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:59)
org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.
java:158) org.apache.synapse.rest.Resource.process(Resource.java:343)
org.apache.synapse.rest.API.process(API.java:338)
org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.jav
a:123)
org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.
java:101)
org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:5
6)
org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2Syn
apseEnvironment.java:304)
org.apache.synapse.mediators.builtin.LoopBackMediator.mediate(LoopBackMediat
or.java:63)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:97)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:59)
org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.
java:158) org.apache.synapse.rest.Resource.process(Resource.java:343)
org.apache.synapse.rest.API.process(API.java:399)
org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.jav
a:123)
org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.
java:101)
org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:6
9)
org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2Syn
apseEnvironment.java:304)
org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageR
eceiver.java:75)
org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosing
RESTHandler(ServerWorker.java:325)
org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingReq
uest(ServerWorker.java:371)
org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:151
)
org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerP
ool.java:172) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown
Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
And
javax.xml.stream.XMLStreamException: Unexpected symbol: START_OBJECT
org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
org.apache.axiom.om.impl.llom.OMElementImpl.buildNext(OMElementImpl.java:653
)
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.buildNext(OMSourcedElemen
tImpl.java:880)
org.apache.axiom.om.impl.llom.OMNodeImpl.getNextOMSibling(OMNodeImpl.java:12
2)
org.apache.axiom.om.impl.llom.OMElementImpl.getNextOMSibling(OMElementImpl.j
ava:343)
org.apache.axiom.om.impl.traverse.OMChildrenIterator.getNextNode(OMChildrenI
terator.java:36)
org.apache.axiom.om.impl.traverse.OMAbstractIterator.hasNext(OMAbstractItera
tor.java:58)
org.apache.synapse.commons.json.JsonUtil.removeIndentations(JsonUtil.java:41
8)
org.apache.synapse.commons.json.JsonUtil.removeIndentations(JsonUtil.java:42
5)
org.apache.synapse.commons.json.JsonUtil.getNewJsonPayload(JsonUtil.java:587
)
org.apache.synapse.commons.json.JsonUtil.getNewJsonPayload(JsonUtil.java:654
)
org.apache.synapse.mediators.transform.PayloadFactoryMediator.mediate(Payloa
dFactoryMediator.java:173)
org.apache.synapse.mediators.transform.PayloadFactoryMediator.mediate(Payloa
dFactoryMediator.java:104)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:97)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:59)
org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.
java:158) org.apache.synapse.rest.Resource.process(Resource.java:343)
org.apache.synapse.rest.API.process(API.java:338)
org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.jav
a:123)
org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.
java:101)
org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:5
6)
org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2Syn
apseEnvironment.java:304)
org.apache.synapse.mediators.builtin.LoopBackMediator.mediate(LoopBackMediat
or.java:63)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:97)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:59)
org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.
java:158) org.apache.synapse.rest.Resource.process(Resource.java:343)
org.apache.synapse.rest.API.process(API.java:399)
org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.jav
a:123)
org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.
java:101)
org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:6
9)
org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2Syn
apseEnvironment.java:304)
org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageR
eceiver.java:75)
org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosing
RESTHandler(ServerWorker.java:325)
org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingReq
uest(ServerWorker.java:371)
org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:151
)
org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerP
ool.java:172) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown
Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

I guess the problem is the expression type in the payload factory mediator while passing the arguments to the json.
*<payloadFactory media-type="json">
<format>{"statusCode":$1,"errorMessage":"$2","errors":$3}</format>
<args>
<***arg evaluator="xml"*** expression="get-property('statusCode')/>
<arg evaluator="xml" expression="get-property('errorMessage')/>
<arg evaluator="xml" expression="get-property('errors')/>
</args>
<payloadFactory>*
change the value of arg evaluator="xml" expression="get-property('statusCode') from xml to arg evaluator="json" expression="get-property('statusCode')json and give it a try. I believe the exception is due to parsing xml as json.
Comment if the error isn't resolved.
Thanks

Perhaps the arguments you are trying to inject into the json payload are not either an int or a boolean , which would cause a parsing exception.
Try this :
<payloadFactory media-type="json">
<format>{"statusCode":"$1","errorMessage":"$2","errors": "$3"}</format>
<args>
<arg evaluator="xml" expression="get-property('statusCode')/>
<arg evaluator="xml" expression="get-property('errorMessage')/>
<arg evaluator="xml" expression="get-property('errors')/>
</args>
<payloadFactory>
To see what is happening in detail during mediation , try setting the synapse logger (org.apache.synapse) and wire log to DEBUG.

Related

Transforming XML to JSON in WSO Api manager 3.2 using Script Mediator

Description : I am trying to transform from xml to json using script mediator in wso2 3.2 api manager. The issue which I am facing is the script mediator method getPayloadXML() is not able to pull out a specific value from xml where it always returns as ReferenceError: "code" is not defined. I tried multiple things but couldn't figure out how to achieve this. Any help from someone would be really appreciable.
Response Mediation
<sequence xmlns="http://ws.apache.org/ns/synapse" name="transform">
<script language="js"><![CDATA[
var envelope = mc.getPayloadXML()..*::fault-code.toString()
var request ={"data":{"success":"true","message":"SuccessFull","faultcode":envelope}};
mc.setPayloadJSON(request);
]]></script>
<log level="full">
<property name="Message" value="UpdatedMessage"/>
</log>
<property name="HTTP_SC" value="200" scope="axis2" />
<property name="messageType" value="application/json" scope="axis2"/>
</sequence>
Original Response
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsa:MessageID>210419-BA7CF-32444</wsa:MessageID>
<wsa:RelatesTo>Test123456</wsa:RelatesTo>
<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
<wsa:From>
<wsa:Address>some data</wsa:Address>
</wsa:From>
<wsa:Action>some data</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<cbo:response xmlns:abr="url" xmlns:asic="url" client-reference1="A1" response-type="error" version="1.2">
<cbo:error>
<cbo:fault-code>CBOX017</cbo:fault-code>
<cbo:fault-string>User account is inactive.</cbo:fault-string>
<cbo:fault-actor/>
<cbo:detail/>
</cbo:error>
</cbo:response>
</soapenv:Body>
</soapenv:Envelope>
Expected Response (Transform To JSON)
{
"data": {
"success": "true",
"message": "SuccessFull",
"faultcode":CBOX017
}
}
Error Logs
TID: [-1234] [] [2021-04-19 16:14:41,259] ERROR {org.apache.synapse.mediators.bsf.ScriptMediator} - {api:admin--equifaxACNCheck:v1.0.0} The script engine returned an error executing the inlined js script function mediate com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "code" is not defined. (<Unknown Source>#2) in <Unknown Source> at line number 2
at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:68)
at javax.script.CompiledScript.eval(CompiledScript.java:92)
at org.apache.synapse.mediators.bsf.ScriptMediator.mediateForInlineScript(ScriptMediator.java:395)
at org.apache.synapse.mediators.bsf.ScriptMediator.invokeScript(ScriptMediator.java:290)
at org.apache.synapse.mediators.bsf.ScriptMediator.mediate(ScriptMediator.java:258)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler.mediate_aroundBody0(APIManagerExtensionHandler.java:73)
at org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler.mediate(APIManagerExtensionHandler.java:58)
at org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler.handleResponse_aroundBody4(APIManagerExtensionHandler.java:132)
at org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler.handleResponse(APIManagerExtensionHandler.java:120)
at org.apache.synapse.rest.API.process(API.java:371)
at org.apache.synapse.rest.RESTRequestHandler.apiProcessNonDefaultStrategy(RESTRequestHandler.java:144)
at org.apache.synapse.rest.RESTRequestHandler.identifyAPI(RESTRequestHandler.java:164)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:90)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:60)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:331)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:583)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:197)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:285)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "code" is not defined. (<Unknown Source>#2)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3687)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3665)
at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3750)
at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1728)
at org.mozilla.javascript.gen._Unknown_Source__2233._c_script_0(<Unknown Source>:2)
at org.mozilla.javascript.gen._Unknown_Source__2233.call(<Unknown Source>)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
at org.mozilla.javascript.gen._Unknown_Source__2233.call(<Unknown Source>)
at org.mozilla.javascript.gen._Unknown_Source__2233.exec(<Unknown Source>)
at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:55)
... 25 more
TID: [-1234] [] [2021-04-19 16:14:41,267] ERROR {API_LOGGER.admin--equifaxACNCheck} - The script engine returned an error executing the inlined js script function mediate com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "code" is not defined. (<Unknown Source>#2) in <Unknown Source> at line number 2
at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:68)
at javax.script.CompiledScript.eval(CompiledScript.java:92)
at org.apache.synapse.mediators.bsf.ScriptMediator.mediateForInlineScript(ScriptMediator.java:395)
at org.apache.synapse.mediators.bsf.ScriptMediator.invokeScript(ScriptMediator.java:290)
at org.apache.synapse.mediators.bsf.ScriptMediator.mediate(ScriptMediator.java:258)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler.mediate_aroundBody0(APIManagerExtensionHandler.java:73)
at org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler.mediate(APIManagerExtensionHandler.java:58)
at org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler.handleResponse_aroundBody4(APIManagerExtensionHandler.java:132)
at org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler.handleResponse(APIManagerExtensionHandler.java:120)
at org.apache.synapse.rest.API.process(API.java:371)
at org.apache.synapse.rest.RESTRequestHandler.apiProcessNonDefaultStrategy(RESTRequestHandler.java:144)
at org.apache.synapse.rest.RESTRequestHandler.identifyAPI(RESTRequestHandler.java:164)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:90)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:60)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:331)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:583)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:197)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:285)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "code" is not defined. (<Unknown Source>#2)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3687)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3665)
at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3750)
at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1728)
at org.mozilla.javascript.gen._Unknown_Source__2233._c_script_0(<Unknown Source>:2)
at org.mozilla.javascript.gen._Unknown_Source__2233.call(<Unknown Source>)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
at org.mozilla.javascript.gen._Unknown_Source__2233.call(<Unknown Source>)
at org.mozilla.javascript.gen._Unknown_Source__2233.exec(<Unknown Source>)
at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:55)
... 25 more
It looks like the ScriptMediator has problem with parsing the fault-code. I think it is because the hyphen - already have meaning in JavaScript and in E4X. Maybe you can use alternate mediation with PayloadFactory like below:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="transform">
<payloadFactory media-type="json">
<format>{"data":{"success":"$1", "message":"$2", "faultcode":"$3"}}</format>
<args>
<arg literal="false" value="true"/>
<arg literal="false" value="SuccessFull"/>
<arg evaluator="xml" expression="//*:fault-code"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
<log level="full">
<property name="Message" value="UpdatedMessage"/>
</log>
<property name="HTTP_SC" value="200" scope="axis2" />
</sequence>
The <property name="messageType" value="application/json" scope="axis2"/> shouldn't be needed, because the payload factory should set that.

WSO2 set a property type is string but change to integer

I set a property type is string as below:
<property name="result" scope="default" type="STRING" value="0"/>
<payloadFactory media-type="xml">
<format>
<jsonObject>
<result>$1</result>
</jsonObject>
</format>
<args>
<arg evaluator="xml" expression="$ctx:result"/>
</args>
</payloadFactory>
But the response result is integer.What happened?
{
"result": 0
}
Property value is not a response content. How you make your response body? May be you use payloadFactory?
You can found something about json types in payload https://www.yenlo.com/blog/wso2torial-json-magic-in-wso2-esb-5.0.0 and wso2 esb - problems with XML to JSON conversion
You've specified your payloadFactory to use xml. I am assuming later on, you convert that xml to json.
In xml, there is no concept of "string" vs "integer" - unless you use xsd's - so when the ESB/EI converts the xml to json, it will convert the value to an integer if it sees a number, and a string if it doesn't.
XML -> JSON conversion is not type safe. Can you not use a json payloadFactory:
<payloadFactory media-type="json">
<format>{ "result": "$1" }</format>
<args>
<arg evaluator="xml" expression="$ctx:result"/>
</args>
</payloadFactory>

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

WSO2 ESB cannot obtain url parameters that contains comma

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.

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.