WSO2 ESB: Unexpected Character Error when using Salesforce Connector - wso2

When attempting to follow the WSO2 directions to update a salesforce record I am getting the following error.
Saleforce adaptor - error injecting sObjects to payload : org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
<?xml version="1.0" encoding="UTF-8"?>
<proxy
xmlns="http://ws.apache.org/ns/synapse"
xmlns:sfdc="sfdc" name="SalesforceUpdateTest" startOnLoad="true" statistics="enable" trace="enable" transports="http,https">
<target>
<inSequence>
<sequence key="conf:/SalesforceLoginInfo"/>
<payloadFactory>
<format>
<sfdc:sObjects
xmlns:sfdc="sfdc" type="Account">
<sfdc:sObject>
<sfdc:Id>TestId1</sfdc:Id>
<sfdc:ValueToChange>Yes</sfdc:ValueToChange>
</sfdc:sObject>
</sfdc:sObjects>
</format>
<args/>
</payloadFactory>
<salesforce.update>
<allOrNone>0</allOrNone>
<allowFieldTruncate>0</allowFieldTruncate>
<sobjects
xmlns:sfdc="sfdc">{//sfdc:sObjects}
</sobjects>
</salesforce.update>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>
I am using WSO2 EI 6.1.0 and the salesforce connector 2.0.1. The Salesforce ID TestId1 exists as does the field ValueToChange. My SalesforceLoginInfo is correct (I can do Salesforce queries, just not updates).
Attempting to solve the problem I saw this very similar question. But I've added the lines to the axis2.xml according to the Solution, restarted, and the problem still exists.
<messageBuilder contentType="application/json" class="org.wso2.carbon.integrator.core.json.JsonStreamBuilder"/>
<messageBuilder contentType="text/javascript" class="org.wso2.carbon.integrator.core.json.JsonStreamBuilder"/>
<messageFormatter contentType="application/json" class="org.wso2.carbon.integrator.core.json.JsonStreamFormatter"/>
<messageFormatter contentType="text/javascript" class="org.wso2.carbon.integrator.core.json.JsonStreamFormatter"/>
Does anyone know how to fix this problem? I feel like I'm just following a tutorial (my code is nearly exactly the given wso2 salesforce example) and yet the problem continues.
UPDATE: To reduce confusion about the SalesforceLoginInfo call, I removed that and put the salesforce.init in the code. The error is still the same.
<?xml version="1.0" encoding="UTF-8"?>
<proxy
xmlns="http://ws.apache.org/ns/synapse"
xmlns:sfdc="sfdc" name="SalesforceUpdateTest" startOnLoad="true" statistics="enable" trace="enable" transports="http,https">
<target>
<inSequence>
<salesforce.init>
<username>developer#mycompany.com</username>
<password>mypasswordandmytoken</password>
<loginUrl>https://test.salesforce.com/services/Soap/u/27.0</loginUrl>
<blocking>true</blocking>
</salesforce.init>
<payloadFactory>
<format>
<sfdc:sObjects
xmlns:sfdc="sfdc" type="Account">
<sfdc:sObject>
<sfdc:Id>TestId1</sfdc:Id>
<sfdc:ValueToChange>Yes</sfdc:ValueToChange>
</sfdc:sObject>
</sfdc:sObjects>
</format>
<args/>
</payloadFactory>
<salesforce.update>
<allOrNone>0</allOrNone>
<allowFieldTruncate>0</allowFieldTruncate>
<sobjects
xmlns:sfdc="sfdc">{//sfdc:sObjects}
</sobjects>
</salesforce.update>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>

Was able to replicate the below behavior with WSO2 EI 6.1.0 and the salesforce connector 2.0.1.
Saleforce adaptor - error injecting sObjects to payload :
org.apache.axiom.om.OMException:
com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{'
(code 123) in prolog; expected '<'
Find the below proxy sequence used to fix it. The workaround was to load the payload into a property and pass the same to salesforce operation <salesforce.update> through Synapse XPath variable $ctx
<payloadFactory media-type="xml">
<format>
<sfdc:sObjects xmlns:sfdc="sfdc" type="Account">
<sfdc:sObject>
<sfdc:Id>0011I001102zk24PZA</sfdc:Id>
<sfdc:Description>Account1</sfdc:Description>
</sfdc:sObject>
</sfdc:sObjects>
</format>
<args/>
</payloadFactory>
<log level="full"/>
<log>
<property xmlns:sfdc="sfdc" expression="//sfdc:sObjects" name="n****n"/>
</log>
<property xmlns:sfdc="sfdc"
expression="//sfdc:sObjects"
name="sobjectPayload"
scope="default"
type="OM"/>
<log>
<property expression="get-property('sobjectPayload')"
name="fromProp****"/>
</log>
<salesforce.update>
<allOrNone>0</allOrNone>
<allowFieldTruncate>1</allowFieldTruncate>
<sobjects>{$ctx:sobjectPayload}</sobjects>
</salesforce.update>
The salesforce record was updated, in this case Account Object record's Description property.
Also there is no need to add new messageBuilder or messageFormatter into the axis2.xml as messageType is : text/xml in Salesforce connector templates, which is included by default in Axis2 configuration.

I can reproduce the error by removing the init operation.
[2017-08-12 09:39:17,315] ERROR - SetupUpdateSobjects Saleforce adaptor - error injecting sObjects to payload : org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
Please add the init operation top of the update method.
<salesforce.init>
<loginUrl>{$ctx:loginUrl}</loginUrl>
<username>{$ctx:username}</username>
<password>{$ctx:password}</password>
<blocking>{$ctx:blocking}</blocking>
</salesforce.init>
<payloadFactory>
<format>
<sfdc:sObjects xmlns:sfdc="sfdc" type="Account">
<sfdc:sObject>
<sfdc:Id>$1</sfdc:Id>
<sfdc:Name>$2</sfdc:Name>
</sfdc:sObject>
</sfdc:sObjects>
</format>
<args>
<arg expression="get-property('id')"/>
<arg expression="get-property('newName')"/>
</args>
</payloadFactory>
<salesforce.update>
<allOrNone>{$ctx:allOrNone}</allOrNone>
<allowFieldTruncate>{$ctx:allowFieldTruncate}</allowFieldTruncate>
<sobjects xmlns:sfdc="sfdc">{//sfdc:sObjects}</sobjects>
</salesforce.update>
or you create local entry for init and call it in the proxy[1].
<payloadFactory>
<format>
<sfdc:sObjects xmlns:sfdc="sfdc" type="Account">
<sfdc:sObject>
<sfdc:Id>$1</sfdc:Id>
<sfdc:Name>$2</sfdc:Name>
</sfdc:sObject>
</sfdc:sObjects>
</format>
<args>
<arg expression="get-property('id')"/>
<arg expression="get-property('newName')"/>
</args>
</payloadFactory>
<salesforce.update configkey="sf_init">
<allOrNone>{$ctx:allOrNone}</allOrNone>
<allowFieldTruncate>{$ctx:allowFieldTruncate}</allowFieldTruncate>
<sobjects xmlns:sfdc="sfdc">{//sfdc:sObjects}</sobjects>
</salesforce.update>
[1] https://docs.wso2.com/display/ESB500/Using+a+Connector

I have two questions to understand the issue u getting here.
First, what are you going to update in Account using the below? Do you need to give the record ID to update, if so you must give a valid id?
The second thing is what is "ValueToChange"? Is it a field for Account object(I don't think this is a field of Account Object)?
Can you modify the proxy as below and try.
<?xml version="1.0" encoding="UTF-8"?>
<proxy
xmlns="http://ws.apache.org/ns/synapse"
xmlns:sfdc="sfdc" name="SalesforceUpdateTest" startOnLoad="true" statistics="enable" trace="enable" transports="http,https">
<target>
<inSequence>
<salesforce.init>
<username>developer#mycompany.com</username>
<password>mypasswordandmytoken</password>
<loginUrl>https://test.salesforce.com/services/Soap/u/27.0</loginUrl>
<blocking>true</blocking>
</salesforce.init>
<payloadFactory>
<format>
<sfdc:sObjects
xmlns:sfdc="sfdc" type="Account">
<sfdc:sObject>
<sfdc:Id>valid salesforce record ID</sfdc:Id>
<sfdc:Name>Jay Smith</sfdc:Name>
</sfdc:sObject>
</sfdc:sObjects>
</format>
<args/>
</payloadFactory>
<salesforce.update>
<allOrNone>0</allOrNone>
<allowFieldTruncate>0</allowFieldTruncate>
<sobjects
xmlns:sfdc="sfdc">{//sfdc:sObjects}
</sobjects>
</salesforce.update>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>

Reason for this error is there is a new line character after the xpath param given for the connector.
In the attached config,
<sobjects
xmlns:sfdc="sfdc">{//sfdc:sObjects}
</sobjects>
Correct once should be
<sobjects xmlns:sfdc="sfdc">{//sfdc:sObjects}</sobjects>
When this happens [1] will get the XPATH expression not the evaluate value, that causes this issue. Tested and find the working proxy.
<?xml version="1.0" encoding="UTF-8"?>
<proxy
xmlns="http://ws.apache.org/ns/synapse"
xmlns:sfdc="sfdc" name="SalesforceUpdateTest" startOnLoad="true" statistics="enable" trace="enable" transports="http,https">
<target>
<inSequence>
<sequence key="conf:/SalesforceLoginInfo"/>
<payloadFactory>
<format>
<sfdc:sObjects
xmlns:sfdc="sfdc" type="Account">
<sfdc:sObject>
<sfdc:Id>TestId1</sfdc:Id>
<sfdc:ValueToChange>Yes</sfdc:ValueToChange>
</sfdc:sObject>
</sfdc:sObjects>
</format>
<args/>
</payloadFactory>
<salesforce.update>
<allOrNone>0</allOrNone>
<allowFieldTruncate>0</allowFieldTruncate>
<sobjects xmlns:sfdc="sfdc">{//sfdc:sObjects}</sobjects>
</salesforce.update>
</inSequence>
<outSequence>
<send/>`
</outSequence>
</target>
</proxy>
[1] https://github.com/wso2-extensions/esb-connector-salesforce/blob/master/connector/src/main/java/org/wso2/carbon/connector/salesforce/SalesforceUtil.java#L72

Related

how to convert xml to json in wso2

Scenario
I've implemented an API which makes a soap call to external service. I need to convert the response from xml to json (which is actually happening). But somehow I'm unable to convert the nested xml nodes to json.
API
<?xml version="1.0" encoding="UTF-8"?>
<api context="/nadra" name="NadraVerification" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:nad="http://XXXX.Verification" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<nad:GetCitizenDemographics>
<nad:franchizeID>XXX</nad:franchizeID>
<nad:xml_request_data><![CDATA[
<CITIZEN_VERIFICATION><USER_VERIFICATION><USERNAME>XXXX</USERNAME><PASSWORD>XXXX</PASSWORD></USER_VERIFICATION><REQUEST_DATA><TRANSACTION_ID>$4</TRANSACTION_ID><SESSION_ID></SESSION_ID><CITIZEN_NUMBER>$5</CITIZEN_NUMBER><CONTACT_NUMBER>$6</CONTACT_NUMBER><AREA_NAME>$7</AREA_NAME></REQUEST_DATA></CITIZEN_VERIFICATION>
]]></nad:xml_request_data>
</nad:GetCitizenDemographics>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="json" expression="$.transactionId"/>
<arg evaluator="json" expression="$.citizenNo"/>
<arg evaluator="json" expression="$.contactNo"/>
<arg evaluator="json" expression="$.areaName"/>
</args>
</payloadFactory>
<header name="Action" scope="default" value="http://XXXX.XXXX.XXXX/ICitizenVerification/GetCitizenDemographics"/>
<send>
<endpoint>
<address format="soap11" uri="https://verification.nadra.gov.pk/bioverisys/xml">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</address>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<payloadFactory media-type="json">
<format>
{
"status" : "success"
"response": $1
}</format>
<args>
<arg evaluator="json" expression="$.GetCitizenDemographicsResponse.GetCitizenDemographicsResult"/>
</args>
</payloadFactory>
<respond/>
</outSequence>
<faultSequence>
<payloadFactory media-type="json">
<format>
{
"status" : "failure"
}</format>
<args/>
</payloadFactory>
</faultSequence>
</resource>
</api>
Response from External Service after converting XML to JSON
{
"GetCitizenDemographicsResponse": {
"GetCitizenDemographicsResult": "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<CITIZEN_VERIFICATION xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <RESPONSE_DATA>\r\n <RESPONSE_STATUS>\r\n <CODE>100</CODE>\r\n
<MESSAGE>successful</MESSAGE>\r\n </RESPONSE_STATUS>\r\n <SESSION_ID>00001343681312</SESSION_ID>\r\n
<CITIZEN_NUMBER>XXXX</CITIZEN_NUMBER>\r\n <PERSON_DATA>\r\n <NAME>ایوب جمال</NAME>\r\n
<FATHER_HUSBAND_NAME>XXX</FATHER_HUSBAND_NAME>\r\n <PRESENT_ADDRESS>XXXX</PRESENT_ADDRESS>\r\n
<PERMANANT_ADDRESS>XXXX</PERMANANT_ADDRESS>\r\n <DATE_OF_BIRTH>1996-01-10</DATE_OF_BIRTH>\r\n
<GENDER>male</GENDER>\r\n <EXPIRY_DATE>2030-07-11</EXPIRY_DATE>\r\n </PERSON_DATA>\r\n
</RESPONSE_DATA>\r\n</CITIZEN_VERIFICATION>"
}
}
Actual Response
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetCitizenDemographicsResponse xmlns="http://NADRA.Citizen.Verification"><GetCitizenDemographicsResult><?xml version="1.0" encoding="utf-16"?>
<CITIZEN_VERIFICATION xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RESPONSE_DATA>
<RESPONSE_STATUS>
<CODE>107</CODE>
<MESSAGE>invalid citizen nummber</MESSAGE>
</RESPONSE_STATUS>
<SESSION_ID />
<CITIZEN_NUMBER>$5</CITIZEN_NUMBER>
</RESPONSE_DATA>
</CITIZEN_VERIFICATION></GetCitizenDemographicsResult></GetCitizenDemographicsResponse></s:Body></s:Envelope>
Question
My exact question is how can I convert the nested xml to json as well?. Since it has converted the first two xml nodes but the third xml node hasn't been converted.
Since you are using the Payload Factory to modify the response, you can use an XPath expression to extract the values from the soap endpoint. You don't need to explicitly convert the SOAP response to JSON using the messageType property before the Payload Factory.
Remove the messageType property
Use an XPath expression in the Payload Factory
Update Answer
According to the response from the backend, in the SOAP body, it has declared the <?xml version="1.0" encoding="UTF-8"?> tag before the CITIZEN_VERIFICATION element. Because of this, we need to first assign it to a property with OM type and then use it in the payload factory. Since we have a namespace defined for GetCitizenDemographicsResponse we need to add the namespace tag as well to the property mediator.
Option 1: With namespace
<property type="OM" xmlns:ns="http://NADRA.Citizen.Verification" expression="//ns:GetCitizenDemographicsResponse/*" name="Payload"/>
Or you can use local-name() function to get the value without defining the namespace in property mediator.
Option 2: Without defining the namespace
<property type="OM" expression="//*[local-name()='GetCitizenDemographicsResult']" name="Payload"/>
<outSequence>
<property type="OM" xmlns:ns="http://NADRA.Citizen.Verification" expression="//ns:GetCitizenDemographicsResponse/*" name="Payload"/>
<payloadFactory media-type="json">
<format>
{
"status" : "success",
"response": $1
}
</format>
<args>
<arg expression="$ctx:Payload" />
</args>
</payloadFactory>
<respond/>
</outSequence>

WSO2 EI 6.6.0 Class Mediator not being able to use SOAP call return content

I have the following API in EI 6.6.0:
<?xml version='1.0' encoding='UTF-8'?>
<api xmlns="http://ws.apache.org/ns/synapse" name="sample" context="/sample">
<resource methods="POST">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<P xmlns="http://tempuri.org/">
<P1>$1</P1>
<P2>$2</P2>
<P3>$3</P3>
</P>
</soap:Body>
</soap:Envelope>
</format>
<args>
<arg evaluator="json" expression="$.p1" />
<arg evaluator="json" expression="$.p2" />
<arg evaluator="json" expression="$.p3" />
</args>
</payloadFactory>
<log level="full" />
<property name="Content-Type" value="text/xml;charset=UTF-8" scope="axis2"/>
<header name="Accept" scope="transport" value="text/xml"/>
<call>
<endpoint>
<wsdl Action="name_of_the_action" service="name_of_the_service" port="name_of_soap_port" uri="http://<ip>/path?WSDL" />
</endpoint>
</call>
<class name="my_mediator_package"></class>
<log level="full" />
<payloadFactory media-type="xml">
<format>
<retorno xmlns="">
<msg>$1</msg>
</retorno>
</format>
<args>
<arg evaluator="xml" expression="get-property('property_set_on_mediator')" />
</args>
</payloadFactory>
<property name="messageType" value="application/xml" scope="axis2" type="STRING" />
<respond />
</inSequence>
<outSequence>
</outSequence>
<faultSequence>
<property name="text" value="An unexpected error occured"/>
<property name="message" expression="get-property('ERROR_MESSAGE')"/>
<payloadFactory media-type="xml">
<format>
<error xmlns="">
<msg>$1</msg>
</error>
</format>
<args>
<arg evaluator="xml" expression="get-property('ERROR_MESSAGE')"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<respond/>
</faultSequence>
</resource>
</api>
my mediate method content:
public boolean mediate(MessageContext synCtx) {
org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx)
.getAxis2MessageContext();
try {
// Getting the json payload to string
String jsonPayloadToString = JsonUtil.jsonPayloadToString(((Axis2MessageContext) synCtx)
.getAxis2MessageContext());
System.out.println("original payload : \n" + jsonPayloadToString + "\n");
I'm not being able to use the return from my SOAP call in my mediator so I can work on it.
When I run the API I get the following from my mediator code:
original payload:
{}
Is there a way so I can obtain the SOAP call returned envelope and use it in my mediator?
The JSON payload is coming as empty because you are calling a SOAP backend and getting a SOAP payload. You can use synCtx.getEnvelope() in your mediator to get the SOAPEnvelope from the response.
1- make sure the json payload is there. So, log the json properties inside your inSequence.
2- I'm not being able to use the return from my SOAP call in my mediator so I can work on it. you can see the response payload in your outSequence which currently is doing nothing.
3- According to your scenario which is simply calling a SOAP webservice, you do not need a class mediator. In other words, when you do not need manipulating the initial payload and then pass it to the destination service, logically implementing your own class mediator benefits you nothing.
Also, there are quite number of samples in https://docs.wso2.com/display/EI611 which will help you.
Please let me know if your problem is solved.

WSO2 ESB - Unable to access properties set in script mediator in a payload mediator

I've got a Script mediator where I've set a certain value (mc.setProperty("x",1)) and immediately after the script mediator I've set a PayloadFactory mediator where I'm trying to get the value x (get-property("x")). I used Log mediators in between my mediation logic to check if the property value is set. But the value isn't set. I'm using js for Script mediator.
I have same problem. I solved it by add call function "String" in script.
Something like -
<script language="js"><![CDATA[
mc.setProperty("x", String(1));
]]></script>
<log level="custom">
<property expression="get-property('x')" name="x" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
Can you try out the following? This is possible with WSO2 ESB 5.0.0
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestProxy"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<script language="js">mc.setProperty("x", 1);</script>
<log level="custom">
<property expression="get-property('x')" name="x"/>
</log>
<payloadFactory media-type="xml">
<format>
<value xmlns="">$1</value>
</format>
<args>
<arg evaluator="xml" expression="get-property('x')"/>
</args>
</payloadFactory>
<respond/>
</inSequence>
</target>
<description/>
</proxy>

Writing on a text file using VFS in WSO2 ESB 4.8.1

I am using VFS transport to poll a simple text file and then i send the text of a file to a queue. This flow works fine but in case of error scenario when fault sequence is executed , i want to write my error message to a simple text file and it is not Working.
Note:
I am using WSO2 ESB Version 4.8.1.
I have enabled the VFS transport in my "axis2.xml" file.
I have also tried all the solutions provided in this question which is related to mine.
My Service Code:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="FileWriteTest"
transports="vfs"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full"
separator="******************FileWrite In Sequence Start*************"/>
</inSequence>
<outSequence/>
<faultSequence>
<payloadFactory media-type="xml">
<format>
<MessageFormat xmlns="">
<ECode>$1</ECode>
<EMsg>$2</EMsg>
<EDetail>$3</EDetail>
<EException>$4</EException>
</MessageFormat>
</format>
<args>
<arg evaluator="xml" expression="get-property('ERROR_CODE')"/>
<arg evaluator="xml" expression="get-property('ERROR_MESSAGE')"/>
<arg evaluator="xml" expression="get-property('ERROR_DETAIL')"/>
<arg evaluator="xml" expression="get-property('ERROR_EXCEPTION')"/>
</args>
</payloadFactory>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<property name="ClientApiNonBlocking" scope="axis2" action="remove"/>
<send>
<endpoint>
<address uri="vfs:file:///home/omerkhalid/Documents/WSO2Test/FileWrite/Errorlog.txt"/>
</endpoint>
</send>
</faultSequence>
<endpoint>
<address uri="jms:/FileWriterResponse?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:6616&transport.jms.DestinationType=queue"/>
</endpoint>
</target>
<parameter name="transport.PollInterval">10</parameter>
<parameter name="transport.vfs.FileURI">file://home/omerkhalid/Documents/WSO2Test/FileWrite/InTest</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file://home/omerkhalid/Documents/WSO2Test/FileWrite/DoneTest</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.txt</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="serviceType">proxy</parameter>
<description/>
</proxy>
Problem Area:
The problem is in the following area of code, where i am defining my endpoint for Fault Sequence. It does create an file on that particular location but that file remains empty.
<send>
<endpoint>
<address uri="vfs:file:///home/omerkhalid/Documents/WSO2Test/FileWrite/Errorlog.txt"/>
</endpoint>
</send>
Exception:
org.apache.axis2.AxisFault: The system cannot infer the transport information from the file:///home/omerkhalid/Documents/WSO2Test/FileWrite/Errorlog.txt URL.
at org.apache.axis2.description.ClientUtils.inferOutTransport(ClientUtils.java:81)
at org.apache.axis2.client.OperationClient.prepareMessageContext(OperationClient.java:288)
at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:249)
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)
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.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.MediatorFaultHandler.onFault(MediatorFaultHandler.java:85)
at org.apache.synapse.FaultHandler.handleFault(FaultHandler.java:54)
at org.apache.synapse.endpoints.AbstractEndpoint.invokeNextFaultHandler(AbstractEndpoint.java:640)
at org.apache.synapse.endpoints.AbstractEndpoint.onFault(AbstractEndpoint.java:475)
at org.apache.synapse.endpoints.AddressEndpoint.onFault(AddressEndpoint.java:43)
at org.apache.synapse.FaultHandler.handleFault(FaultHandler.java:102)
at org.apache.synapse.core.axis2.AsyncCallback.onError(AsyncCallback.java:67)
at org.apache.axis2.engine.AxisEngine$TransportNonBlockingInvocationWorker.run(AxisEngine.java:643)
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)
Change your message in payloadFactory from your faultSequence :
The root node of your message must be : <text xmlns="http://ws.apache.org/commons/ns/payload">
and the content of this node will be the text value sent to your file

Set Custom Payload in wso2 ESB or AM?

I have a rest API in ESB server.I need to set payload as follows
<fields>Name</fields>
<query>
<term>
<NUM>100</NUM>
</term>
</query>
any suggestion ?
you could use the payloadfactory mediator in ESB 4.8.1, take this xml as an example. you need to do some changes :-) but it´s an start:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="JsonToXMLProxy"
transports="https http local"
startOnLoad="true"
trace="disable">
<description/>
<target>
<endpoint>
<address uri="http://www.w3schools.com/webservices/tempconvert.asmx" format="soap11"/>
</endpoint>
<inSequence>
<log>
<property name="TEMPERATURA_ENTRADA" expression="json-eval($.celsius)"/>
</log>
<payloadFactory media-type="xml">
<format>
<web:CelsiusToFahrenheit xmlns:web="http://www.w3schools.com/webservices/">
<web:Celsius>$1</web:Celsius>
</web:CelsiusToFahrenheit>
</format>
<args>
<arg evaluator="json" expression="$.celsius"/>
</args>
</payloadFactory>
<header name="Action"
value="http://www.w3schools.com/webservices/CelsiusToFahrenheit"/>
</inSequence>
<outSequence>
<log>
<property xmlns:p="http://www.w3schools.com/webservices/"
name="TEMPERATURA_SALIDA"
expression="//p:CelsiusToFahrenheitResponse/p:CelsiusToFahrenheitResult"/>
</log>
<payloadFactory media-type="json">
<format>
"Temperatura" : {
"EnFahrenheit" : $1
}
</format>
<args>
<arg xmlns:p="http://www.w3schools.com/webservices/"
evaluator="xml"
expression="//p:CelsiusToFahrenheitResponse/p:CelsiusToFahrenheitResult"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
</outSequence>
</target>
</proxy>
Try payload/enrich mediators ..