I got a problem in rest api project in wso2 integration studio - wso2

I Have this xml:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/testapi" name="testapi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" url-mapping="/testapi">
<inSequence>
<property expression="get-property('query.param.qp')" name="qp1" scope="default" type="STRING"/>
<property expression="$ctx:query.param.qp" name="qp2" scope="default" type="STRING"/>
<property expression="$url:qp" name="qp3" scope="default" type="STRING"/>
<payloadFactory media-type="json">
<format> {"Method1":"$1",
"Method2":"$2",
"Method3":"$3"}</format>
<args>
<arg evaluator="xml" expression="get-property('qp1')"/>
<arg evaluator="xml" expression="get-property('qp2')"/>
<arg evaluator="xml" expression="get-property('qp3')"/>
</args>
</payloadFactory>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
when validating the code in the integration studio these problems appears:
Element 'format' cannot have character [children], because the type's content type is element-only. testapi.xml /test1/test1Configs/src/main/synapse-config/api line 9 XML Problem
The content of element 'faultSequence' is not complete. One of '{"http://ws.apache.org/ns/synapse":call, "http://ws.apache.org/ns/synapse":call-template, "http://ws.apache.org/ns/synapse":drop, "http://ws.apache.org/ns/synapse":log, "http://ws.apache.org/ns/synapse":loopback, "http://ws.apache.org/ns/synapse":property, "http://ws.apache.org/ns/synapse":propertyGroup, "http://ws.apache.org/ns/synapse":respond, "http://ws.apache.org/ns/synapse":send, "http://ws.apache.org/ns/synapse":sequence, "http://ws.apache.org/ns/synapse":store, "http://ws.apache.org/ns/synapse":conditionalRouter, "http://ws.apache.org/ns/synapse":filter, "http://ws.apache.org/ns/synapse":switch, "http://ws.apache.org/ns/synapse":validate, "http://ws.apache.org/ns/synapse":bean, "http://ws.apache.org/ns/synapse":class, "http://ws.apache.org/ns/synapse":pojoCommand, "http://ws.apache.org/ns/synapse":ejb, "http://ws.apache.org/ns/synapse":script, "http://ws.apache.org/ns/synapse":spring, "http://ws.apache.org/ns/synapse":enrich, "http://ws.apache.org/ns/synapse":makefault, "http://ws.apache.org/ns/synapse":header, "http://ws.apache.org/ns/synapse":payloadFactory, "http://ws.apache.org/ns/synapse":jsontransform, "http://ws.apache.org/ns/synapse":smooks, "http://ws.apache.org/ns/synapse":rewrite, "http://ws.apache.org/ns/synapse":xquery, "http://ws.apache.org/ns/synapse":xslt, "http://ws.apache.org/ns/synapse":datamapper, "http://ws.apache.org/ns/synapse":fastXSLT, "http://ws.apache.org/ns/synapse":cache, "http://ws.apache.org/ns/synapse":dblookup, "http://ws.apache.org/ns/synapse":dbreport, "http://ws.apache.org/ns/synapse":enqueue, "http://ws.apache.org/ns/synapse":event, "http://ws.apache.org/ns/synapse":throttle, "http://ws.apache.org/ns/synapse":transaction, "http://ws.apache.org/ns/synapse":aggregate, "http://ws.apache.org/ns/synapse":callout, "http://ws.apache.org/ns/synapse":clone, "http://ws.apache.org/ns/synapse":iterate, "http://ws.apache.org/ns/synapse":foreach, "http://ws.apache.org/ns/synapse":entitlementService, "http://ws.apache.org/ns/synapse":oauthService, "http://ws.apache.org/ns/synapse":builder, "http://ws.apache.org/ns/synapse":rule, "http://ws.apache.org/ns/synapse":bam, "http://ws.apache.org/ns/synapse":publishEvent, "http://ws.apache.org/ns/synapse":NTLM}' is expected. testapi.xml /test1/test1Configs/src/main/synapse-config/api line 3 XML Problem
The content of element 'outSequence' is not complete. One of '{"http://ws.apache.org/ns/synapse":call, "http://ws.apache.org/ns/synapse":call-template, "http://ws.apache.org/ns/synapse":drop, "http://ws.apache.org/ns/synapse":log, "http://ws.apache.org/ns/synapse":loopback, "http://ws.apache.org/ns/synapse":property, "http://ws.apache.org/ns/synapse":propertyGroup, "http://ws.apache.org/ns/synapse":respond, "http://ws.apache.org/ns/synapse":send, "http://ws.apache.org/ns/synapse":sequence, "http://ws.apache.org/ns/synapse":store, "http://ws.apache.org/ns/synapse":conditionalRouter, "http://ws.apache.org/ns/synapse":filter, "http://ws.apache.org/ns/synapse":switch, "http://ws.apache.org/ns/synapse":validate, "http://ws.apache.org/ns/synapse":bean, "http://ws.apache.org/ns/synapse":class, "http://ws.apache.org/ns/synapse":pojoCommand, "http://ws.apache.org/ns/synapse":ejb, "http://ws.apache.org/ns/synapse":script, "http://ws.apache.org/ns/synapse":spring, "http://ws.apache.org/ns/synapse":enrich, "http://ws.apache.org/ns/synapse":makefault, "http://ws.apache.org/ns/synapse":header, "http://ws.apache.org/ns/synapse":payloadFactory, "http://ws.apache.org/ns/synapse":jsontransform, "http://ws.apache.org/ns/synapse":smooks, "http://ws.apache.org/ns/synapse":rewrite, "http://ws.apache.org/ns/synapse":xquery, "http://ws.apache.org/ns/synapse":xslt, "http://ws.apache.org/ns/synapse":datamapper, "http://ws.apache.org/ns/synapse":fastXSLT, "http://ws.apache.org/ns/synapse":cache, "http://ws.apache.org/ns/synapse":dblookup, "http://ws.apache.org/ns/synapse":dbreport, "http://ws.apache.org/ns/synapse":enqueue, "http://ws.apache.org/ns/synapse":event, "http://ws.apache.org/ns/synapse":throttle, "http://ws.apache.org/ns/synapse":transaction, "http://ws.apache.org/ns/synapse":aggregate, "http://ws.apache.org/ns/synapse":callout, "http://ws.apache.org/ns/synapse":clone, "http://ws.apache.org/ns/synapse":iterate, "http://ws.apache.org/ns/synapse":foreach, "http://ws.apache.org/ns/synapse":entitlementService, "http://ws.apache.org/ns/synapse":oauthService, "http://ws.apache.org/ns/synapse":builder, "http://ws.apache.org/ns/synapse":rule, "http://ws.apache.org/ns/synapse":bam, "http://ws.apache.org/ns/synapse":publishEvent, "http://ws.apache.org/ns/synapse":NTLM}' is expected. testapi.xml /test1/test1Configs/src/main/synapse-config/api line 3 XML Problem
Cannot find the declaration of element 'project'. pom.xml /test1/test1CompositeExporter line 3 XML Problem
Referenced file contains errors (jar:file:/D:/WSO2-Integration-Studio-8.1.0-win32-x86_64/IntegrationStudio/plugins/org.wso2.integrationstudio.gmf.esb.diagram_8.1.0.202211111317.jar!/resources/schema/endpoint.xsd). For more information, right click on the message in the Problems View and select "Show Details..." testapi.xml /test1/test1Configs/src/main/synapse-config/api line 1 XML Problem
I try to build rest api with wso2 integration studio

You have to delete those Caracters "&#xd" from your JSON Payload as below :
<?xml version="1.0" encoding="UTF-8"?>
<api context="/testapi" name="testapi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" url-mapping="/testapi">
<inSequence>
<property expression="get-property('query.param.qp')" name="qp1" scope="default" type="STRING"/>
<property expression="$ctx:query.param.qp" name="qp2" scope="default" type="STRING"/>
<property expression="$url:qp" name="qp3" scope="default" type="STRING"/>
<payloadFactory media-type="json">
<format> {"Method1":"$1",
"Method2":"$2",
"Method3":"$3"}</format>
<args>
<arg evaluator="xml" expression="get-property('qp1')"/>
<arg evaluator="xml" expression="get-property('qp2')"/>
<arg evaluator="xml" expression="get-property('qp3')"/>
</args>
</payloadFactory>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>

Related

Extracting binary as base64 String results in incomplete file?

I am trying to extract binary from soap response and convert it to base64 string but what happens is that I get part of the binary converted to base64 not the full binary data.
Integration Studio : 8.1.0
the soap response is as following :
--A-B--MIME-BOUNDARY--27d99311536fa8c4-18606176189--Y-Z
Content-Transfer-Encoding: binary
Content-Type: application/xop+xml; type="application/soap+xml"; charset=UTF-8
Content-ID:
<v0-27d99311536fa8c4-18606176189#mtom.p8ce.filenet.com>
<?xml version="1.0" encoding="UTF-8"?>
<e:Envelope xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:fn35="http://www.filenet.com/ns/fnce/2005/02/ws/schema" xmlns:fn40m="http://www.filenet.com/ns/fnce/2006/11/ws/MTOM/schema" xmlns:fn40="http://www.filenet.com/ns/fnce/2006/11/ws/schema" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:e="http://schemas.xmlsoap.org/soap/envelope/">
<e:Body>
<GetContentResponse xmlns="http://www.filenet.com/ns/fnce/2006/11/ws/schema">
<ContentResponse id="1" i:type="fn40:ContentElementResponse" retrievalName="test.pdf" totalSize="4586622" bufferedSize="1048576" continueFrom="offset=1048576;id={B3795692-DA06-468C-AEC9-523A3715455D};">
<SourceSpecification i:type="fn40:ObjectReference" classId="Document" objectId="{E408981D-FF67-4D91-B7A9-CEBEC4630AB0}" objectStore="MCIDEV"></SourceSpecification>
<ElementSpecification elementSequenceNumber="0"></ElementSpecification>
<Content i:type="fn40:InlineContent">
<Binary>
<xop:Include href="cid:v1-27d99311536fa8c4-18606176189#mtom.p8ce.filenet.com"></xop:Include>
</Binary>
</Content>
</ContentResponse>
</GetContentResponse>
</e:Body>
</e:Envelope>
--A-B--MIME-BOUNDARY--27d99311536fa8c4-18606176189--Y-Z
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream
Content-Id:
<v1-27d99311536fa8c4-18606176189#mtom.p8ce.filenet.com>
%PDF-1.4
......
......
......
--A-B--MIME-BOUNDARY--27d99311536fa8c4-18606176189--Y-Z--
The code to extract the binary and convert it to base64 string is as follows :
<property expression="$body/fn:GetContentResponse/fn:ContentResponse/fn:Content/fn:Binary" name="DataBase64" scope="default" type="STRING" xmlns:fn="http://www.filenet.com/ns/fnce/2006/11/ws/schema"/>
My service code is as follows :
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="StorageGetDocumentSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<propertyGroup>
<property expression="json-eval($.username)" name="Username" scope="default" type="STRING"/>
<property expression="json-eval($.password)" name="Password" scope="default" type="STRING"/>
<property expression="json-eval($.objectStore)" name="ObjectStore" scope="default" type="STRING"/>
<property name="DocumentClass" scope="default" type="STRING" value="Document"/>
<property expression="json-eval($.documentId)" name="DocumentId" scope="default" type="STRING"/>
<property expression="json-eval($.version)" name="Version" scope="default" type="STRING"/>
</propertyGroup>
<sequence key="StorageRequestValidatorSeq"/>
<script description="Response Builder" language="js"><![CDATA[var errors = [];
var errorProperties = mc.getPropertyKeySet();
var it = errorProperties.iterator();
var i = 1;
while(it.hasNext()){
var prop = it.next();
if (prop.contains('Error')) {
print(prop.toString());
errors.push(mc.getProperty(prop));
}
}
mc.setProperty('errorList', "[" + errors.toString() + "]");]]></script>
<filter regex="false" source="get-property('IsValid')">
<then>
<payloadFactory description="Response Payload" media-type="json">
<format>
{"errorCode":400,"errorMessage":"One or more validation error","errorList":$1}</format>
<args>
<arg evaluator="xml" expression="get-property('errorList')"/>
</args>
</payloadFactory>
<property description="Set 400 response code" name="HTTP_SC" scope="axis2" type="STRING" value="400"/>
<respond description="Response to client"/>
</then>
<else/>
</filter>
<sequence key="StorageGetMimeTypeSeq"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext">
<hd:UsernameToken xmlns:hd="http://schemas.xmlsoap.org/ws/2002/12/secext">
<hd:Username>$1</hd:Username>
<hd:Password>$2</hd:Password>
</hd:UsernameToken>
</Security>
</soapenv:Header>
<soapenv:Body>
<p857:GetContentRequest validateOnly="0" xmlns:p857="http://www.filenet.com/ns/fnce/2006/11/ws/schema">
<p857:ContentRequest continueFrom="" cacheAllowed="1" id="1" startOffset="0">
<p857:SourceSpecification classId="$4" itemIndex="0" objectId="$5" objectStore="$3"
serializationDuplicate="0" xsi:type="p857:ObjectSpecification"/>
<p857:ElementSpecification elementSequenceNumber="0" itemIndex="0"/>
</p857:ContentRequest>
</p857:GetContentRequest>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('Username')"/>
<arg evaluator="xml" expression="get-property('Password')"/>
<arg evaluator="xml" expression="get-property('ObjectStore')"/>
<arg evaluator="xml" expression="get-property('DocumentClass')"/>
<arg evaluator="xml" expression="get-property('DocumentId')"/>
</args>
</payloadFactory>
<call-template target="StorageEndpointTemplate"/>
<propertyGroup>
<property expression="$axis2:HTTP_SC" name="HTTPStatus" scope="default" type="STRING"/>
<property expression="$body/e:Fault/e:Reason/e:Text" name="ErrorMessage" scope="default" type="STRING" xmlns:e="http://www.w3.org/2003/05/soap-envelope"/>
<property expression="$body/fn:GetContentResponse/fn:ContentResponse/#retrievalName" name="FileName" scope="default" type="STRING" xmlns:fn="http://www.filenet.com/ns/fnce/2006/11/ws/schema"/>
<property expression="$body/fn:GetContentResponse/fn:ContentResponse/#totalSize" name="FileSize" scope="default" type="STRING" xmlns:fn="http://www.filenet.com/ns/fnce/2006/11/ws/schema"/>
<property expression="$body/fn:GetContentResponse/fn:ContentResponse/fn:Content/fn:Binary" name="DataBase64" scope="default" type="STRING" xmlns:fn="http://www.filenet.com/ns/fnce/2006/11/ws/schema"/>
</propertyGroup>
<log level="headers"/>
<log level="custom">
<property expression="get-property('FileName')" name="FileNameLog"/>
<property expression="get-property('FileSize')" name="FileSizeLog"/>
</log>
<filter regex="true" source="boolean(get-property('ErrorMessage'))=''">
<then>
<payloadFactory media-type="json">
<format>
{
"fileName":"$1",
"fileSize": $2,
"mimeType":"$3",
"dataBase64":"$4"
}
</format>
<args>
<arg evaluator="xml" expression="get-property('FileName')"/>
<arg evaluator="xml" expression="get-property('FileSize')"/>
<arg evaluator="xml" expression="get-property('MimeType')"/>
<arg evaluator="xml" expression="get-property('DataBase64')"/>
</args>
</payloadFactory>
</then>
<else>
<property name="HTTP_SC" scope="axis2" type="STRING" value="400"/>
<payloadFactory description="Response Payload" media-type="json">
<format>{"errorCode": "$1","errorMessage": "$2"}</format>
<args>
<arg value="400"/>
<arg evaluator="xml" expression="get-property('ErrorMessage')"/>
</args>
</payloadFactory>
</else>
</filter>
</sequence>
EDIT : I also tried the base64Encode as follows :
<property expression="base64Encode($body/fn:GetContentResponse/fn:ContentResponse/fn:Content/fn:Binary)" name="DataBase64" scope="default" type="STRING" xmlns:fn="http://www.filenet.com/ns/fnce/2006/11/ws/schema"/>
And it also results in corrupted base64String
I found out that the issue was not related to WSO2 at all but a filenet limitation
Inline Content Retrieval Limit default is 1 MB so that filenet API itself was returning 1 MB only of the file.
https://www.ibm.com/docs/en/filenet-p8-platform/5.5.x?topic=engine-improving-content-uploads-downloads

WSO2 EI: empty fields ("") are added as null in the payload transformation

I'm retrieving some data's from DSS by using select query and then some transformation by payload factory after that I'm passing it to an endpoint, but when I do that the empty fields are being passed as null and not as empty strings ""
"department":"{department":null}",
"Selling_dealer__c":"{Selling_dealer__c":null}"
I wish it really showed like this:
"department":"",
"Selling_dealer__c":""
Note: Also tried the synapse properties file method but not working as excepted refer link 1 refer link 2
<sequence name="LaravelConnectorSequence" xmlns="http://ws.apache.org/ns/synapse">
<payloadFactory media-type="json">
<format>
{
"screen_type": "opportunity",
"vehicle_type__c": "",
"description": "",
"audio_file_name__c": "$1",
"lead_type__c": "Phone",
"request_type__c": "",
"mobile__c": "$2",
"leadsource": "Novum",
"company__c": "N/A",
"location__c": "$3",
"department__c": "$4",
"selling_dealer__c":"$5"
}
</format>
<args>
<arg evaluator="xml"
expression="get-property('audioFileName')"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="get-property('mobile')"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="get-property('location')"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="get-property('department')"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml"
expression="get-property('selling_dealer__c')"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
<log level="custom">
<property expression="json-eval($)"
name="=======Laravel Request====" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<property expression="get-property('Novum-configs')" name="config"
scope="axis2" type="OM" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="$axis2:config//*[local-name()='laravelToken']"
name="Authorization" scope="transport" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="$axis2:config//*[local-name()='laravelURL']"
name="uri.var.laravelapi" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<call>
<endpoint>
<http method="POST" uri-template="{uri.var.laravelapi}"/>
</endpoint>
</call>
<log level="custom">
<property expression="json-eval($)"
name="=======Laravel Response====" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
Since you want to convert your null values into "" strings, one workaround would be to convert the JSON to XML and then extract the elements from that and add them to your final JSON payload. In WSO2 there are different options you can set when converting JSON payloads. You can read about different options and how to work with JSON messages from here.
Since you want null to be "". You need to set the following property. If you are on MI this needs to go into deployment.toml, if on EI this goes into synapse.properties
'synapse.commons.enableXmlNullForEmptyElement'=false
Note: In MI (Surround the property name with single quotes)
When you are extracting data from the DSS response make sure to use Xpath expressions instead of JSON path expressions. Following is a simplified version of your configurations. Note I have hardcoded the DSS response.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/api" name="RESTApi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" url-mapping="/sample">
<inSequence>
<payloadFactory media-type="json">
<format>{"Selling_dealer__c": null}</format>
<args/>
</payloadFactory>
<property expression="//Selling_dealer__c" name="logInJson" scope="default" type="STRING"/>
<payloadFactory media-type="json">
<format>
{
"screen_type": "opportunity",
"selling_dealer__c": "$1"
}
</format>
<args>
<arg evaluator="xml" expression="$ctx:logInJson"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Above will produce the following response.
{
"screen_type": "opportunity",
"selling_dealer__c": "{"Selling_dealer__c":""}"
}
I used the script mediator to overcome this issue.
<script language="js"><![CDATA[var log=mc.getServiceLog();
var dep = mc.getProperty('department').toString();
var sell = mc.getProperty('selling_dealer__c').toString();
//log.info("===DepartmentValue===: "+dep);
var deps = mc.getProperty('department').startsWith("<Department");
//log.info("++++++++++++++++++++TRUE VALUE++++++++++++++++++"+deps);
if(dep.startsWith("<Department"))
{
dep ="";
mc.setProperty('department',dep);
}
//log.info("===DepartmentValueAfter===: "+dep)
//log.info("===SellingDealerValue===: "+sell);
var sells = mc.getProperty('selling_dealer__c').startsWith("<selling_dealer__c");
//log.info("++++++++++++++++++++TRUE VALUE++++++++++++++++++"+sells);
if(sell.startsWith("<selling_dealer__c"))
{
sell ="";
mc.setProperty('selling_dealer__c',sell);
}
//log.info("===selling_dealer__cValueAfter===: "+sell)
]]></script>

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.

Iterate Mediator sends duplicate payload almost always

We are trying out a scenario where we want to iterate over a list of nodes and make a POST call to some service with each individual request payload. We are seeing the iterate mediator actually sends two elements in that call and
that causes issues on the API end.
I have a mock service deployed locally that returns response say :
<result>
<row>
<product_id>8351</product_id>
<event_key>17708</event_key>
<event_code>AEONBM</event_code>
<show_title>Some Show</show_title>
<venue_name>Eugene ONeill Theatre</venue_name>
<area>ORCHC</area>
<row>C</row>
<seat_num>103</seat_num>
<seat_increment>1</seat_increment>
<marketing_code>PREMIUM</marketing_code>
<Cost>352.0000</Cost>
</row>
<row>
<product_id>8351</product_id>
<event_key>17708</event_key>
<event_code>AEONBM</event_code>
<show_title>Some Show</show_title>
<venue_name>Eugene ONeill Theatre</venue_name>
<area>ORCHC</area>
<row>C</row>
<seat_num>104</seat_num>
<seat_increment>1</seat_increment>
<marketing_code>PREMIUM</marketing_code>
<Cost>352.0000</Cost>
</row
</result>
Here is how my proxy service looks like:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="CreateListingFromGetLocation"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full">
<property name="text" value="Triggering getLocation API call.."/>
</log>
<send receive="createListingsFromGetLocationResponseSequence">
<endpoint>
<http method="get" uri-template="http://localhost:8989/GetLocation/"/>
</endpoint>
</send>
<property name="OUT_ONLY" value="true"/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
<description/>
</proxy>
Here is my receiving sequence that is using the iterate mediator:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="createListingsFromGetLocationResponseSequence">
<iterate xmlns:tem="http://tempuri.org" xmlns:ns="http://org.apache.synapse/xsd" expression="//result/row">
<target>
<sequence>
<log level="full">
<property name="LocationRow" value="Row element from GetLocationResponse"></property>
</log>
<payloadFactory media-type="xml">
<format>
<listing xmlns="">
<eventId>$1</eventId>
<eventDescription>$2</eventDescription>
<pricePerTicket>
<amount>$3</amount>
<currency>USD</currency>
</pricePerTicket>
<quantity>$4</quantity>
<section>$5</section>
<rows>$6</rows>
<seats>$7</seats>
<splitOption>NONE</splitOption>
</listing>
</format>
<args>
<arg expression="//event_key" evaluator="xml"></arg>
<arg expression="//show_title" evaluator="xml"></arg>
<arg expression="//Cost" evaluator="xml"></arg>
<arg expression="//seat_increment" evaluator="xml"></arg>
<arg expression="//area" evaluator="xml"></arg>
<arg expression="//row/row" evaluator="xml"></arg>
<arg expression="//seat_num" evaluator="xml"></arg>
</args>
</payloadFactory>
<log level="full">
<property name="ListingRequest" value="Listing request xml"></property>
</log>
<property name="Content-Type" value="application/xml" scope="transport" type="STRING"></property>
<property name="messageType" value="application/xml" scope="transport" type="STRING"></property>
<property name="TARGET_HOST" value="srwd30" scope="transport" type="STRING"></property>
<property name="HTTP_METHOD" value="POST" scope="transport" type="STRING"></property>
<send>
<endpoint>
<http format="pox" method="post" uri-template="http://www.srwd30.com/listings/v1/"></http>
</endpoint>
</send>
</sequence>
</target>
</iterate>
</sequence>
Firstly, I see that it is iterating over each xml node properly, here are some logs indicating that:
[2014-04-22 13:29:42,020] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:3bc14a33-3a7a-478e-bdbf-720f1ec855a5, Direction: response, LocationRow = Row element from GetLocationResponse, Envelope: <?xml version="1.0" encoding="utf-8
"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><row>
<product_id>8351</product_id>
<event_key>17708</event_key>
<event_code>AEONBM</event_code>
<show_title>Some Show</show_title>
<venue_name>Eugene ONeill Theatre</venue_name>
<area>ORCHC</area>
<row>D</row>
<seat_num>103</seat_num>
<seat_increment>1</seat_increment>
<marketing_code>PREMIUM</marketing_code>
<Cost>352.0000</Cost>
</row></soapenv:Body></soapenv:Envelope>
[2014-04-22 13:29:42,021] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:0e04ac15-a0bf-41a3-a7d7-80a1401d3efc, Direction: response, ListingRequest = Listing request xml, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:En
velope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><listing><eventId>17708</eventId><eventDescription>Some Show</eventDescription><pricePerTicket><amount>352.0000</amount><currency>USD</currency></pricePerTicket><quantity>1</quantity><section>ORCHC</section><rows
>C</rows><seats>103</seats><splitOption>NONE</splitOption></listing></soapenv:Body></soapenv:Envelope>
But on my API I see that we are receiving duplicate or two root nodes:
Content-Type: application/xml
Headers: {cache-control=[no-cache], connection=[Keep-Alive],
content-type=[application/xml], host=[www.srwd30.com], http_method=[POST], messagetype=[application/xml], target_host=[srwd30], transfer-encoding=
[chunked], user-agent=[Synapse-PT-HttpComponents-NIO]}
Payload: <listing><eventId>17708</eventId><eventDescription>Some Show</eventDescription><pricePerTicket><amount>352.0000</amount><currency>USD</currenc
y></pricePerTicket><quantity>1</quantity><section>ORCHC</section><rows>C</rows><seats>103</seats><splitOption>NONE</splitOption></listing><listing><eventId>1770
8</eventId><eventDescription>Some Show</eventDescription><pricePerTicket><amount>352.0000</amount><currency>USD</currency></pricePerTicket><quantity>1<
/quantity><section>ORCHC</section><rows>D</rows><seats>104</seats><splitOption>NONE</splitOption></listing>
--------------------------------------
2014-04-22 19:01:51,468 [e14f#fbf/http://www.srwd30.com/listings/v1/] priority=WARN app_name=shared-stubhubjobs thread=http-0.0.0.0-
8080-8 location=AbstractJAXBProvider line=112 javax.xml.bind.UnmarshalException
- with linked exception:
[com.ctc.wstx.exc.WstxParsingException: Illegal to have multiple roots (start tag in epilog?).
at [row,col {unknown-source}]: [1,291]]
From the looks of it, iterator is sending two elements when I make that send call. Am i missing something or doing something wrong? How can make each call independent from other?
I got the issue resolved by adding a Action header using urn:test value for that header. I realized that this was causing that duplicate requests to be sent and sometimes only one request being sent even if the iterator has about 10 records.
<proxy name="PushInventory"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<log level="full">
<property name="STATUS"
value="+++++++++++++++++ Inside PushInventory Proxy Service ++++++++++++++++++"/>
</log>
<iterate xmlns:tem="http://tempuri.org"
xmlns:ns="http://org.apache.synapse/xsd"
id="pushInventoryIterator"
expression="//result/row"
sequential="true">
<target>
<sequence>
<payloadFactory media-type="xml">
<format>
<listing xmlns="">
<eventId>$1</eventId>
<eventDescription>$2</eventDescription>
<pricePerTicket>
<amount>$3</amount>
<currency>USD</currency>
</pricePerTicket>
<quantity>$4</quantity>
<section>$5</section>
<rows>$6</rows>
<seats>$7</seats>
<splitOption>NONE</splitOption>
</listing>
</format>
<args>
<arg evaluator="xml" expression="//event_key"/>
<arg evaluator="xml" expression="//show_title"/>
<arg evaluator="xml" expression="//Cost"/>
<arg evaluator="xml" expression="//seat_increment"/>
<arg evaluator="xml" expression="//area"/>
<arg evaluator="xml" expression="//row_desc"/>
<arg evaluator="xml" expression="//seat_num"/>
</args>
</payloadFactory>
<log level="full">
<property name="STATUS"
value="++++++++++++ Invoking Listing EndPoint ++++++++++++++"/>
</log>
<property name="Authorization"
value="Basic dafdsfadsfdsafdsfdsafdsafsdfadsf"
scope="transport"
type="STRING"/>
<property name="Content-Type"
value="application/xml"
scope="transport"
type="STRING"/>
<property name="messageType"
value="application/xml"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="transport" type="STRING"/>
<header name="Action" scope="default" value="urn:test"/>
<send>
<endpoint key="ListingEndPoint"/>
</send>
</sequence>
</target>
</iterate>
</inSequence>
<outSequence>
<log level="full">
<property name="STATUS"
value="+++++++++++++++++ Inside OutSequence of PushInventory ++++++++++++++++++"/>
</log>
<aggregate>
<completeCondition>
<messageCount min="10" max="10"/>
</completeCondition>
<onComplete xmlns:ns2="com.blah.blah" expression="//listing">
<log level="full" separator=",">
<property name="STATUS"
value="+++++++++++++++++ Aggregating responses back ++++++++++++++++++"/>
</log>
<enrich>
<source type="envelope" clone="true"/>
<target type="body"/>
</enrich>
<send/>
</onComplete>
</aggregate>
</outSequence>
</target>
</proxy>
You put your log before the iterator mediator and see what you're receiving from the endpoint. It may contain duplicate entries. Then within iterate you have another log mediator. Check for records are right.

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