I'm integrating wso2dss 3.5 and wso2esb 4.9. In DSS, I created a DataService to get data from a database. Following the WSO2 Dashboard into DSS, I used the endpoint in my eclipse project (Developer Studio). The xml gerated by DSS is:
<elements xmlns="http://ws.wso2.org/dataservice">
<row>
<name>nome1</name>
<address>rua xalala das xalalas</address>
</row>
<row>
<name>nome2</name>
<address>ruas rms did sa</address>
</row>
<row>
<name>nome3</name>
<address>aldoas daso dasodsa</address>
</row>
</elements>
So, in my ESB project I have this gerated code:
<foreach expression="//elements/row">
<sequence>
<payloadFactory media-type="xml">
<format>
<p:Insert xmlns:p="http://ws.wso2.org/dataservice">
<xs:nome xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:nome>
<xs:endereco xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:endereco>
</p:Insert>
</format>
<args>
<arg evaluator="xml" expression="/row/name"/>
<arg evaluator="xml" expression="/row/address"/>
</args>
</payloadFactory>
<log>
<property name="xalela" value="xalxalxlalxal"/>
</log>
</sequence>
</foreach>
The problem is that it isn't loggin into foreach, in other words, it isn't accessing inside the foreach mediator. What's wrong?
xpath //elements/row return nothing because node "elements" belong to namespace http://ws.wso2.org/dataservice
try with //ds:element/ds:row and define ds as xmlns:ds="http://ws.wso2.org/dataservice"
Related
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.
I am transforming xml message into csv using xslt mediator. Transforming is happening fine but in the output message
is getting added on its own. Output message shown below
<text xmlns="http://ws.apache.org/commons/ns/payload">E5cjHWs_9N5ZiSWuvMHg_7Bhlxka|admin#xyz.super|admin|Test_API/|3.0|time|time|time|time|time|time|time|time|2018-09-25 11:51|time|time|time
</text>
Can some one please let me know how to remove them from the output file. Though in the log file the message looks good but actual message do have this added.
Any help pls...
Finally it worked.
I had to put payloadFactory after xslt mapping to remove the xmlns
Below code I added
<property name="messageType" scope="axis2" type="STRING"
value="text/plain"/>
<payloadFactory media-type="text">
<format>$1</format>
<args>
<arg evaluator="xml" expression="$body//*"
xmlns:ns="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
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
I'm integrating wso2dss 3.5 and wso2esb 4.9. In DSS, I created a DataService to get data from a database. Following the WSO2 Dashboard into DSS, I used the endpoint in my eclipse project (Developer Studio). The xml gerated by DSS is:
<elements xmlns="http://ws.wso2.org/dataservice">
<row>
<name>nome1</name>
<address>rua xalala das xalalas</address>
</row>
<row>
<name>nome2</name>
<address>ruas rms did sa</address>
</row>
<row>
<name>nome3</name>
<address>aldoas daso dasodsa</address>
</row>
</elements>
So, in my ESB config project, there is this generated code:
<foreach expression="//ds:elements/ds:row" xmlns:ds="http://ws.wso2.org/dataservice">
<sequence>
<payloadFactory media-type="xml">
<format>
<p:Insert xmlns:p="http://ws.wso2.org/dataservice">
<xs:nome xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:nome>
<xs:endereco xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:endereco>
</p:Insert>
</format>
<args>
<arg evaluator="xml" expression="/ds:row/name"/>
<arg evaluator="xml" expression="/ds:row/address"/>
</args>
</payloadFactory>
<log>
<property expression="/ds:row/name" name="nome"/>
<property expression="/ds:row/address" name="endereco"/>
</log>
</sequence>
</foreach>
I'm trying to get the value of first and second element at each row (name and address). How can I do this?
try add the xmlns:ds to args tag, like this:
<foreach expression="//ds:elements/ds:row" xmlns:ds="http://ws.wso2.org/dataservice">
<sequence>
<payloadFactory media-type="xml">
<format>
<p:Insert xmlns:p="http://ws.wso2.org/dataservice">
<xs:nome xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:nome>
<xs:endereco xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:endereco>
</p:Insert>
</format>
<args xmlns:ds="http://ws.wso2.org/dataservice">>
<arg evaluator="xml" expression="//ds:name"/>
<arg evaluator="xml" expression="//ds:address"/>
</args>
</payloadFactory>
<log>
<property expression="/ds:row/name" name="nome"/>
<property expression="/ds:row/address" name="endereco"/>
</log>
</sequence>
</foreach>
I am working on a wso2 scenario in which I send a SOAP message to a webservice and then receive and manipulate the answer. For this purpose I have TWO Webservices. One is placed in a test environment (1) and the another is the live one (2).
I have no access to the webservice code, I'm just a user.
The problem is:
Via SOAPUI
I'm able to use the service from Webservices (1) and (2). No error, everything works fine.
Via WSO2
I'm able to use the service from webservice (1) but when I point to the webservice (2) I get a HTML 403 Forbidden response instead of a SOAP/XML message.
Am I missing something or this could be a misconfiguration of the webservice?
Following my in/out requests:
Sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="pricing" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<smooks config-key="smooks-csv.xml">
<input type="text"/>
<output type="xml"/>
</smooks>
<iterate expression="//product" id="iterateXML" sequential="true"
xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd">
<target>
<sequence>
<payloadFactory media-type="xml">
<format>
<xyz xmlns="http://tempuri.org/">
<safeKey>$6</safeKey>
<storeId>$5</storeId>
<articleId>$1</articleId>
<barcode/>
<sku>$2</sku>
<price>$3</price>
<discount>$4</discount>
</xyz>
</format>
<args>
<arg evaluator="xml" expression="//articleId"/>
<arg evaluator="xml" expression="//sku"/>
<arg evaluator="xml" expression="//price"/>
<arg evaluator="xml" expression="//discount"/>
<arg evaluator="xml" expression="//storeId"/>
<arg evaluator="xml" expression="//key"/>
</args>
</payloadFactory>
<in>
<header name="Action" scope="default" value="http://tempuri.org/xyz"/>
<send>
<endpoint>
<recipientlist>
<endpoint key="PS_PRICING"/>
<endpoint key="fileSave"/>
</recipientlist>
</endpoint>
</send>
<drop/>
</in>
<out>
<send/>
</out>
<log level="full" separator=";">
<property expression="*" name="ResponsePriceUpdate"/>
</log>
</sequence>
</target>
</iterate>
</sequence>
UPDATE:
After testing using TCPMon and TCPTrace I got the following:
Via SOAPUi
If I send the message SOAPUi -> Live Webservice - Works fine! (Picture a)
If I send the message SOAPUi -> TCPMon/TCPTrace -> Live Webservice - 403 Forbidden! (Picture b)
It doesn't make sense at all to me. I'm running out of ideas.
(a)
(b)
For the people who has found this question relevant:
The problem was in the server-side. Server was rejecting some "unknown" sources of incoming traffic.
Maybe add ?wsdl as postfix to the url: http://sample.com/webservice.asmx?wsdl