WSO2 WebSocket cannot parse JSON string - json

Since WSO2 5.0 supports WebSockets, I have written a simple app following by tutorials:
WebSocket Transport
Sending a Message from a WebSocket Client to an HTTP Endpoint
Here's my source view output from WSO2:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
<registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
<parameter name="cachableDuration">15000</parameter>
</registry>
<taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"/>
<sequence name="fault">
<!-- Log the message at the full log level with the ERROR_MESSAGE and the ERROR_CODE-->
<log level="full">
<property name="MESSAGE" value="Executing default 'fault' sequence"/>
<property expression="get-property('ERROR_CODE')" name="ERROR_CODE"/>
<property expression="get-property('ERROR_MESSAGE')" name="ERROR_MESSAGE"/>
</log>
<!-- Drops the messages by default if there is a fault -->
<drop/>
</sequence>
<sequence name="main">
<in>
<!-- Log all messages passing through -->
<log level="full"/>
<!-- ensure that the default configuration only sends if it is one of samples -->
<!-- Otherwise Synapse would be an open proxy by default (BAD!) -->
<filter regex="http://localhost:9000.*" source="get-property('To')">
<!-- Send the messages where they have been sent (i.e. implicit "To" EPR) -->
<send/>
</filter>
</in>
<out>
<send/>
</out>
<description>The main sequence for the message mediation</description>
</sequence>
<sequence name="outDispatchSeq">
<log level="full">
<property name="MESSAGE" value="Executing outDispatchSeq -------------- "/>
</log>
<respond/>
</sequence>
<sequence name="dispatchSeq">
<payloadFactory media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="get-property('body')"/>
</args>
</payloadFactory>
<property expression="json-eval($.testPropertyName)"
name="testPropertyName" scope="default" type="STRING"/>
<log level="full">
<property name="MESSAGE" value="Executing dispatchSeq -------------- "/>
</log>
</sequence>
<!-- You can add any flat sequences, endpoints, etc.. to this synapse.xml file if you do
*not* want to keep the artifacts in several files -->
<inboundEndpoint name="test" onError="fault" protocol="ws"
sequence="dispatchSeq" suspend="false">
<parameters>
<parameter name="inbound.ws.port">9091</parameter>
<parameter name="ws.outflow.dispatch.sequence">outDispatchSeq</parameter>
<parameter name="ws.client.side.broadcast.level">0</parameter>
<parameter name="ws.outflow.dispatch.fault.sequence">fault</parameter>
<parameter name="content.type">application/json</parameter>
</parameters>
</inboundEndpoint>
</definitions>
Then I create simple JavaScript code to connect with WebSocket and send simple JSON data:
function connect() {
webSocket = new WebSocket('ws://localhost:9091/');
webSocket.onopen = function(e) {
console.log('connected: ' + webSocket);
};
// some logic here...
webSocket.send("{ \"testPropertyName\": \"testValue\"}");
}
But by all the time, WSO2 cannot parse my JSON object. I am getting errors like:
DEBUG - PayloadFactoryMediator #mediate. Transformed payload format>>>
ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path <$.testPropertyName>. Returning empty result. Error>>> invalid path
INFO - LogMediator To: , MessageID: urn:uuid:93c8c0bc-2a77-4895-a852-1267e21f2044, Direction: request, MESSAGE = Executing dispatchSeq -------------- , Payload: {}
DEBUG - PayloadFactoryMediator #mediate. Transformed payload format>>>
ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path <$.testPropertyName>. Returning empty result. Error>>> invalid path
INFO - LogMediator To: , MessageID: urn:uuid:828216c3-a3ba-476a-886d-302a62e117be, Direction: request, MESSAGE = Executing dispatchSeq -------------- , Payload: {}
UPDATE:
After changing loggin to:
log4j.logger.org.apache.synapse.transport.http.wire=DEBUG
and adding loggig just after payloadFactory:
<sequence name="dispatchSeq">
<payloadFactory media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="get-property('body')" />
</args>
</payloadFactory>
<log level="full" />
<property expression="json-eval($.testPropertyName)" name="testPropertyName" scope="default" type="STRING" />
<log level="full">
<property name="MESSAGE" value="Executing dispatchSeq -------------- " />
</log>
</sequence>
WSO2 is logging following output:
DEBUG - PayloadFactoryMediator #mediate. Transformed payload format>>>
INFO - LogMediator To: , MessageID: urn:uuid:7a04df37-b3c0-47a0-9ea1-78df460aec0a, Direction: request, Payload: {}
ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path <$.testPropertyName>. Returning empty result. Error>>> invalid path
INFO - LogMediator To: , MessageID: urn:uuid:7a04df37-b3c0-47a0-9ea1-78df460aec0a, Direction: request, MESSAGE = Executing dispatchSeq -------------- , Payload: {}
DEBUG - PayloadFactoryMediator #mediate. Transformed payload format>>>
INFO - LogMediator To: , MessageID: urn:uuid:9ef7732c-b196-435e-a800-5d98d670b11a, Direction: request, Payload: {}
ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path <$.testPropertyName>. Returning empty result. Error>>> invalid path
INFO - LogMediator To: , MessageID: urn:uuid:9ef7732c-b196-435e-a800-5d98d670b11a, Direction: request, MESSAGE = Executing dispatchSeq -------------- , Payload: {}
UPDATE
I removed payloadFactory like:
<sequence name="dispatchSeq">
<log level="full" />
<property expression="json-eval($.testPropertyName)" name="testPropertyName" scope="default" type="STRING" />
<log level="full">
<property name="MESSAGE" value="Executing dispatchSeq -------------- " />
</log>
</sequence>
WSO2 logs show me:
INFO - LogMediator To: , MessageID: urn:uuid:db00d7aa-69c8-4de6-8140-91169183c3d6, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
WARN - SynapseJsonPath Json Payload is empty.
INFO - LogMediator To: , MessageID: urn:uuid:db00d7aa-69c8-4de6-8140-91169183c3d6, Direction: request, MESSAGE = Executing dispatchSeq -------------- , Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
INFO - LogMediator To: , MessageID: urn:uuid:19816ec6-c255-4edf-adae-cca83dbd2008, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
WARN - SynapseJsonPath Json Payload is empty.
INFO - LogMediator To: , MessageID: urn:uuid:19816ec6-c255-4edf-adae-cca83dbd2008, Direction: request, MESSAGE = Executing dispatchSeq -------------- , Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
UPDATE
Modified dispatchSeq:
<sequence name="dispatchSeq">
<log level="full" />
<property expression="json-eval($.testPropertyName)" name="testPropertyName" scope="default" type="STRING" />
<log level="full">
<property name="MESSAGE" value="Executing dispatchSeq -------------- " />
<property expression="get-property('websocket.source.handshake.present')" name="websocket.source.handshake.present.value" scope="default" type="STRING"/>
</log>
</sequence>
WSO2 output is:
INFO - LogMediator To: , MessageID: urn:uuid:5cc82e8d-6638-4cca-97f7-ac4f96877f85, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
WARN - SynapseJsonPath Json Payload is empty.
INFO - LogMediator To: , MessageID: urn:uuid:5cc82e8d-6638-4cca-97f7-ac4f96877f85, Direction: request, MESSAGE = Executing dispatchSeq -------------- , websocket.source.handshake.present.value = true, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
INFO - LogMediator To: , MessageID: urn:uuid:81b0e2bd-4e79-48bd-b177-f49fd5664c0a, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
WARN - SynapseJsonPath Json Payload is empty.
INFO - LogMediator To: , MessageID: urn:uuid:81b0e2bd-4e79-48bd-b177-f49fd5664c0a, Direction: request, MESSAGE = Executing dispatchSeq -------------- , websocket.source.handshake.present.value = null, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
Do you know what else I am missing?
I will appreciate any code examples.
Thank you very much!

Related

How can I create a JSON payload with text containing XML in it?

I try to create an automatic JIRA problem reporting (in some FAULT sequences.
I make a JSON payload for JIRA APIs what works just fine for text.
I would like to however report to JIRA a SOAP request and response whereby I could investigate on the issue.
my question is how can I create a JSON payload with text containing XML in it?
I get this exception in WSO2 ESB
[2016-09-18 21:46:31,774] ERROR - NativeWorkerPool Uncaught exception
java.lang.Error: Error: could not match input
at org.apache.synapse.commons.staxon.core.json.stream.impl.JsonScanner.zzScanError(JsonScanner.java:530)
at org.apache.synapse.commons.staxon.core.json.stream.impl.JsonScanner.yylex(JsonScanner.java:941)
payload which I want to generate
<payloadFactory description="" media-type="json">
<format>
{
"fields": {
"project":
{
"key": "$1"
},
"summary": "$2",
"description": "$3",
"issuetype": { "name": "$4" }
}
}
</format>
<args>
<arg evaluator="xml" expression="$func:projectKey"/>
<arg evaluator="xml" expression="$func:summary"/>
<arg evaluator="xml" expression="$func:description"/>
<arg evaluator="xml" expression="$func:issueType"/>
</args>
</payloadFactory>
and I want to send some text containing XML into the parameter $func:description. When I sent only poor XML into the $func:description, the payload Factory transferred into into JSON what is not needed in this case, the the XML is supposed to be a text - the message
for the completeness to get the XML message I used
<property expression="$body" name="request"
scope="default" type="STRING"/>
call the end-point
<property expression="$body" name="response"
scope="default" type="STRING"/>
and I need to know bind "request" + "response" into $func:description
If the XML is well-formed you can simply set messageType property to application/json and do the conversion automatically. Refer this for more details.
Or else you can use the payload Factory mediator or Enrich mediator to custom build your Json.
create the payload with the XML structure you like.
use JS script mediator to modify one node as CDATA.
change the content type.
My proxy config, please do the change you need for your requirement:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="XMLinsideJSON"
transports="http https"
startOnLoad="true">
<target>
<inSequence>
<property name="BOK" expression="//*[1]" type="OM" scope="default"/>
<enrich>
<source type="inline" clone="true">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<fields xmlns="">
<summary xmlns=""/>
<project xmlns=""/>
<description xmlns=""/>
<issuetype xmlns="">
<name xmlns=""/>
</issuetype>
</fields>
</soapenv:Body>
</soapenv:Envelope>
</source>
<target type="envelope"/>
</enrich>
<script language="js">
importPackage(Packages.org.apache.axiom.om);
var elem= mc.getEnvelope().getBody().getFirstElement().getFirstElement();
var myText = elem.getOMFactory().createOMText(elem, mc.getProperty("BOK"), OMNode.CDATA_SECTION_NODE);
elem.addChild(myText)
</script>
<property name="messageType" scope="axis2" value="application/json"/>
<respond/>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>
My request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<payload>
<response>
<data>AAA</data>
</response>
</payload>
</soapenv:Body>
</soapenv:Envelope>
My response:
{"fields":{"summary":"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body>\n <payload>\n <response>\n <data>AAA</data>\n </response>\n </payload>\n </soapenv:Body></soapenv:Envelope>","project":null,"description":null,"issuetype":{"name":null}}}

Unable to get response in JSON format after aggregation in WSO2 ESB

I have a proxy service to search a user in multiple systems and should return the combined responses in JSON format.I get the responses combined but instead of getting it in JSON format I get the responses in XML format.
I can see JSON responses in WSO2 server logs as below:
[2016-07-19 07:26:58,249] INFO - LogMediator To: http://www.w3.org/2005/08/addr
essing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:895c4303-6de5-49
88-a4d1-c06275582841, Direction: response, Component = Application2, Payload: {
"findUsers":[
{"id":"20","add_state":"0","remove_state":"0","supervisor_id_name":"","idc_id":"
3","backup_supervisor_name":"","backup_supervisor":"","business_unit_id":"","com
pany":"companyb","creation_date":"2016-05-11 18:02:42.0","deletion_date":"","dep
artment":"922","display_name":"Kevin Mollo (companyb)","email_address":"Kevin.Mo
llo#companyb.com","exception_count":"","first_name":"Kevin","is_terminated":"Fal
se","job_status":"Active","last_name":"Mollo","legacy_employee_id":"171352","sup
ervisor_id":"","termination_date":"","title":"Broadband Technician","unique_id":
"9000070","user_id":"user71","violation_count":""}
]
}
[2016-07-19 07:26:58,888] INFO - LogMediator To: http://www.w3.org/2005/08/addr
essing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:0cee9dc3-b6e6-48
81-9bdd-a89ec22999a7, Direction: response, Component = Application1, Payload: {"vi
ewableIdentityAttributes":{"Email":"Kevin.Mollo#companyb.com","cn":"Kevin Mollo"
,"Last Name":"Mollo","First Name":"Kevin"},"assignedRoles":[],"listAttributes":[
"First Name","Last Name","Email","cn"]}
However, I don't get response in JSON format after calling the proxy url.
Below is my ESB configuration:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="SPRSAPproxy"
transports="http,https"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log/>
<clone>
<target>
<sequence>
<property name="Application" value="Application1"/>
<property name="messageType"
value="application/xacml+json"
scope="axis2"
type="STRING"/>
<property name="Authorization"
expression="fn:concat('Basic ', base64Encode('username:password'))"
scope="transport"/>
<send>
<endpoint>
<address uri="http://hostname1:8080/identityiq/rest/identities/9000070"/>
</endpoint>
</send>
</sequence>
</target>
<target>
<sequence>
<property name="Application" value="Application2"/>
<property name="messageType"
value="application/json"
scope="axis2"
type="STRING"/>
<send>
<endpoint>
<address uri="http://hostname2:8080/aveksa/command.submit?cmd=findUsers&format=json&unique_id=9000070"/>
</endpoint>
</send>
</sequence>
</target>
</clone>
</inSequence>
<outSequence>
<log level="full" description="">
<property name="Component" expression="get-property('Application')"/>
</log>
<aggregate>
<completeCondition>
<messageCount min="2"/>
</completeCondition>
<onComplete expression="/">
<property name="messageType"
value="application/xacml+json"
scope="axis2"
type="STRING"
description="messageType"/>
<enrich>
<source clone="true" xpath="/"/>
<target type="body"/>
</enrich>
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence>
<log level="full" category="WARN"/>
</faultSequence>
</target>
<description/>
</proxy>
I get the response as below:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/><soapenv:Body><jsonObject><findUsers><id>20</id><add_state>0</add_state><remove_state>0</remove_state><supervisor_id_name></supervisor_id_name><idc_id>3</idc_id><backup_supervisor_name></backup_supervisor_name><backup_supervisor></backup_supervisor><business_unit_id></business_unit_id><company>companyb</company><creation_date>2016-05-11 18:02:42.0</creation_date><deletion_date></deletion_date><department>922</department><display_name>Kevin Mollo (companyb)</display_name><email_address>Kevin.Mollo#companyb.com</email_address><exception_count></exception_count><first_name>Kevin</first_name><is_terminated>False</is_terminated><job_status>Active</job_status><last_name>Mollo</last_name><legacy_employee_id>171352</legacy_employee_id><supervisor_id></supervisor_id><termination_date></termination_date><title>Broadband Technician</title><unique_id>9000070</unique_id><user_id>user71</user_id><violation_count></violation_count></findUsers></jsonObject><soapenv:Envelope><soapenv:Header/><soapenv:Body><jsonObject><viewableIdentityAttributes><Email>Kevin.Mollo#companyb.com</Email><cn>Kevin Mollo</cn><Last Name>Mollo</Last Name><First Name>Kevin</First Name></viewableIdentityAttributes><listAttributes>First Name</listAttributes><listAttributes>Last Name</listAttributes><listAttributes>Email</listAttributes><listAttributes>cn</listAttributes></jsonObject></soapenv:Body></soapenv:Envelope></soapenv:Body></soapenv:Envelope>
Please let me know how I can get the JSON response.
Any help would be greatly appreciated.
You can set the messageType to application/json instead of application/xacml+json in outSequence and try.
<property name="messageType" value="application/json" scope="axis2" type="STRING" description="messageType"/>
Also there is no application/xacml+json message formatters and message builders shipped with WSO2 ESB by default. If you need to use these formats you have to write your own formatters and builders and configure them in axis2.xml file.

How to convert rest service response from binary to xml in WSO2 ESB 4.8.1

Below is the proxy implemented in WSO2 ESB 4.8.1, this return response in binary format as shown next to the proxy code. Response is expected in the xml response.
Note: This proxy returns xml response in WSO2 ESB 4.9.0 as expected.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="postIDMPCall-withheader"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<in>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<organizationList xmlns="">
<Organization>
<sourceRecordId>132</sourceRecordId>
<idmpRecordId>0</idmpRecordId>
<orgName>depcomp</orgName>
<smeNumber/>
<psmflCode/>
<countryCode>AF</countryCode>
<shortName/>
<remarks/>
<address>addressgger</address>
<city>mys</city>
<state>kar</state>
<postalCode>234</postalCode>
<contactPhone/>
<phoneExtension/>
<faxNumber/>
<faxExtension/>
<webSite/>
<active>YES</active>
<organizationId/>
</Organization>
</organizationList>
</format>
<args/>
</payloadFactory>
<log>
<property name="before call" expression="$body"/>
</log>
<property name="user" value="system" scope="default" type="STRING"/>
<property name="password"
value="Password2#"
scope="default"
type="STRING"/>
<header name="_user" scope="transport" expression="get-property('user')"/>
<header name="_password"
scope="transport"
expression="get-property('password')"/>
<log>
<property name="header" expression="get-property('user')"/>
</log>
<call blocking="true">
<endpoint>
<address uri="http://<ipaddress>:<port>/<rest-Services-path>/UpdateOrganization"
format="rest"/>
</endpoint>
</call>
<log>
<property name="after call" expression="$body"/>
</log>
<property name="messageType" value="text/xml" scope="axis2" type="STRING"/> <header name="To" scope="default" action="remove"/>
<property name="RESPONSE" value="true"/>
<send/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<drop/>
</in>
</inSequence>
</target>
</proxy>
1.Logs:
[ESB] [2016-05-04 15:10:27,222] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /services/postIDMPCall-withheader.postIDMPCall-withheaderHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:b5814442-977e-43ed-9cc9-f60faa46c5c2, Direction: request, before call = <soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><organizationList><Organization><sourceRecordId>132</sourceRecordId><idmpRecordId>0</idmpRecordId><orgName>depcomp</orgName><smeNumber></smeNumber><psmflCode></psmflCode><countryCode>AF</countryCode><shortName></shortName><remarks></remarks><address>addressgger</address><city>mys</city><state>kar</state><postalCode>234</postalCode><contactPhone></contactPhone><phoneExtension></phoneExtension><faxNumber></faxNumber><faxExtension></faxExtension><webSite></webSite><active>YES</active><organizationId></organizationId></Organization></organizationList></soapenv:Body> {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2016-05-04 15:10:27,230] INFO {org.apache.synapse.core.axis2.TimeoutHandler} - This engine will expire all callbacks after : 120 seconds, irrespective of the timeout action, after the specified or optional timeout {org.apache.synapse.core.axis2.TimeoutHandler}
TID: [0] [ESB] [2016-05-04 15:10:31,066] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:cee9a5c2-1f64-4ff3-a6bd-712785567f8d, Direction: request, after call = <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><axis2ns1:binary xmlns:axis2ns1="http://ws.apache.org/commons/ns/payload">PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8b3JnYW5pemF0aW9uUmVzcG9uc2VMaXN0PgogICAgPE9yZ2FuaXphdGlvbj4KICAgICAgICA8c291cmNlUmVjb3JkSWQ+MTMyPC9zb3VyY2VSZWNvcmRJZD4KICAgICAgICA8aWRtcFJlY29yZElkPjE3MTY5PC9pZG1wUmVjb3JkSWQ+CiAgICAgICAgPHN1Y2Nlc3M+U1VDQ0VTUzwvc3VjY2Vzcz4KICAgICAgICA8ZXJyb3I+Tm8gRXJyb3JzPC9lcnJvcj4KICAgIDwvT3JnYW5pemF0aW9uPgo8L29yZ2FuaXphdGlvblJlc3BvbnNlTGlzdD4K</axis2ns1:binary></soapenv:Body> {org.apache.synapse.mediators.builtin.LogMediator}
2.Response received in binary format:
<axis2ns6:binary xmlns:axis2ns6="http://ws.apache.org/commons/ns/payload">PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8b3JnYW5pemF0aW9uUmVzcG9uc2VMaXN0PgogICAgPE9yZ2FuaXphdGlvbj4KICAgICAgICA8c3VjY2Vzcz5GQUlMVVJFPC9zdWNjZXNzPgogICAgICAgIDxlcnJvcj5SZWNvcmQgaXMgbm90IHByb2Nlc3NlZCBzdWNjZXNzZnVsbHkuIFBsZWFzZSBQcm92aWRlIHZhbGlkIFJlcXVlc3QgWE1MPC9lcnJvcj4KICAgIDwvT3JnYW5pemF0aW9uPgo8L29yZ2FuaXphdGlvblJlc3BvbnNlTGlzdD4K</axis2ns6:binary>
To convert an XML payload to JSON, set the messageType property to application/json in the axis2 scope before sending message to an endpoint.
<property name="messageType" value="application/json" scope="axis2"/>
I am not sure why you only have inSequence .
And you are logging both before and after call content inside inSequence.
Can you use outSequence and check ? i.e
<outSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
</outSequence>
Please check that you have enabled the binary message builder/formatter in /repository/conf/axis2/axis2.xml. If so, disable binary message builder and use default message builders/formatters and try this again.

JSON format in WSO2 ESB PayloadFactory mediator

PayloadFactory mediator I’m using JSON format string. The Problem is, when I enable the following lines in /repository/conf/axis2/axis2.xml, POST request works fine, but GET request produce error message.
<!--messageFormatter contentType="application/json"
class="org.apache.axis2.json.JSONStreamFormatter"/-->
<!--messageBuilder contentType="application/json"
class="org.apache.axis2.json.JSONStreamBuilder"/-->
Here is the ESB template for paypal List all Payment Resources:
<template name="listPaymentResources" xmlns="http://ws.apache.org/ns/synapse">
<sequence class="sequence">
<payloadFactory media-type="json">
<format>
{}
</format>
</payloadFactory>
<property name="messageType" scope="axis2" value="application/json" />
<call>
<endpoint>
<http method="get" uri-template="{uri.var.paypalUrl}/v1/payments/payment"/>
</endpoint>
</call>
</sequence>
</template>
Proxy service:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="listPaymentResources"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property xmlns:ns="uri.var.payment"
name="ppurl"
expression="//ns:paypalurl/text()"/>
<PayPal.config>
<appUri>{$ctx:ppurl}</appUri>
</PayPal.config>
<PayPal.listPaymentResources/>
<respond/>
</inSequence>
<outSequence>
<log/>
<send/>
</outSequence>
</target>
<description/>
</proxy>
The Error log:
[2013-12-11 17:25:10,971] ERROR - TargetHandler Unexpected error: Cannot get a J
SON writer
java.lang.UnsupportedOperationException: Cannot get a JSON writer
at org.apache.axis2.json.JSONStreamFormatter.getJSONWriter(JSONStreamFor
matter.java:63)
at org.apache.axis2.json.AbstractJSONMessageFormatter.getTargetAddress(A
bstractJSONMessageFormatter.java:228)
at org.apache.synapse.transport.passthru.TargetRequest.start(TargetReque
st.java:152)
at org.apache.synapse.transport.passthru.TargetHandler.requestReady(Targ
etHandler.java:136)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.produceOutput(D
efaultNHttpClientConnection.java:244)
at org.apache.synapse.transport.http.conn.LoggingNHttpClientConnection.p
roduceOutput(LoggingNHttpClientConnection.java:112)
at org.apache.synapse.transport.passthru.ClientIODispatch.onOutputReady(
ClientIODispatch.java:88)
at org.apache.synapse.transport.passthru.ClientIODispatch.onOutputReady(
ClientIODispatch.java:41)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.outputReady(Abstr
actIODispatch.java:148)
I have done some testing on the subject on latest release of the WSO2 ESB and i could not able to reproduce this given issue.

WSO2 ESB - XML to MySQL Database

I need a solution for a problem:
I just tried this example for the WSO2 ESB and it is working:
http://wso2.org/library/articles/2011/01/wso2-esb-example-file-processing
But I like to use an XML file as input and write this to a MySQL-DB.
The XML-file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Name>word</Name>
<Surname>processor</Surname>
<Phone>12333</Phone>
</soapenv:Body>
</soapenv:Envelope>
If i put this into my "in"-folder the file will be moved to the "out"-folder, but nothing is written into the database. There is no error message.
My Proxy-Service:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="FileProxy" transports="vfs" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
<clone>
<target sequence="fileWriteSequence"/>
<target sequence="databaseSequence"/>
</clone>
</inSequence>
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">15</parameter>
<parameter name="transport.vfs.MoveAfterProcess">C:/wso2esb/testordner/out</parameter>
<parameter name="transport.vfs.FileURI">C:/wso2esb/testordner/in</parameter>
<parameter name="transport.vfs.MoveAfterFailure">C:/wso2esb/testordner/error</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
<parameter name="transport.vfs.ContentType">text/xml</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<description></description>
</proxy>
And my Sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse"
name="databaseSequence"
trace="enable"
statistics="enable">
<log level="full">
<property name="sequence" value="before-smooks"/>
</log>
<smooks config-key="smooks">
<input type="xml"/>
<output type="xml"/>
</smooks>
<log level="full">
<property name="sequence" value="after-smooks"/>
</log>
<log level="full">
<property xmlns:ns="http://org.apache.synapse/xsd"
name="name"
expression="//csv-record/name/text()"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="surname"
expression="//csv-record/surname/text()"/>
<property name="phone" value="//csv-record/phone/text()"/>
</log>
<iterate xmlns:ns2="http://org.apache.synapse/xsd"
xmlns:ns="http://org.apache.synapse/xsd"
xmlns:sec="http://secservice.samples.esb.wso2.org"
expression="//csv-set/csv-record">
<target>
<sequence>
<log level="full">
<property name="State" value="Iteration"/>
</log>
<log level="full" category="DEBUG"/>
<dbreport>
<connection>
<pool>
<password>passwort</password>
<user>esb</user>
<url>jdbc:mysql://localhost:3306/</url>
<driver>com.mysql.jdbc.Driver</driver>
</pool>
</connection>
<statement>
<sql>insert into info.info (name, surname, phone) values (?, ?, ?)</sql>
<parameter expression="//csv-record/name/text()" type="VARCHAR"/>
<parameter expression="//csv-record/surname/text()" type="VARCHAR"/>
<parameter expression="//csv-record/phone/text()" type="VARCHAR"/>
</statement>
</dbreport>
</sequence>
</target>
</iterate>
<log level="full" category="DEBUG"/>
</sequence>
I thought this would be a simple problem, but I'm not able to get it...
Like I said, it's working with a normal text-file, but not with XML. I tried different thinks and have no idea what else I could try...
Does someone know what's my mistake?
Update:
The log from the console:
[2013-04-12 09:35:55,687] INFO - DBReportMediator Successfully created data source for jdbc:mysql://localhost:3306/.
[2013-04-12 09:36:10,170] INFO - LogMediator To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:
2CBD1753113A1373101365752170177, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope x
mlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
<Name>word</Name>
<Surname>processor</Surname>
<Phone>12333</Phone>
</soapenv:Body></soapenv:Envelope>
[2013-04-12 09:36:10,175] INFO - LogMediator To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:
a9252cd8-fe73-4e85-9f41-0842872d3a73, Direction: request, sequence = before-smooks, Envelope: <?xml version='1.0' encodi
ng='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
<Name>word</Name>
<Surname>processor</Surname>
<Phone>12333</Phone>
</soapenv:Body></soapenv:Envelope>
[2013-04-12 09:36:10,178] INFO - LogMediator sequence = fileWriteSequence
[2013-04-12 09:36:10,246] INFO - LogMediator To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:
a9252cd8-fe73-4e85-9f41-0842872d3a73, Direction: request, sequence = after-smooks, Envelope: <?xml version='1.0' encodin
g='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><csv-set/></soapenv
:Body></soapenv:Envelope>
[2013-04-12 09:36:10,249] INFO - LogMediator To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:
a9252cd8-fe73-4e85-9f41-0842872d3a73, Direction: request, name = , surname = , phone = //csv-record/phone/text(), Envelo
pe: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><s
oapenv:Body><csv-set/></soapenv:Body></soapenv:Envelope>
[2013-04-12 09:36:11,254] WARN - TimeoutHandler Expiring message ID : urn:uuid:4c422f4e-aed5-4eaa-ad9b-e5407db20562; dr
opping message after global timeout of : 120 seconds
The fileWriteSequence looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse"
name="fileWriteSequence"
trace="enable"
statistics="enable">
<log level="custom">
<property name="sequence" value="fileWriteSequence"/>
</log>
<property xmlns:ns2="http://org.apache.synapse/xsd"
xmlns:ns="http://org.apache.synapse/xsd"
name="transport.vfs.ReplyFileName"
expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.xml')"
scope="transport"
type="STRING"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint name="FileEpr">
<address uri="vfs:C:/wso2esb/testordner/out"/>
</endpoint>
</send>
</sequence>
Smooks config:
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
<!--Configure the CSVParser to parse the message into a stream of SAX events. -->
<resource-config selector="org.xml.sax.driver">
<resource>org.milyn.csv.CSVParser</resource>
<param name="fields" type="string-list">name,surname,phone</param>
</resource-config>
</smooks-resource-list>
I also changed the code of the databaseSequence above.
Thank you.
Your proxy service looks ok. But I have few concerns.
Why have you put the sql query as CDATA. Please see the sample available here.
You have not mentioned the database name in the connection url. May be it is not a problem since you have used the database.table format in your sql query.
After fixing and 1 and 2, if the issue still exists, try your proxy with only one sequence. i.e. Avoid the file write sequence temporarily and try only with the dbwrite sequence.
You can also log the entries which you are going to insert before the DBReport mediator. i.e. Right after the smooks mediator, put a log mediator and log the name, surname and phone. This will make sure you are trying to insert values which are correctly extracted from the message.