Unexpected behavior from wso2 esb during soap to rest conversion - web-services

I have built a proxy service with WSO2 ESB and i want to use it to expose a REST webservice (from some random vendor) as a SOAP webservice to another random vendor. The issue that im having trouble with is that one of the soap methods simply didnt worked. The method in question is "myVendorBpmInsereCliente". What i find really confusing is that the method "myVendorBpmAtualizaCliente" which is pretty much the same thing does work! Im getting error code 405 (http reponse code) because the property mediator "REST_URL_POSTFIX" doesnt seem to append the rest of the path to the uri.
The sequence:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="cadastroMyVendor" transports="https,http" statistics="enable" trace="enable" startOnLoad="true">
<target>
<inSequence>
<property name="request_action" expression="get-property('Action')"/>
<switch source="get-property('request_action')">
<case regex="myVendorBpmConsultaPeriodo">
<property name="chave" value="myKey" scope="default" type="STRING"/>
<property name="datainicio" expression="//datainicio" scope="default" type="STRING"/>
<property name="datafim" expression="//datafim" scope="default" type="STRING"/>
<property name="queryparams" expression="fn:concat('consulta/periodo?chave=',get-property('chave'))" scope="default" type="STRING"/>
<property name="queryparams" expression="fn:concat(get-property('queryparams'),'&datainicio=')" scope="default" type="STRING"/>
<property name="queryparams" expression="fn:concat(get-property('queryparams'),get-property('datainicio'))" scope="default" type="STRING"/>
<property name="queryparams" expression="fn:concat(get-property('queryparams'),'&datafim=')" scope="default" type="STRING"/>
<property name="queryparams" expression="fn:concat(get-property('queryparams'),get-property('datafim'))" scope="default" type="STRING"/>
<property name="REST_URL_POSTFIX" expression="get-property('queryparams')" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<log level="full"/>
<case regex="myVendorBpmInsereCliente">
<property name="chave" value="myKey" scope="default" type="STRING"/>
<property name="queryparams" expression="fn:concat('cliente/novo?chave=',get-property('chave'))" scope="default" type="STRING"/>
<property name="REST_URL_POSTFIX" expression="get-property('queryparams')" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<xslt key="conf:/repository/scripts/dropTheSoap.xsl"/>
</case>
<case regex="myVendorBpmAtualizaCliente">
<property name="chave" value="myKey" scope="default" type="STRING"/>
<property name="queryparams" expression="fn:concat('cliente/atualiza?chave=',get-property('chave'))" scope="default" type="STRING"/>
<property name="REST_URL_POSTFIX" expression="get-property('queryparams')" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="PUT" scope="axis2" type="STRING"/>
<xslt key="conf:/repository/scripts/dropTheSoap.xsl"/>
</case>
<default>
<!-- code omitted -->
</default>
</switch>
<send>
<endpoint key="gov:/trunk/endpoints/myKey"/>
<address uri="http://somehost:8080/STL-WS/myVendor/" format="pox"/>
<endpoint key="gov:/trunk/endpoints/myKey"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<description></description>
This is what i got from wso2-esb-trace:
16:26:51,090 [-] [HttpClientWorker-10] INFO TRACE_LOGGER End : Send mediator
16:26:51,090 [-] [HttpClientWorker-10] INFO TRACE_LOGGER End : Sequence <anonymous>
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Proxy Service cadastro_myVendor received a new message from : 127.0.0.1
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Message To: /services/cadastro_myVendor
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER SOAPAction: myVendorBpmInsereCliente
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER WSA-Action: myVendorBpmInsereCliente
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Using the anonymous in-sequence of the proxy service for mediation
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Start : Sequence <anonymous>
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Sequence <SequenceMediator> :: mediate()
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Start : Property mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Setting property : request_action at scope : default to : myVendorBpmInsereCliente (i.e. result of expression : get-property('Action'))
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER End : Property mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Start : Switch mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER XPath : get-property('request_action') evaluates to : myVendorBpmInsereCliente
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Matching case found : myVendorBpmInsereCliente
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Sequence <AnonymousListMediator> :: mediate()
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Start : Property mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Setting property : chave at scope : default to : myKey (i.e. constant : myKey)
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER End : Property mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Start : Property mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Setting property : queryparams at scope : default to : cliente/novo?chave=myKey (i.e. result of expression : fn:concat('cliente/novo?chave=',get-property('chave')))
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER End : Property mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Start : Property mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Setting property : REST_URL_POSTFIX at scope : axis2 to : cliente/novo?chave=myKey (i.e. result of expression : get-property('queryparams'))
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER End : Property mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Start : XSLT mediator
16:26:51,324 [-] [HttpServerWorker-15] WARN TRACE_LOGGER Warning encountered during stylesheet parsing : javax.xml.transform.TransformerConfigurationException: The attribute axis starting at an attribute node will never select anything
16:26:51,324 [-] [HttpServerWorker-15] WARN TRACE_LOGGER Warning encountered during stylesheet parsing : javax.xml.transform.TransformerConfigurationException: The child axis starting at an attribute node will never select anything
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER output method: xml; encoding: ISO-8859-1
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Using org.apache.synapse.util.jaxp.StreamSourceBuilder
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Using org.apache.synapse.util.jaxp.StreamResultBuilder
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Transformation completed - processing result
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Replace node with result
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER End : XSLT mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Start : Property mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Setting property : HTTP_METHOD at scope : axis2 to : POST (i.e. constant : POST)
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER End : Property mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Start : Send mediator
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER Sending message through endpoint : gov//trunk/endpoints/myVendor resolving to address = http://somehost:8080/STL-WS/myVendor/
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER SOAPAction: myVendorBpmInsereCliente
16:26:51,324 [-] [HttpServerWorker-15] INFO TRACE_LOGGER WSA-Action: myVendorBpmInsereCliente
16:26:51,340 [-] [HttpServerWorker-15] INFO TRACE_LOGGER End : Send mediator
16:26:51,340 [-] [HttpServerWorker-15] INFO TRACE_LOGGER End : Sequence <anonymous>
16:26:51,355 [-] [HttpClientWorker-11] INFO TRACE_LOGGER Start : Sequence <anonymous>
16:26:51,355 [-] [HttpClientWorker-11] INFO TRACE_LOGGER Sequence <SequenceMediator> :: mediate()
16:26:51,371 [-] [HttpClientWorker-11] ERROR TRACE_LOGGER Error while building message_
During another attempt, i added a custom log mediator to log the value of the expression: $axis2:REST_URL_POSTFIX and the result was what i expected: "cliente/novo?chave=myKey". Note that i changed the endpoint in the sequence for ilustrative purposes. Im using WSO2 ESB Version 4.6.0, running as a service. Any sugestions?

Could you please change the endpoint format to rest and check whether that solves the issue.

Related

Why I cant' extract the field values of objects iterating on a JSON document using WSO2 ESB?

I am working on a WSO2 ESB project and I am finding the following difficulties:
I have a JSON document like this:
{
"forecast_1": {
"country": "Rwanda",
"forecast_date": "2018-03-20",
"province": "Kigali City",
"district": "Kigali",
"morning": {
"min_temp": 14,
"status": "Sun with right rain",
"max_temp": 16,
"humidity": "",
"wind_direction": "",
"wind_force": "",
"description": "Lorem ipsum"
},
"afternoon": {
"min_temp": 24,
"status": "Dark cloud with rain",
"max_temp": 28,
"humidity": "",
"wind_direction": "",
"wind_force": "",
"description": "Lorem ipsum"
}
},
"forecast_2": {
"country": "Rwanda",
"forecast_date": "2018-03-25",
"province": "Kigali",
"district": "Kigali",
"morning": {
"min_temp": 21,
"status": "Rain showers",
"max_temp": 21,
"humidity": "",
"wind_direction": "",
"wind_force": "",
"description": "There will be heavy rain"
},
"afternoon": {
"min_temp": 32,
"status": "Rain showers",
"max_temp": 32,
"humidity": "",
"wind_direction": "",
"wind_force": "",
"description": "There will be heavy rain with thunder"
}
}
}
Unfortunately this JSON document doesn't contains an array of objects but contains some forecast_XXX objects, where XXX will change.
I have to iterate on each forecast_XXX objects (the first level objects) defined into this JSON document and extracts the values of the fields.
To iterate on these "first level" objects I am doing in this way (and it seems to work):
<foreach id="foreach_1" expression="//*[starts-with(name(), 'forecast_')]" xmlns:m0="http://services.samples">
<sequence>
<log description="Log" level="custom">
<property name="iteration" value="ITERATION !!!"/>
</log>
<enrich>
<source clone="true" xpath="/country/text()"/>
<target property="test" type="property"/>
</enrich>
<log description="Log" level="custom">
<property expression="$ctx:test" name="test"/>
</log>
<log level="full"/>
</sequence>
</foreach>
The iteration seems to works because in my WSO2 logs I obtain:
TID: [-1234] [] [2018-03-29 13:51:50,271] INFO {org.apache.synapse.mediators.builtin.LogMediator} - iteration = ITERATION !!! {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2018-03-29 13:51:50,271] ERROR {org.apache.synapse.mediators.elementary.EnrichMediator} - Specified node by xpath cannot be found. {org.apache.synapse.mediators.elementary.EnrichMediator}
TID: [-1234] [] [2018-03-29 13:51:50,272] INFO {org.apache.synapse.mediators.builtin.LogMediator} - test = {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2018-03-29 13:51:50,272] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /meteo/forecast, MessageID: urn:uuid:21779fb7-6ce6-4e90-a9cb-4187dab8988b, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><forecast_date>2018-03-20</forecast_date></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2018-03-29 13:51:50,272] INFO {org.apache.synapse.mediators.builtin.LogMediator} - iteration = ITERATION !!! {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2018-03-29 13:51:50,272] ERROR {org.apache.synapse.mediators.elementary.EnrichMediator} - Specified node by xpath cannot be found. {org.apache.synapse.mediators.elementary.EnrichMediator}
TID: [-1234] [] [2018-03-29 13:51:50,273] INFO {org.apache.synapse.mediators.builtin.LogMediator} - test = {org.apache.synapse.mediators.builtin.LogMediator}
So, as you can see, I have 2 logs related to the current iteration, something lie this:
TID: [-1234] [] [2018-03-29 13:51:50,271] INFO {org.apache.synapse.mediators.builtin.LogMediator} - iteration = ITERATION !!! {org.apache.synapse.mediators.builtin.LogMediator}
But now I am finding some difficulties to extract the field values related to the current object iteration.
I tried to do in this way:
<enrich>
<source clone="true" xpath="/country/text()"/>
<target property="test" type="property"/>
</enrich>
<log description="Log" level="custom">
<property expression="$ctx:test" name="test"/>
</log>
but, as you can see in the log, the enrich mediato go into error and the "test" property will contain no value:
TID: [-1234] [] [2018-03-29 13:51:50,271] ERROR {org.apache.synapse.mediators.elementary.EnrichMediator} - Specified node by xpath cannot be found. {org.apache.synapse.mediators.elementary.EnrichMediator}
TID: [-1234] [] [2018-03-29 13:51:50,272] INFO {org.apache.synapse.mediators.builtin.LogMediator} - test = {org.apache.synapse.mediators.builtin.LogMediator}
So what is wrong? Why the XPATH expression is wrong? How can I correctly extracts the field values of the current iteration object? (I am not so sure that using the enrich mediator is the best choice).
Using xpath as follows worked for me.
//*/country
Here is the enrich mediator:
<enrich>
<source clone="true" xpath="//*/country"/>
<target property="test" type="property"/>
</enrich>
Result:
[2018-04-02 12:41:03,252] [EI-Core] INFO - LogMediator iteration = ITERATION !!!
[2018-04-02 12:41:03,252] [EI-Core] INFO - LogMediator test = Rwanda
using //country/text() instead of /country/text() is working for me.

How to Remove charset=utf-8 in WSO2 ESB

I have a requirement to call rest service, which accept "Content-Type: application/json" in header but when I try to call it from ESB. WSO2 adds "charset=utf-8" automatically. I am not sure how to remove it.
I have also used ContentType property but no luck.
<property name="HTTP_METHOD" scope="axis2" type="STRING" value="PUT"/>
<property name="ContentType" scope="axis2" type="STRING" value="application/json"/>
<header expression="fn:concat('Basic ', get-property('ENCODED_URL'))" name="Authorization" scope="transport" xmlns:ns="http://org.apache.synapse/xsd"/>
<payloadFactory media-type="json">
<format>{
"name": "XXX_Token",
"type": "XXXX-cf04186e2156_sessionID",
"version": "1.0.1",
"Attribute-N": $1
}
</format>
<args>
<arg expression="$ctx:XXXTokenValue" literal="false" />
</args>
</payloadFactory>
<property name="REST_URL_POSTFIX" scope="axis2" value=""/>
<call>
<endpoint>
<address trace="disable" uri="https://XXXXX:9493/governance/restservices/52b1caba-b507-4f6a-95bc-2ea7b2418e67"/>
</endpoint>
</call>
Logs:
- End : Call mediator - Non Blocking Call
TID: [-1] [ESB] [2017-09-21 14:30:37,785] DEBUG {org.apache.synapse.transport.http.wire} - << "PUT /governance/restservices/5XXXXX2ea7b2418e67 HTTP/1.1[\r][\n]"
TID: [-1] [ESB] [2017-09-21 14:30:37,785] DEBUG {org.apache.synapse.transport.http.wire} - << "X-AspNet-Version: 4.0.30319[\r][\n]"
TID: [-1] [ESB] [2017-09-21 14:30:37,785] DEBUG {org.apache.synapse.transport.http.wire} - << "Authorization: Basic YWRtaW46YWRtaW4=[\r][\n]"
TID: [-1] [ESB] [2017-09-21 14:30:37,785] DEBUG {org.apache.synapse.transport.http.wire} - << "Content-Type: application/json; charset=utf-8[\r][\n]"
TID: [-1] [ESB] [2017-09-21 14:30:37,785] DEBUG {org.apache.synapse.transport.http.wire} - << "X-Powered-By: ASP.NET[\r][\n]"
TID: [-1] [ESB] [2017-09-21 14:30:37,785] DEBUG {org.apache.synapse.transport.http.wire} - << "Cache-Control: private, max-age=0[\r][\n]"
TID: [-1] [ESB] [2017-09-21 14:30:37,785] DEBUG {org.apache.synapse.transport.http.wire} - << "Transfer-Encoding: chunked[\r][\n]"
TID: [-1] [ESB] [2017-09-21 14:30:37,785] DEBUG {org.apache.synapse.transport.http.wire} - << "Host: XXXXXXz:9493[\r][\n]"
TID: [-1] [ESB] [2017-09-21 14:30:37,785] DEBUG {org.apache.synapse.transport.http.wire} - << "Connection: K
This was a bug in ESB 4.9.0 [1]. This might have fixed in later versions.
Please check whether below property is available in "/repository/conf/passthru-http.properties"
http.headers.preserve=Content-Type
(Note that you can add multiple header values as comma separated list)
Btw use the property "messageType" to set the Content type. Please refer the document on messageType and ContentType from [2]
[1] https://wso2.org/jira/browse/ESBJAVA-4620
[2] https://docs.wso2.com/display/ESB500/Generic+Properties#GenericProperties-messageType

How to call multiple operations of data service in single proxy service of wso2 esb?

I have a data service that contains two queries. One is a select query and the other is an insert query.
How could we call both queries in a single proxy service? Is there any way to call both queries in a single operation or by adding two call mediators in the proxy service?
As I am using call mediator, how can we call different operations? I have tried it by creating two different data services, but it is giving error "Error while building Passthrough stream"
Can any one provide a sample of both?
Source of my Proxy
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="EslSfaOfaCreateSaleOrdersPS"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<call>
<endpoint>
<address format="soap11"
uri="http://10.1.6.175:9763/services/EslSfaExtractSODataService.SOAP11Endpoint/"/>
</endpoint>
</call>
<call>
<endpoint>
<address format="soap11"
uri="http://10.1.6.175:9763/services/EslSfaInsertTempDataService.SOAP11Endpoint/"/>
</endpoint>
</call>
<log level="full"/>
<datamapper config="gov:datamapper/EslSfaOfaCreateSOMapping.dmc"
inputSchema="gov:datamapper/EslSfaOfaCreateSOMapping_inputSchema.json"
inputType="XML"
outputSchema="gov:datamapper/EslSfaOfaCreateSOMapping_outputSchema.json"
outputType="XML"/>
<log level="full"/>
<header/>
<call>
<endpoint>
<address format="soap11"
uri="https://host/soa-infra/services/default/DooDecompReceiveOrderExternalComposite/ReceiveOrderRequestService"/>
</endpoint>
</call>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
<description/>
</proxy>
The error start coming as i aded second call
TID: [-1234] [] [2017-02-25 15:08:36,060] ERROR {org.apache.synapse.transport.passthru.util.RelayUtils} - Error while building Passthrough stream {org.apache.synapse.transport.passthru.util.RelayUtils}
org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found faultstring
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:305)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:252)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createNextOMElement(StAXSOAPModelBuilder.java:234)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:249)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:204)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:154)
at org.apache.axiom.om.impl.AbstractOMMetaFactory.createStAXSOAPModelBuilder(AbstractOMMetaFactory.java:73)
at org.apache.axiom.om.impl.AbstractOMMetaFactory.createSOAPModelBuilder(AbstractOMMetaFactory.java:79)
at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:196)
at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:65)
at org.apache.synapse.transport.passthru.util.DeferredMessageBuilder.getDocument(DeferredMessageBuilder.java:148)
at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:137)
at org.apache.synapse.transport.passthru.util.RelayUtils.buildMessage(RelayUtils.java:100)
at org.apache.synapse.mediators.AbstractListMediator.buildMessage(AbstractListMediator.java:140)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:83)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:260)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.mediateFromContinuationStateStack(Axis2SynapseEnvironment.java:766)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:282)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:554)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:188)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:261)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
TID: [-1234] [] [2017-02-25 15:08:36,065] ERROR {org.apache.synapse.mediators.base.SequenceMediator} - Error while building message {org.apache.synapse.mediators.base.SequenceMediator}
org.apache.axis2.AxisFault: Error while building Passthrough stream
at org.apache.synapse.transport.passthru.util.RelayUtils.handleException(RelayUtils.java:284)
at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:143)
at org.apache.synapse.transport.passthru.util.RelayUtils.buildMessage(RelayUtils.java:100)
at org.apache.synapse.mediators.AbstractListMediator.buildMessage(AbstractListMediator.java:140)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:83)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:260)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.mediateFromContinuationStateStack(Axis2SynapseEnvironment.java:766)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:282)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:554)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:188)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)

API Manager - Send Mediator: "Uncaught exception {org.apache.axis2.transport.base.threads.NativeWorkerPool} java.lang.NumberFormatException: null"

I have 2 API as below and I am trying to invoke API2 from my API1 using SEND mediator but no response is returned and error is printed in logs:
API1 -
URLhttps://localhost:8243/sendtest/1.0/{num}
In Flow Sequence
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="send_mediator_test_in" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="get-property('uri.var.num')" name="uri.var.num" scope="default" type="STRING"/>
<send>
<endpoint>
<http method="get" uri-template="https://localhost:8243/protest/1.0/{uri.var.num}"/>
</endpoint>
</send>
</sequence>
API2 - (Prototyped)
URLhttps://localhost:8243/protest/1.0/{num}
Inline Script
mc.setProperty('CONTENT_TYPE', 'application/json');
var Num = mc.getProperty('uri.var.num');
mc.setPayloadJSON({ "NumberReturn": Num });
Response
{
"NumberReturn": "100"
}
Invoking API1 with below environments works fine and proper response is returned.
OS: Windows 7
Java: 1.7.0_45
WSO2 AM: 2.0.0
But gets error with below environment
OS: Red Hat Enterprise Linux Server release 6.8 (Santiago)
Java: 1.7.0_101
WSO2 AM: 2.0.0
Error while invoking API1
TID: [-1] [] [2017-02-03 06:34:23,265] DEBUG {org.apache.synapse.transport.http.wire} - HTTPS-Sender I/O dispatcher-2 >> "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [-1] [] [2017-02-03 06:34:23,265] DEBUG {org.apache.synapse.transport.http.wire} - HTTPS-Sender I/O dispatcher-2 >> "a4[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [-1] [] [2017-02-03 06:34:23,265] DEBUG {org.apache.synapse.transport.http.wire} - HTTPS-Sender I/O dispatcher-2 >> "0[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [-1] [] [2017-02-03 06:34:23,265] DEBUG {org.apache.synapse.transport.http.wire} - HTTPS-Sender I/O dispatcher-2 >> "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [-1234] [] [2017-02-03 06:34:23,278] ERROR {org.apache.axis2.transport.base.threads.NativeWorkerPool} - Uncaught exception {org.apache.axis2.transport.base.threads.NativeWorkerPool}
java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Long.java:404)
at java.lang.Long.parseLong(Long.java:483)
at org.wso2.carbon.apimgt.gateway.handlers.common.APIMgtLatencyStatsHandler.handleResponse(APIMgtLatencyStatsHandler.java:43)
at org.apache.synapse.rest.API.process(API.java:323)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:90)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:56)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:300)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:554)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:188)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:255)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
TID: [-1234] [] [2017-02-03 06:34:30,750] INFO {org.wso2.andes.server.handler.ChannelCloseHandler} - Received channel close for id 1 citing class 0 and method 0 {org.wso2.andes.server.handler.ChannelCloseHandler}
TID: [-1234] [] [2017-02-03 06:34:30,750] INFO {org.wso2.andes.server.AMQChannel} - No consumers to unsubscribe on channel [/127.0.0.1:53226(admin):1] {org.wso2.andes.server.AMQChannel}
TID: [-1234] [] [2017-02-03 06:34:30,750] INFO {org.wso2.andes.kernel.FlowControlManager} - Channel removed (ID: 127.0.0.1:53226) {org.wso2.andes.kernel.FlowControlManager}
TID: [-1234] [] [2017-02-03 06:34:30,752] INFO {org.wso2.andes.server.handler.ConnectionCloseMethodHandler} - ConnectionClose received with reply code/reply text 200/JMS client is closing the connection. for /127.0.0.1:53226(admin) {org.wso2.andes.server.handler.ConnectionCloseMethodHandler}
Please advise what is wrong.
This is a known issue in APIM 2.0.0 and is fixed in 2.1.0
This happens with prototype APIs or other APIs which does not have APIAuthenticationHandler, when you have analytics enabled. Maybe you have enable analytics in your Windows setup only.
As a workaround, put
<property expression="get-property('SYSTEM_TIME')" name="api.ut.backendRequestTime"/>
inside inSequence of your prototype API, like this.
<inSequence>
<script language="js">your-js-goes-here</script>
<property expression="get-property('SYSTEM_TIME')" name="api.ut.backendRequestTime"/>
...
...
<inSequence>

WSO2 Proxy Service "InSequence" incorrectly sending a request instead of a response for API

I am experiencing an issue within my In Sequnce of the following proxy :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="AckServiceAPIProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="json-xml" value="text/xml" scope="axis2" type="STRING"/>
<log level="full" category="DEBUG" separator="____:____"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="name"
expression="//productSearch/productName/text()"
scope="default"
type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="size"
expression="//productSearch/productSize/text()"
scope="default"
type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="colour"
expression="//productSearch/productColour/text()"
scope="default"
type="STRING"/>
<payloadFactory media-type="xml">
<format>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ack="http://ack.pepkor.org">
<soap:Header/>
<soap:Body>
<ack:productSearch>
<ack:productName>$1</ack:productName>
<ack:productSize>$2</ack:productSize>
<ack:productColour>$3</ack:productColour>
</ack:productSearch>
</soap:Body>
</soap:Envelope>
</format>
<args>
<arg xmlns:ns="http://org.apache.synapse/xsd"
expression="$ctx:name"
evaluator="xml"/>
<arg xmlns:ns="http://org.apache.synapse/xsd"
expression="$ctx:size"
evaluator="xml"/>
<arg xmlns:ns="http://org.apache.synapse/xsd"
expression="$ctx:colour"
evaluator="xml"/>
</args>
</payloadFactory>
<log level="full" category="DEBUG" separator="____:____"/>
<send>
<endpoint key="conf:/ackServiceEpr"/>
</send>
</inSequence>
<outSequence>
<log level="full" category="DEBUG" separator="____:____"/>
<property name="messageType"
value="application/json"
scope="axis2"
type="STRING"/>
<log level="full" category="DEBUG" separator="____:____"/>
<send/>
</outSequence>
<faultSequence/>
</target>
<description/>
</proxy>
The REST request :
{ "productSearch":
{ "productName": "nike_shirts" ,
"productSize": "7",
"productColour": "red"
}
}
Let me break down the log :
TID: [0] [ESB] [2015-02-03 11:56:14,994] DEBUG {org.apache.synapse.commons.json.JsonStreamBuilder} - #processDocument. Built JSON payload from JSON stream. MessageID: urn:uuid:0d62c4ad-01b5-4eb5-ae7e-3b3aee762fbf {org.apache.synapse.commons.json.JsonStreamBuilder}
...
#mediate. Transformed payload format>>>
<pfPadding>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ack="http://ack.pepkor.org"><soap:Header></soap:Header><soap:Body><ack:productSearch><ack:productName>nike_shirts</ack:productName><ack:productSize>7</ack:productSize><ack:productColour>red</ack:productColour></ack:productSearch></soap:Body></soap:Envelope></pfPadding>
So I would expect the above message to be sent to the Ack Service (on Application Server) , however , INSIDE the SEND mediator , it then tranforms the original request payload(REST) again , and instead sends this to the service :
<productSearch><productName>nike_shirts</productName><productSize>7</productSize><productColour>red</productColour></productSearch>
The service call fails because of no namespaces , and brings back a fault.
The send mediator full log :
Start : Send mediator {org.apache.synapse.mediators.builtin.SendMediator}
TID: [0] [ESB] [2015-02-03 12:08:34,896] DEBUG {org.apache.synapse.endpoints.EndpointContext} - Checking if endpoint : AnonymousEndpoint currently at state ACTIVE can be used now? {org.apache.synapse.endpoints.EndpointContext}
TID: [0] [ESB] [2015-02-03 12:08:34,896] DEBUG {org.apache.synapse.endpoints.AddressEndpoint} - Sending message through endpoint : null resolving to address = https://localhost:9444/services/ProductSearchACKService.ProductSearchACKServiceHttpsSoap12Endpoint/ {org.apache.synapse.endpoints.AddressEndpoint}
TID: [0] [ESB] [2015-02-03 12:08:34,896] DEBUG {org.apache.synapse.endpoints.AddressEndpoint} - SOAPAction: null {org.apache.synapse.endpoints.AddressEndpoint}
TID: [0] [ESB] [2015-02-03 12:08:34,897] DEBUG {org.apache.synapse.endpoints.AddressEndpoint} - WSA-Action: null {org.apache.synapse.endpoints.AddressEndpoint}
TID: [0] [ESB] [2015-02-03 12:08:34,897] DEBUG {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient} - Sending [add = false] [sec = false] [rm = false] [mtom = false] [swa = false] [format = null] [force soap11=false] [force soap12=false] [pox=false] [get=false] [encoding=null] [to=https://localhost:9444/services/ProductSearchACKService.ProductSearchACKServiceHttpsSoap12Endpoint/] {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient}
TID: [0] [ESB] [2015-02-03 12:08:34,898] DEBUG {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient} - Message [Original Request Message ID : urn:uuid:a451c7d8-b5a9-4474-8bd3-af9a25b65933] [New Cloned Request Message ID : urn:uuid:b0540f15-2094-4c3e-9184-fdc2df2fd491] {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient}
TID: [0] [ESB] [2015-02-03 12:08:34,898] DEBUG {org.apache.synapse.core.axis2.SynapseCallbackReceiver} - Callback added. Total callbacks waiting for : 1 {org.apache.synapse.core.axis2.SynapseCallbackReceiver}
TID: [0] [ESB] [2015-02-03 12:08:34,900] DEBUG {org.apache.synapse.commons.json.JsonUtil} - #transformElement. Transformed OMElement. Result: <productSearch><productName>nike_shirts</productName><productSize>7</productSize><productColour>red</productColour></productSearch> {org.apache.synapse.commons.json.JsonUtil}
TID: [0] [ESB] [2015-02-03 12:08:34,901] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #XmlReaderDelegate. Setting XMLStreamReader: com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,902] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSearch, new=productSearch {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,903] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productName, new=productName {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,903] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productName, new=productName {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,904] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSize, new=productSize {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,904] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSize, new=productSize {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,904] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productColour, new=productColour {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,905] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productColour, new=productColour {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,905] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSearch, new=productSearch {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,905] DEBUG {org.apache.synapse.commons.json.JsonStreamFormatter} - #writeTo. Wrote JSON payload to output stream. MessageID: urn:uuid:b0540f15-2094-4c3e-9184-fdc2df2fd491 {org.apache.synapse.commons.json.JsonStreamFormatter}
TID: [0] [ESB] [2015-02-03 12:08:34,906] DEBUG {org.apache.synapse.mediators.builtin.SendMediator} - End : Send mediator
.
Your proxy receive a JSON request and you don't specify anything for the output so, the ESB send a JSON request to your ack service (see log trace #writeTo. Wrote JSON payload to output stream. MessageID: urn:uuid:b0540f15-2094-4c3e-9184-fdc2df2fd491 {org.apache.synapse.commons.json.JsonStreamFormatter})
If you want to send a SOAP request, you can specify attribute format="soap11" in your endpoint def (ackServiceEpr) or add a property in your inSequence, before send :
<property name="messageType" value="text/xml" scope="axis2"/>
Perhaps do you need to set the SOAPAction in this case, use header mediator. If you want to set a blank one :
<header name="Action" value=""""/>
If your ack service need plain xml, use application/xml