WSO2: Converting CSV message to json wso2 esb . failing with Unexpected character '"' (code 34) in prolog; expected '<' - csv

I am trying to use data mapper to convert csv into json. Below is the proxy service which i have written.
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="csvtojson" startOnLoad="true" transports="http https vfs"
xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property expression="$body/*[1]" name="body" scope="default" type="OM"/>
<log level="full">
<property name="PropertyName" value="Message tobe fed to mapper"/>
</log>
<datamapper config="gov:datamapper/csvtojsonmapping.dmc"
inputSchema="gov:datamapper/csvtojsonmapping_inputSchema.json"
inputType="CSV"
outputSchema="gov:datamapper/csvtojsonmapping_outputSchema.json"
outputType="JSON"/>
<log level="full">
<property name="property_name" value="aftermapping"/>
</log>
<property name="ContentType" scope="axis2" type="STRING"
value="application/json"/>
<log description="" level="full">
<property name="property_name" value="msgpropertyset as json"/>
</log>
<send>
<endpoint>
<http method="post" uri-template="https://www.google.com/"/>
</endpoint>
</send>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
<parameter name="transport.PollInterval">1</parameter>
<parameter name="transport.vfs.FileURI">file:///tmp/in</parameter>
<parameter name="transport.vfs.ContentType">text/csv</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter
name="transport.vfs.MoveAfterFailure">file:///tmp/failure</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="transport.vfs.Build">false</parameter>
<parameter name="transport.vfs.FileNamePattern">.*\.csv</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///tmp/out</parameter>
</proxy>
Already included below two in axis2.xml file:
While executing the service, I am getting below error:
[2018-08-30 18:38:44,535] [EI-Core] ERROR - VFSTransportListener Error
processing File URI : file:///tmp/in/test.csv
org.apache.axiom.om.OMException:
com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '"' (code
34) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]
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
(OMXMLBuilderFacto ry.java:196)
at org.apache.axis2.builder.SOAPBuilder.processDocument
(SOAPBuilder.java:65)
at org.apache.synapse.transport.vfs.VFSTransportListener.processFile
(VFSTransportListener.java:822)
at
org.apache.synapse.transport.vfs.VFSTransportListener.scanFileOrDirectory
(VFSTransportListener.java:477)
at org.apache.synapse.transport.vfs.VFSTransportListener.poll
(VFSTransportListener.java:188)
at org.apache.synapse.transport.vfs.VFSTransportListener.poll
(VFSTransportListener.java:134)
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:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException:
Unexpected character '"' (code 34) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar
(StreamScanner.java:639)
at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog
(BasicStreamReader.java:2052)
at com.ctc.wstx.sr.BasicStreamReader.next
(BasicStreamReader.java:1134)
at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next
(XMLStreamReaderWrapper.java:225)
at
(DisallowDoctypeDeclStreamReaderWrapper.java:34)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext
(StAXOMBuilder.java:681)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next
(StAXOMBuilder.java:214)
... 15 more
This is the content of the messae which I am placing in /tmp/in folder
the content are as follows:
ContactType,FirstName,MiddleName,LastName,Email,PhoneNumber,Company,Address1,Address2,Address3,Zip,Country,FacsimileTelephoneNumber,PartnerFinanceID 1,ABC,A,CBD,test#test.com,123456789,Test,200WS,300 WSD,400tyu,125kji,World,4567894585,dummy
please help with your inputs. Please let me know if you need any more info from my side...........

you can access the content inside the request/response payload of CSV by configuring the org.apache.axis2.format.PlainTextBuilder and org.apache.axis2.format.PlainTextFormatter for the text/csv content type in axis2.xml. For example:
<messageBuilder contenttype="text/csv" class="org.apache.axis2.format.PlainTextBuilder"/>
<messageFormatter contenttype="text/csv" class="org.apache.axis2.format.PlainTextFormatter"/>
Please refer -
https://docs.wso2.com/display/ESB500/Working+with+Message+Builders+and+Formatters#WorkingwithMessageBuildersandFormatters-Handlingtext/csvmessages

Related

WSO2: xml to json data mapping in wso2 esb : json message is wrapped in soap envelope

I am working on one request where the input message is xml and it has to be converted to json. I am using data mapper to do this.
Configured proxy service for the same and below is the code for it:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="xmltojson_to_Partneronb" startOnLoad="true" transports="vfs
http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log level="full">
<property name="property_name" value="Initial reading file"/>
</log>
<datamapper config="gov:datamapper/ProducerPartnerOnb.dmc" inputSchema="gov:datamapper/ProducerPartnerOnb_inputSchema.json" inputType="XML" outputSchema="gov:datamapper/ProducerPartnerOnb_outputSchema.json" outputType="JSON"/>
<log level="full">
<property name="property_name" value="after enriching"/>
</log>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
<parameter name="transport.PollInterval">1</parameter>
<parameter name="transport.vfs.FileURI">file:///tmp/in</parameter>
<parameter name="transport.vfs.ContentType">application/xml</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///tmp/failure</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="transport.vfs.FileNamePattern">.*\.xml</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///tmp/out</parameter>
</proxy>
From the logs which you have provided the SOAP format is not framed correctly, below is the formatted SOAP Response.
<soapenv:Envelope xmlns:soapenv="schemas.xmlsoap.org/soap/envelope/">
;
<soapenv:Body>
<jsonObject>
<FirstName>ABC</FirstName>
<MiddleInitial>m</MiddleInitial>
<LastName>LN</LastName>
<Email>test#test.com</Email>
<Company>Test</Company>
<Address1>200 West St</Address1>
<Address2>hjhjhj</Address2>
</jsonObject>
</soapenv:Body>
</soapenv:Envelope>
After SOAP envelop ends there is a ; due to which you are getting error, you need to rectify this.

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.

WSO2 Smook response not write to file

I'm trying write the response from a proxy with Smooks Mediator on a file but nothing happens.
The mediator get a csv file with vfs option, convert to xml output and send the csv to a out directory correctely.
In console i see the ws02-esb-service.log and the xml is correctly.
But i not do get write to file.
In /u01/app/wso2esb-4.7.0/tmp/send/convert then result not appears.
And not have any error.
This is the code.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="SmookTest"
transports="vfs"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<smooks config-key="smooks-registro">
<input type="text"/>
<output type="xml"/>
</smooks>
<log level="full"/>
<property name="transport.vfs.ReplyFileName"
value="test1.xml"
scope="transport"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint name="grabar">
<address uri="vfs:file:///u01/app/wso2esb-4.7.0/tmp/send/convert"/>
</endpoint>
</send>
</inSequence>
</target>
<parameter name="transport.vfs.ReplyFileURI">salida.xml</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">5</parameter>
<parameter name="transport.vfs.FileURI">/u01/app/wso2esb-4.7.0/tmp/send</parameter>
<parameter name="transport.vfs.MoveAfterProcess">/u01/app/wso2esb-4.7.0/tmp/send/out</parameter>
<parameter name="transport.vfs.MoveAfterFailure">/u01/app/wso2esb-4.7.0/tmp/send/fail</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.csv</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<description/>
</proxy>
Since the VFS read as a plain/text format it will not engage the formarter until you explicitly mention it. Therefore you can mention the content type before you call the endpoint
Like
<property name="OUT_ONLY" value="true"/>
<property name="messageType"
value="application/soap"
scope="axis2"
type="STRING"/>
<send>
<endpoint name="grabar">
<address uri="vfs:file:///u01/app/wso2esb-4.7.0/tmp/send/convert"/>
</endpoint>
</send>
I found the solution.
adding format to endpoint and the file content are write correctly.
<address uri="vfs:file:///u01/app/wso2esb-4.7.0/tmp/send/convert"
format="soap11"/>

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.