I am trying to respond PDFcontent from wso2 esb rest api and want to view in browser. I have enabled the messageFormatter and messageBuilder for application/pdf as well. But when I invoke my api from browser I am getting exception below in wso2 esb.
axis2.xml:
<messageBuilder contentType="application/pdf" class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
<messageFormatter contentType="application/pdf" class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
Exception:
ERROR {org.apache.synapse.transport.passthru.PassThroughHttpSender} - Failed to submit the response {org.apache.synapse.transport.passthru.PassThroughHttpSender}
java.lang.RuntimeException: ContentID is null
at org.apache.axiom.om.impl.llom.OMTextImpl.getDataHandler(OMTextImpl.java:381)
at org.wso2.carbon.relay.ExpandingMessageFormatter.findAndWrite2OutputStream(ExpandingMessageFormatter.java:179)
at org.wso2.carbon.relay.ExpandingMessageFormatter.writeTo(ExpandingMessageFormatter.java:97)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.submitResponse(PassThroughHttpSender.java:573)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:264)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:230)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:531)
at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:118)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:59)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.rest.Resource.process(Resource.java:343)
at org.apache.synapse.rest.API.process(API.java:338)
at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:123)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:101)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:56)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:304)
at org.apache.synapse.mediators.builtin.LoopBackMediator.mediate(LoopBackMediator.java:63)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:59)
at org.apache.synapse.config.xml.AnonymousListMediator.mediate(AnonymousListMediator.java:37)
at org.apache.synapse.config.xml.SwitchCase.mediate(SwitchCase.java:69)
at org.apache.synapse.mediators.filters.SwitchMediator.mediate(SwitchMediator.java:148)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:260)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.mediateFromContinuationStateStack(Axis2SynapseEnvironment.java:775)
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:262)
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)
Unexpected error sending message back {org.apache.synapse.core.axis2.Axis2Sender}
org.apache.axis2.AxisFault: Failed to submit the response
at org.apache.synapse.transport.passthru.PassThroughHttpSender.handleException(PassThroughHttpSender.java:632)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:266)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:230)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:531)
at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:118)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:59)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.rest.Resource.process(Resource.java:343)
at org.apache.synapse.rest.API.process(API.java:338)
at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:123)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:101)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:56)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:304)
at org.apache.synapse.mediators.builtin.LoopBackMediator.mediate(LoopBackMediator.java:63)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:59)
at org.apache.synapse.config.xml.AnonymousListMediator.mediate(AnonymousListMediator.java:37)
at org.apache.synapse.config.xml.SwitchCase.mediate(SwitchCase.java:69)
at org.apache.synapse.mediators.filters.SwitchMediator.mediate(SwitchMediator.java:148)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:260)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.mediateFromContinuationStateStack(Axis2SynapseEnvironment.java:775)
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:262)
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)
API Content:
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">$1</ns:binary>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="//*[local-name()='Binary']/text()"/>
</args>
</payloadFactory>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<property name="ContentType" value="application/pdf" scope="axis2" type="STRING"/>
<property name="messageType" value="application/pdf" scope="axis2" type="STRING"/>
<respond/>
I have tried to convert binary to pdf using online tool and it works fine.
Find out eventually how to do it.
I use postgres in my experiments. Let's create table which will store files content. It is pretty simple. Anyway there are 2 cases. File might be stored as base64 or blob (bytea in postgres).
I implemented case when file is stored as string in base64 format in database.
drop table if exists pdf_files ;
create table pdf_files(
id serial primary key,
file_name text,
pdf_base64 text,
pdf_binary bytea
);
Insert data file content into table in base64 format.
File in base64 format can be converted online here or any other online tool
http://www.motobit.com/util/base64-decoder-encoder.asp
insert into pdf_files(file_name, pdf_base64)
values('title.pdf', 'JVBERi0x.....................NjMKJSVFT0YK');
Now lets get binary field filled
update pdf_files set pdf_binary = decode(pdf_base64, 'base64');
I got this in database:
First i tried to implement soap service which will respond pdf.
There is service I made:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Sample" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
<target>
<inSequence>
<dblookup>
<connection>
<pool>
<dsName>pgConn</dsName>
</pool>
</connection>
<statement>
<sql>select pdf_base64 from pdf_files where id = ?</sql>
<parameter xmlns:nb="http://mru" expression="//nb:id" type="INTEGER"/>
<result column="pdf_base64" name="pdf_base64"/>
</statement>
</dblookup>
<payloadFactory media-type="xml">
<format>
<ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">$1</ns:binary>
</format>
<args>
<arg evaluator="xml" expression="get-property('pdf_base64')"/>
</args>
</payloadFactory>
<loopback/>
</inSequence>
<outSequence>
<script language="js">
var binaryNode = mc.getEnvelope().getBody().getFirstElement().getFirstOMChild();
binaryNode.setBinary(true);
</script>
<property name="messageType" scope="axis2" type="STRING" value="application/pdf"/>
<respond/>
</outSequence>
</target>
<description/>
</proxy>
It accepts request with tag id which is refers to table id(primary key)
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:nb="http://mru">
<soap:Body>
<nb:id>1</nb:id>
</soap:Body>
</soap:Envelope>
Let's make request using curl (I assume request is saved in file request.xml)
curl -v -X POST -H "Content-Type:text/xml" -d #./request.xml http://localhost:8280/services/Sample.SampleHttpSoap12Endpoint > title1.pdf
This what i got
As you see after I can open pdf file returned by service.
Now same thing for API. It is actually easy and almost the same. Only need to configure url-template to catch parameter id for sql query.
<api xmlns="http://ws.apache.org/ns/synapse" name="GetPdf" context="/pdf">
<resource methods="GET" uri-template="/id/{fileId}">
<inSequence>
<property name="ID" expression="get-property('uri.var.fileId')"/>
<dblookup>
<connection><pool><dsName>pgConn</dsName></pool></connection>
<statement>
<sql>select pdf_base64 from pdf_files where id = ?</sql>
<parameter expression="get-property('ID')" type="INTEGER"/>
<result name="pdf_base64" column="pdf_base64"/>
</statement>
</dblookup>
<payloadFactory media-type="xml">
<format>
<ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">$1</ns:binary>
</format>
<args>
<arg evaluator="xml" expression="get-property('pdf_base64')"/>
</args>
</payloadFactory>
<loopback/>
</inSequence>
<outSequence>
<script language="js">
var binaryNode = mc.getEnvelope().getBody().getFirstElement().getFirstOMChild();
binaryNode.setBinary(true);
</script>
<property name="messageType" value="application/pdf" scope="axis2" type="STRING"/>
<respond/>
</outSequence>
</resource>
</api>
This api will return PDF file using proper Content-Type header so browser will understand it.
Picture is underneath. Browser properly identify content, via content type header, and use builtin pdf renderer to display pdf file served by wsoesb server.
Related
I've to convert my backend soap response to json. For this i use a datamapper XML to JSON. The datamapper failed at runtime with this error:
[2019-11-01 14:58:29,805] [micro-integrator] ERROR - DataMapperMediator DataMapper mediator : mapping failed
Error while parsing XML input stream. Current context not Object but root
at org.wso2.carbon.mediator.datamapper.engine.input.readers.XMLInputReader.read(XMLInputReader.java:124)
at org.wso2.carbon.mediator.datamapper.engine.input.InputBuilder.buildInputModel(InputBuilder.java:59)
at org.wso2.carbon.mediator.datamapper.engine.core.mapper.MappingHandler.doMap(MappingHandler.java:90)
at org.wso2.carbon.mediator.datamapper.DataMapperMediator.transform(DataMapperMediator.java:390)
at org.wso2.carbon.mediator.datamapper.DataMapperMediator.mediate(DataMapperMediator.java:301)
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.apache.synapse.rest.Resource.process(Resource.java:363)
at org.apache.synapse.rest.API.process(API.java:370)
at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:135)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:113)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:58)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:325)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:578)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:195)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:265)
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)
[2019-11-01 14:58:29,807] [micro-integrator] ERROR - AgendaRestApi DataMapper mediator : mapping failed
Error while parsing XML input stream. Current context not Object but root
at org.wso2.carbon.mediator.datamapper.engine.input.readers.XMLInputReader.read(XMLInputReader.java:124)
at org.wso2.carbon.mediator.datamapper.engine.input.InputBuilder.buildInputModel(InputBuilder.java:59)
at org.wso2.carbon.mediator.datamapper.engine.core.mapper.MappingHandler.doMap(MappingHandler.java:90)
at org.wso2.carbon.mediator.datamapper.DataMapperMediator.transform(DataMapperMediator.java:390)
at org.wso2.carbon.mediator.datamapper.DataMapperMediator.mediate(DataMapperMediator.java:301)
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.apache.synapse.rest.Resource.process(Resource.java:363)
at org.apache.synapse.rest.API.process(API.java:370)
at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:135)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:113)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:58)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:325)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:578)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:195)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:265)
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)
The input and output sample files used to configure the datamapper are:
INPUT
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetSpecialtiesResponse xmlns="http://agenda/">
<GetSpecialtiesResult xmlns:a="http://schemas.datacontract.org/2004/07/WsAgenda.DataContracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Specialty>
<a:code>cardiology</a:code>
<a:name>Cardiologie</a:name>
</a:Specialty>
<a:Specialty>
<a:code>neurology</a:code>
<a:name>Neurologie</a:name>
</a:Specialty>
</GetSpecialtiesResult>
</GetSpecialtiesResponse>
</s:Body>
</s:Envelope>
OUTPUT:
{"Specialties": [
{
"id": "cardiology",
"description": "Cardiologie"
},
{
"id": "cardiology",
"description": "Cardiologie"
}
]}
In the datamapper designer all seems to working fine.
Here is the sequence code:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/agenda" name="AgendaRestApi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" url-mapping="/specialties">
<inSequence>
<log/>
<payloadFactory description="" media-type="xml">
<format>
<soapenv:Envelope xmlns:agen="http://agenda/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<agen:GetSpecialties/>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<header name="soapAction" scope="transport" value="http://agenda/agenda/GetSpecialties"/>
<send>
<endpoint key="AgendaEP"/>
</send>
</inSequence>
<outSequence>
<datamapper config="gov:datamapper/GetSpecialtiesMapping.dmc" inputSchema="gov:datamapper/GetSpecialtiesMapping_inputSchema.json" inputType="XML" outputSchema="gov:datamapper/GetSpecialtiesMapping_outputSchema.json" outputType="JSON" xsltStyleSheet="gov:datamapper/GetSpecialtiesMapping_xsltStyleSheet.xml"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<respond/>
</outSequence>
<faultSequence>
<log level="full"/>
</faultSequence>
</resource>
</api>
All possible solutions are welcome :)
I had the same problem and solved adding this property before the datamapper mediator.
<property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
<datamapper config="gov:datamapper/GetSpecialtiesMapping.dmc" inputSchema="gov:datamapper/GetSpecialtiesMapping_inputSchema.json" inputType="XML" outputSchema="gov:datamapper/GetSpecialtiesMapping_outputSchema.json" outputType="JSON" xsltStyleSheet="gov:datamapper/GetSpecialtiesMapping_xsltStyleSheet.xml"/>
Hope this helps,
JP
Getting the below errors when I am trying to connect to Salesforce, Anything essential am I missing?
//TID[-1234] [EI] [2019-03-19 20:40:40,174] ERROR {org.apache.axis2.description.ClientUtils} - The system cannot infer the transport information from the /services/createSFBuzz URL.
//TID[-1234] [EI] [2019-03-19 20:40:40,174] ERROR {org.apache.synapse.core.axis2.Axis2Sender} - Unexpected error during sending message out org.apache.axis2.description.ClientUtils.inferOutTransport(ClientUtils.java:86) org.apache.synapse.core.axis2.DynamicAxisOperation$DynamicOperationClient.executeImpl(DynamicAxisOperation.java:116) org.apache.axis2.client.OperationClient.execute(OperationClient.java:149) org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:603) org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:85) org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:547) org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:120) org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:108) org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:70) org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158) org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:224) org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180) org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:337) org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:383) org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:151) org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:745)
My Proxy Code:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="createSFBuzz"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<property expression="json-eval($.accessToken)" name="accessToken"/>
<property expression="json-eval($.apiUrl)" name="apiUrl"/>
<property expression="json-eval($.clientId)" name="clientId"/>
<property expression="json-eval($.refreshToken)" name="refreshToken"/>
<property expression="json-eval($.clientSecret)" name="clientSecret"/>
<property expression="json-eval($.hostName)" name="hostName"/>
<property expression="json-eval($.apiVersion)" name="apiVersion"/>
<property expression="json-eval($.registryPath)" name="registryPath"/>
<property expression="json-eval($.intervalTime)" name="intervalTime"/>
<salesforcerest.init>
<accessToken>{$ctx:accessToken}</accessToken>
<apiUrl>{$ctx:apiUrl}</apiUrl>
<apiVersion>{$ctx:apiVersion}</apiVersion>
<hostName>{$ctx:hostName}</hostName>
<clientSecret>{$ctx:clientSecret}</clientSecret>
<clientId>{$ctx:clientId}</clientId>
<refreshToken>{$ctx:refreshToken}</refreshToken>
<registryPath>{$ctx:registryPath}</registryPath>
<intervalTime>{$ctx:intervalTime}</intervalTime>
</salesforcerest.init>
<log level="full" separator=","/>
<send/>
</inSequence>
<outSequence>
<payloadFactory media-type="json">
<format>{"success":"Connection Successful"}</format>
<args/>
</payloadFactory>
<respond/>
</outSequence>
</target>
<description/>
</proxy>
The problem is not in the salesforce connector, but in the send mediator afterwards. It has no idea where to send anything. You have a send mediator without a defined endpoint, and most likely without a To header that points to a valid endpoint.
What are you trying to achieve with the Send mediator?
I am trying to use the data mapper to map the response from two(2) different api. So what I did was use the clone mediator and aggregate mediator to merge these two api together and then map it using the data mapper but when I get on the data mapper part I always get an error. It works if I removed the data mapper mediator part.
Here's my api
<?xml version="1.0" encoding="UTF-8"?>
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<property name="ROOT" scope="default">
<root:movie xmlns:root="www.wso2esb.com"/>
</property>
<log level="full"/>
<clone continueParent="true" id="movie" sequential="true">
<target>
<sequence>
<send>
<endpoint>
<address format="rest" uri="https://api.themoviedb.org/3/movie/tt0918940?api_key=code"/>
</endpoint>
</send>
</sequence>
</target>
<target>
<sequence>
<send>
<endpoint>
<address format="rest" uri="https://www.omdbapi.com/?type=movie&i=tt0918940"/>
</endpoint>
</send>
</sequence>
</target>
</clone>
</inSequence>
<outSequence>
<aggregate id="movie">
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete enclosingElementProperty="ROOT" expression="//jsonObject/*" xmlns:dummy="http://org.dummy" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<datamapper config="gov:datamapper/TestMapping.dmc" inputSchema="gov:datamapper/TestMapping_inputSchema.json" inputType="JSON" outputSchema="gov:datamapper/TestMapping_outputSchema.json" outputType="JSON"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<respond/>
</onComplete>
</aggregate>
</outSequence>
</resource>
</api>
and here's my log
[2016-07-21 09:33:56,180] ERROR - SequenceMediator Runtime error occurred while mediating the message
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at org.wso2.carbon.mediator.datamapper.engine.input.readers.JSONInputReader.readFromInputStream(JSONInputReader.java:76)
at org.wso2.carbon.mediator.datamapper.engine.input.readers.JSONInputReader.read(JSONInputReader.java:59)
at org.wso2.carbon.mediator.datamapper.engine.input.InputBuilder.buildInputModel(InputBuilder.java:59)
at org.wso2.carbon.mediator.datamapper.engine.core.mapper.MappingHandler.doMap(MappingHandler.java:67)
at org.wso2.carbon.mediator.datamapper.DataMapperMediator.transform(DataMapperMediator.java:306)
at org.wso2.carbon.mediator.datamapper.DataMapperMediator.mediate(DataMapperMediator.java:256)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:95)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:57)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.mediators.eip.aggregator.AggregateMediator.completeAggregate(AggregateMediator.java:447)
at org.apache.synapse.mediators.eip.aggregator.AggregateMediator.mediate(AggregateMediator.java:330)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:95)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:57)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.rest.Resource.process(Resource.java:325)
at org.apache.synapse.rest.API.process(API.java:338)
at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:125)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:101)
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:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Please check your governance registry whether you add configuration correctly into ESB. (Navigate to Governance registry)
You will get null pointer exception as it can't find relevant details. Please add relevant configurations and test.
At the start of the Outsequence I am using this:
<property name="messageType" value="application/JSON" scope="axis2"/>
but still I get the error message Content not allowed in prolog.
If I directly send the response to the client without using any mediators I don't get any error.
Below is the full stack trace:
[2015-07-07 12:11:35,747] ERROR - RelayUtils Error while building Passthrough stream
org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
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:55)
at org.apache.synapse.transport.passthru.util.DeferredMessageBuilder.getDocument(DeferredMessageBuilder.java:138)
at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:107)
at org.apache.synapse.transport.passthru.util.RelayUtils.buildMessage(RelayUtils.java:82)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:68)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:268)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:488)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:170)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:225)
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)
I am able to parse JSON response.
WSO2 ESB version used- 4.8.1
Below is the proxy code.
<?xml version="1.0" encoding="UTF-8"?><proxy xmlns="http://ws.apache.org/ns/synapse" name="JsonProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<log level="full">
<property name="################ REQUEST ###################" expression="$body"/>
</log>
<send>
<endpoint>
<address uri="http://ip.jsontest.com/"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<log level="full">
<property name="################ RESPONSE###################" expression="$body"/>
</log>
<log>
<property name="::::::::::::::::::::::::::::: JSON :::::::::::::::::::::::::::" expression="json-eval($.)"/>
</log>
<send/>
</outSequence>
</target>
<description/>
</proxy>
Please cross check that below lines are only uncommented in axis2.xml
<messageFormatter contentType="application/json"
class="org.apache.synapse.commons.json.JsonStreamFormatter"/>
<messageFormatter contentType="application/json/badgerfish"
class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/>
<messageBuilder contentType="application/json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"/>
<messageBuilder contentType="application/json/badgerfish"
class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/>
I have a proxy service in WSO2 ESB which is listening over a Queue via JMS and then after some processing it sends message to another queue. It works fine. I am implementing fault sequence of this service that in case if endpoint is suspended then it should send message to an error queue. In fault sequence WSO2 ESB is generating ERROR_MESSAGE, ERROR_DETAIL, ERROR_EXCEPTION but it is not generating ERROR_CODE.
Fault Sequence:
<faultSequence xmlns="http://ws.apache.org/ns/synapse">
<log level="full" separator="**********Fault Sequence File Processor***********">
<property name="ErrorCode" expression="get-property('ERROR_CODE')"></property>
<property name="ErrorMessage" expression="get-property('ERROR_MESSAGE')"></property>
<property name="ErrorDetail" expression="get-property('ERROR_DETAIL')"></property>
<property name="ErrrorException" expression="get-property('ERROR_EXCEPTION')"></property>
</log>
<payloadFactory media-type="xml">
<format>
<MessageFormat xmlns="">
<ECode>$1</ECode>
<EMsg>$2</EMsg>
<EDetail>$3</EDetail>
<EException>$4</EException>
</MessageFormat>
</format>
<args>
<arg expression="get-property('ERROR_CODE')" evaluator="xml"></arg>
<arg expression="get-property('ERROR_MESSAGE')" evaluator="xml"></arg>
<arg expression="get-property('ERROR_DETAIL')" evaluator="xml"></arg>
<arg expression="get-property('ERROR_EXCEPTION')" evaluator="xml"></arg>
</args>
</payloadFactory>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"></property>
<property name="ClientApiNonBlocking" action="remove" scope="axis2"></property>
<send>
<endpoint key="conf:/endpoints/ErrorQueue.xml"></endpoint>
</send>
</faultSequence>
Endpoint Which i am suspending:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="Endpoint">
<address uri="jms:/RequestQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://192.168.1.33:61616&transport.jms.DestinationType=queue" format="pox">
<timeout>
<duration>6000</duration>
</timeout>
<markForSuspension>
<errorCodes>101504, 101505, 303001, 303000</errorCodes>
<retriesBeforeSuspension>1</retriesBeforeSuspension>
<retryDelay>1</retryDelay>
</markForSuspension>
<suspendOnFailure>
<errorCodes>101500, 101501, 101506, 101507, 101508, 303001, 303000</errorCodes>
<initialDuration>1000</initialDuration>
<progressionFactor>2</progressionFactor>
<maximumDuration>6400</maximumDuration>
</suspendOnFailure>
</address>
</endpoint>
Note:
The IP mentioned in the "address" URI is not correct so that's why service goes into fault sequence.
Output on Error Queue:
<MessageFormat><ECode>0</ECode><EMsg>Unexpected error during sending message out</EMsg><EDetail>org.apache.synapse.SynapseException: Unexpected error during sending message out
at org.apache.synapse.core.axis2.Axis2Sender.handleException(Axis2Sender.java:172)
at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:71)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:338)
at org.apache.synapse.endpoints.AbstractEndpoint.send(AbstractEndpoint.java:333)
at org.apache.synapse.endpoints.AddressEndpoint.send(AddressEndpoint.java:59)
at org.apache.synapse.endpoints.IndirectEndpoint.send(IndirectEndpoint.java:54)
at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:196)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.mediators.eip.Target.mediate(Target.java:106)
at org.apache.synapse.mediators.eip.splitter.IterateMediator.mediate(IterateMediator.java:146)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:196)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:166)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.axis2.transport.base.AbstractTransportListener.handleIncomingMessage(AbstractTransportListener.java:328)
at org.apache.synapse.transport.vfs.VFSTransportListener.processFile(VFSTransportListener.java:597)
at org.apache.synapse.transport.vfs.VFSTransportListener.scanFileOrDirectory(VFSTransportListener.java:328)
at org.apache.synapse.transport.vfs.VFSTransportListener.poll(VFSTransportListener.java:158)
at org.apache.synapse.transport.vfs.VFSTransportListener.poll(VFSTransportListener.java:107)
at org.apache.axis2.transport.base.AbstractPollingTransportListener$1$1.run(AbstractPollingTransportListener.java:67)
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:744)
Caused by: org.apache.axis2.AxisFault: Unable to create a JMSMessageSender for : null
at org.apache.axis2.transport.base.AbstractTransportSender.handleException(AbstractTransportSender.java:226)
at org.apache.axis2.transport.jms.JMSSender.sendMessage(JMSSender.java:129)
at org.apache.axis2.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:112)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:297)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:482)
at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:59)
... 33 more
Caused by: javax.jms.JMSException: Could not connect to broker URL: tcp://192.168.1.33:61616. Reason: java.net.NoRouteToHostException: No route to host
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:301)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:246)
at org.apache.activemq.ActiveMQConnectionFactory.createQueueConnection(ActiveMQConnectionFactory.java:203)
at org.apache.axis2.transport.jms.JMSOutTransportInfo.createJMSSender(JMSOutTransportInfo.java:363)
at org.apache.axis2.transport.jms.JMSSender.sendMessage(JMSSender.java:127)
... 39 more
</EDetail><EException></EException></MessageFormat>
Problem:
Why WSO2 ESB does not generate ERROR_CODE? I have to get that error code and on the basis of error code make some further logic.
This is default behaviour of WSO2 ESB. In Endpoint failure case, WSO2 ESB returns 0 as ErrorCode but Error Detail and Error Message have specific error messages. What you can do is, using Filter mediator or Switch mediator you can make your custom error code and message.
<filter xmlns:ns="http://org.apache.synapse/xsd" source="json-eval($.node[0].nid)" regex="100">
<then>
//your business here
</then>
<else>
//your business here
</else>
</filter>