how to convert xml to json in wso2 - 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>

Related

How to add additional information in the response?

Scenario
I've integrated an external service in my API. In addition to the response from the external service, I want to add a few more JSON keys and values.
API
<?xml version="1.0" encoding="UTF-8"?>
<api context="/PhoneVerify" name="PhoneVerifi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:cmpa="http://XXX.XXX.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://object.pmd.com/xsd">
<soapenv:Header/>
<soapenv:Body>
<cmpa:verify>
<!--Optional:-->
<cmpa:userName>XXXXX</cmpa:userName>
<!--Optional:-->
<cmpa:passwd>XXXXX</cmpa:passwd>
<!--Optional:-->
<cmpa:request>
<!--Optional:-->
<xsd:cnic>$1</xsd:cnic>
<!--Optional:-->
<xsd:msisdn>$2</xsd:msisdn>
<!--Optional:-->
<xsd:transactionID>$3</xsd:transactionID>
</cmpa:request>
</cmpa:verify>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="json" expression="$.cnic"/>
<arg evaluator="json" expression="$.msisdn"/>
<arg evaluator="json" expression="$.transactionID"/>
</args>
</payloadFactory>
<log category="DEBUG" level="full"/>
<header name="Action" scope="default" value="verify"/>
<send>
<endpoint>
<address format="soap11" uri="https://XXXXX.com/CMPA/services/CnicMsisdnPairing.CnicMsisdnPairingHttpsSoap11Endpoint/">
<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="$.verifyResponse.return"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<respond/>
</outSequence>
<faultSequence>
<payloadFactory media-type="json">
<format>
{
"status" : "failure"
}</format>
<args/>
</payloadFactory>
</faultSequence>
</resource>
</api>
Response from External Service
"verifyResponse":{
"return" : {
"#type":"ax21:Response",
"message":"Duplicate Transaction ID",
"responseCode":"08",
"status":"00"
}
}
Desired Response
{
"status": "success"
"response": {
"#type":"ax21:Response",
"message":"Duplicate Transaction ID",
"responseCode":"08",
"status":"00"}
}
Question
My exact question is that when I try to achieve the above problem, I'm getting the response as shown below (basically its wrapped in " "). How can I make achieved the desired response?
{
"status": "success"
"response": "{"#type":"ax21:Response","message":"Duplicate Transaction ID","responseCode":"08","status":"00"}"
}
The Payload factory is adding " " since you have defined the argument $1 within " ". If you modify the Payload factory as below you should be able to get the desired output.
<payloadFactory media-type="json">
<format>
{
"status" : "success",
"response": $1
}
</format>
<args>
<arg evaluator="json" expression="$.verifyResponse.return"/>
</args>
</payloadFactory>
I have tried the above in the latest Integration Studio(8.1.0), if the above solution doesn't work please specify the MI version you are using.

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.

How to make an additional http call inside api and process response?

I'm trying to create Message Mediation Policies, with which I can make an additional http call, process the response and enrich the current message. How can i do this? I use call Mediator, but I don’t understand how to handle the response.
<?xml version="1.0" encoding="UTF-8"?> <sequence name="call_out_handler" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<call blocking="true">
<endpoint>
<http method="get" uri-template="http://192.168.99.100:8888/stubFORAPIMan/ServletWithTimeout"/>
</endpoint>
</call> </sequence>
You can use the PayloadFactory Mediator [1] to handle/format the response you received by calling an endpoint inside the Call mediator.
An example would be like this. Say you want to provide a json object by populating the values from the response you received; you can define the json object format in the "format" section and populate the values by providing the arguments in the "args" section in the PayloadFactory mediator as below.
<payloadFactory media-type="json">
<format>
{
"Data": {
"PaymentSubmissionId": "$1",
"PaymentId": "$2",
"Status": "$3",
"CreationDateTime": "$4"
}
}
</format>
<args>
<arg evaluator="xml" expression="$body//PaymentSubId"/>
<arg evaluator="xml" expression="$body//PaymentId"/>
<arg evaluator="xml" value="AcceptedSettlementInProcess"/>
<arg value="2019-06-05T15:15:22+00:00"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
[1] https://docs.wso2.com/display/EI640/PayloadFactory+Mediator

WSO2 ESB: Unexpected Character Error when using Salesforce Connector

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

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 ..