WSO2 Studio Developer - Data Mapper Mediator - wso2

I am trying to create a Data Mapper mediator that converts from XML to JSON. However, whenever I try to create a link, I get the following error message:
!ENTRY org.wso2.developerstudio.datamapper.diagram 2 0 2018-02-22 12:43:29.804
!MESSAGE Could not save file L/X/Y.dmc : java.lang.ArrayIndexOutOfBoundsException
Here's the XML:
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns0:response xmlns:ns0="http://www.server.com/api/SoapEndpoint">
<return>
<messages>
<code>0</code>
<message>STRING</message>
</messages>
</return>
</ns0:response>
</S:Body>
</S:Envelope>
Here's the JSON schema:
{
"success": true,
"messages": [
{
"code": 0,
"message": "string"
}
]
}
Whenever I try to create a link from the XML code element to the corresponding field in the JSON schema, I get the error message.
Here's my Data Mapper config portion:
<datamapper config="gov:datamapper/Y.dmc" inputSchema="gov:datamapper/A.json" inputType="XML" outputSchema="gov:datamapper/Y.json" outputType="JSON"/>

Found out the issue: when I was importing it into the Data Mapper diagram, the messages element was being interpreted as an Object rather than array. Once I changed it to an array, the mapping started working and the issue went away.

Related

Invoking a BPMN REST Endpoint in WSO2BPS and get payloads in to format xml

I want to use BPMN Service Task and invoke a REST API.
I need to receive requests from the service ESB in format XML.
Example of request:
<?xml version="1.0" encoding="utf-8"?>
<reqSendEvent extrSystem="rout" typeEvent="newRout" xmlns="http://magnit.ru/tanderCoreMassageData.xsd">
<originTime>2017.08.25 15:12:00</originTime>
<content>
<rout>
<name>xxxxx</name>
</rout>
</content>
</reqSendEvent>
servicetask:
<serviceTask id="servicetask1" name="Service Task" activiti:class="org.wso2.developerstudio.bpmn.extensions.restTask.RESTTask">
<extensionElements>
<activiti:field name="serviceURL">
<activiti:expression><![CDATA[http://localhost:9773/tanderBPMN/services/servicetask1]]></activiti:expression>
</activiti:field>
<activiti:field name="method">
<activiti:string><![CDATA[POST]]></activiti:string>
</activiti:field>
<activiti:field name="headers">
<activiti:expression><![CDATA[Content-Type:text/xml]]></activiti:expression>
</activiti:field>
<activiti:field name="outputMappings">
<activiti:string><![CDATA[xxxxxx]]></activiti:string>
</activiti:field>
</extensionElements>
</serviceTask>
In all the examples, using JSON payloads. What do i write expression in to the outputMappings to get value from tag *//rout/name?
You should be able to use a simple String to hold the POST payload and map the parameter to the String.
Have you tried this?
Greg

Getting error while deleting entities in Project server 2013 using asmx web service through Soap UI

I want to remove task from project in project server 2013 using Soap UI via its exposed asmx services, but i am getting ProjectServerError(s) LastError=GeneralUnhandledException while doing operation through Soap UI and java code also.
My request body is :
<proj:QueueDeleteFromProject>
<proj:jobUid>4b86f225-cbe8-e411-a291-005056ad0474</proj:jobUid>
<proj:sessionUid>4b86f225-cbe8-e411-a291-005056ad0473</proj:sessionUid>
<proj:projectUid>4b86f225-cbe8-e411-a291-005056ad0472</proj:projectUid>
<proj:projectEntityUids>
<proj:guid>ee6566d1-cbe8-e411-a291-005056ad0472</guid>
<proj:guid>84d6b846-f4e8-e411-a291-005056ad0472</guid>
</proj:projectEntityUids>
</proj:QueueDeleteFromProject>
And the response is :
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode>s:Server</faultcode>
<faultstring xml:lang="en-US">ProjectServerError(s) LastError=GeneralUnhandledException Instructions: Pass this into PSClientError constructor to access all error information</faultstring>
<detail>
<errinfo>
<general>
<class name="General Unhandled Exception in _Project.QueueDeleteFromProject_">
<error id="42" name="GeneralUnhandledException" uid="ce084759-96f8-e411-97e7-005056ad0472" Exception="System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
at System.Data.SqlClient.SqlBuffer.get_String()
at Microsoft.Office.Project.Server.DataAccessLayer.ProjectDal.GetSessionInfo(Guid projectUid, Guid& sessionID, String& sessionDescription)
at Microsoft.Office.Project.Server.BusinessLayer.Project.ValidateSession(Guid projectUid, Guid sessionUid)
at Microsoft.Office.Project.Server.BusinessLayer.Project.QueueDeleteFromProject(Guid jobUid, Guid sessionUid, Guid projectUid, Guid[] projectEntityUids)
at Microsoft.Office.Project.Server.Wcf.Implementation.ProjectImpl.<>c__DisplayClass75.<QueueDeleteFromProject>b__74()
at Microsoft.Office.Project.Server.Wcf.Implementation.WcfMethodInvocation.InvokeBusinessObjectMethod(String businessObjectName, String methodName, IEnumerable`1 actions)"/>
</class>
</general>
</errinfo>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
Please help me with this issue. Thanks in advance.
Also mention any suggestions if you have.

Soapui property transfer to request header

I want to set the value of token in this soap ws header
<soapenv:Enveloppe ...
<soapenv:Header>
<web:token>123456 </web:token>
FROM step named test get idSession in response
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:authentification xmlns:ns1="http://ws.demowebservices.com/">
<bloc1>
<bloc2>
<idSession>e1c64cd9-b933-4f56-ae1f-0f7d7f23942b</idSession>
</bloc2>
I tried to put in-between web:token tag
${test#Response#//ns1:authentification/bloc1/bloc2/idSession}
but it does not work
What should I put instead ?
I'm not sure if this is what you're trying to achieve, however If you have a SOAP Test step called Test Request and you want to use the value of the <soapenv:Header><web:token></soapenv:Header> of this request in another SOAP Test step you can refer this value in the second SOAP Test step request using the follow syntax:
<soapenv:Enveloppe ...
<soapenv:Header>
<web:token>${Test Request#Request#//soapenv:Header/web:token}</web:token>
The syntax ${Test Request#Request#//soapenv:Header/web:token} has three parts, the name of the test step, followed by the property (could be #Request or #Response), and finally the xpath to get the value //soapenv:Header/web:token.
UPDATED:
As you said you've two SOAP Test Request, the first one is called test an has the follow response:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:authentification xmlns:ns1="http://ws.demowebservices.com/">
<bloc1>
<bloc2>
<idSession>e1c64cd9-b933-4f56-ae1f-0f7d7f23942b</idSession>
</bloc2>
</bloc1>
</ns1:authentification>
</soap:Body>
</soap:Envelope>
The second is named for example test 2 (don't care because the second name not affect your purpose) and has the follow request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<web:token>${test#Response#//ns1:authentification/bloc1/bloc2/idSession}</web:token>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
With ${test#Response#//ns1:authentification/bloc1/bloc2/idSession} you're referencing the idSession value of the test response correctly. Take a look on the http log tab when you send your test 2 as shown in the follow image:
Hope this helps,

WSO2 XML Declaration

I'm using WSO2 ESB 4.0.3 to deploy a simple service. I have a service returning the following XML:
<Employees>
<Employee>
<EmployeeID>JOHNDOE1</EmployeeID>
<FirstName>JOHN</FirstName>
<LastName>DOE</LastName>
</Employee>
<Status>1</Status>
</Employees>
The problem I'm having is that there is no XML declaration. Is there a setting that will return the response with the XML declaration included, or do I need to use the ESB response to add it? I was hoping for something like:
<?xml version="1.0" encoding="utf-8"?>
<Employees>
<Employee>
<EmployeeID>JOHNDOE1</EmployeeID>
<FirstName>JOHN</FirstName>
<LastName>DOE</LastName>
</Employee>
<Status>1</Status>
</Employees>
Any help is appreciated.
This is an old question, but seeing as I ran into the same thing just now I'll post my solution.
I needed to have a proxy service return a plain XML message without the enclosing soap envelope. I tried using application/xml and text/xml (org.apache.axis2.transport.http.ApplicationXMLFormatter and org.wso2.carbon.relay.ExpandingMessageFormatter respectively) content types to no avail. Neither of these content types returned the message with the XML declaration.
The solution is to write a custom message formatter. Here's my implementation that behaves like org.apache.axis2.transport.http.ApplicationXMLFormatter but properly writes the XML declaration to the message.
package com.example.axis2.messageformatter;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.transport.http.ApplicationXMLFormatter;
public class CustomApplicationXmlFormatter extends ApplicationXMLFormatter {
#Override
public void writeTo(MessageContext context, OMOutputFormat format, OutputStream out, boolean preserve) throws AxisFault {
String xmlHeader = "<?xml version=\"1.0\" encoding=\"" + format.getCharSetEncoding() + "\"?>";
try {
out.write(xmlHeader.getBytes());
} catch (IOException e) {
throw new AxisFault("Unable to write XML declaration to output stream.", e);
}
super.writeTo(context, format, out, preserve);
}
}
You can drop the class in a jar file to <ESB_ROOT>/repository/components/lib.
Additionally you need to refer to the class from the axis2 config (<ESB_ROOT>/repository/conf/axis2/axis2.xml) by adding the following into the message formatters portion of the file:
<messageFormatter contentType="application/xml" class="com.example.axis2.messageformatter.CustomApplicationXmlFormatter"/>
As Kallja answered before - messageFormatter should be fixed.
I've implemented his fix as a maven-based project - available here: https://github.com/akakunin/custom-appxml-message-formatter
I've tested it with WSO2 EI 6.0.0 - it works fine for me.
Just putting this here in case someone else stumbles upon the same issue, WSO2 now support this OOTB with the following axis2 property
<property name="WRITE_XML_DECLARATION" scope="axis2" value="true"/>
source for this - https://github.com/wso2/wso2-axis2/blob/master/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java#L53
How you captured SOAP message? You can use Tcpmon or just add a log mediator with log level full to observe the complete the complete message. I assume you what you have observed is SOAP body. You do not need to add xml declaration etc. manually.
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>

How to retrieve result from WebService response?

I am new to WebService. I am getting the following response from the WebService
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header/>
<S:Body><ns2:getGreetingResponse xmlns:ns2="http://wsserver.myfirst.com/">
<return>Hello Cheepu</return>
</ns2:getGreetingResponse></S:Body></S:Envelope>
Result in the XML is "Hello Cheepu". How can i retrieve that from the response.
You may load the XML DOM with code such as:
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(text,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(text);
}
Then traverse the DOM to the element.
This code is for javaScrip at the browser. Similar code in Java as given in http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/