WSO2 Api Manager 3.2.0 How Expose a SOAP Service as a REST API - wso2

I Use this document but this is Don't work:
https://apim.docs.wso2.com/en/3.2.0/learn/tutorials/expose-a-soap-service-as-a-rest-api/
for example automatic create this mediator for input and it's not work :
<header description="SOAPAction" name="SOAPAction" scope="transport" value="http://tempuri.org/ILivePublisher/Candles"/>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<property expression="json-eval($.Candles.instrumentIsin)" name="req.var.Candles.instrumentIsin"/>
<property expression="json-eval($.Candles.interval.Interval)" name="req.var.Candles.interval.Interval"/>
<property expression="json-eval($.Candles.since)" name="req.var.Candles.since"/>
<property expression="json-eval($.Candles.to)" name="req.var.Candles.to"/>
<payloadFactory description="transform" media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<web:Candles xmlns:web="http://tempuri.org/">
<web:instrumentIsin>$1</web:instrumentIsin>
<web:interval>
<web:Interval>$2</web:Interval>
</web:interval>
<web:since>$3</web:since>
<web:to>$4</web:to>
</web:Candles>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('req.var.Candles.instrumentIsin')"/>
<arg evaluator="xml" expression="get-property('req.var.Candles.interval.Interval')"/>
<arg evaluator="xml" expression="get-property('req.var.Candles.since')"/>
<arg evaluator="xml" expression="get-property('req.var.Candles.to')"/>
</args>
</payloadFactory>
<property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>

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

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

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>

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 change reply to send to the caller

Sorry for my English, I'm using Google Translate to help myself.
I'm writing an API call to a web service. The call is ok and the api returns the response to the caller service, but the client wants that the output of the end-point must be changed from WSO2.
I added this outSequence to the api but the return is a returncode 202 without body.
Can someone help me please?
<outSequence>
<sequence key="">
<payloadFactory media-type="json">
<format>
{ "status": "1",
"message": $2
}
</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')"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<send/>
</sequence>
</outSequence>
I think you should try something like this instead
<inSequence>
<sequence key="">
<payloadFactory media-type="json">
<format>
{ "status": "1",
"message": $2
}
</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')"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<send/>
</inSequence>
<outSequence>
<property expression="json-eval($)" name="body-before-aggreg" scope="default" type="STRING"/>
<aggregate>
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete aggregateElementType="root" expression="json-eval($)">
<!--get back from send body here in outsequence!-->
<respond/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence>
<log level="custom">
<property name="text" value="An unexpected error occured for service"/>
<property expression="get-property('ERROR_MESSAGE')" name="message"/>
</log>
<respond/>
</faultSequence>
</resource>
</api>
please note that when you use send -> response messages will go through the Out mediator.

Wso2 EI 7.1.0 response processing slow

I am using Wso2 EI 7.1.0 for one of my ESB use case. I implemented flow like API mediator-->Iterate mediator-->Send mediator--->Aggregate--->Payload Factory--->Respond, here I am facing more time taking at Payload Factory while responding, I am using default configurations and I tested this at Linux 16 Core + 32 GB RAM server. I am adding template XML, please assist.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/cbr" name="CBRAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<script language="groovy"><![CDATA[def start_time = System.currentTimeMillis();
mc.setProperty('start_time',start_time);]]></script>
<class description="" name="com.custom.wso2.plugin.ot.CacheBuildMediator">
<property name="DB_CONFIG" value="jdbc:mysql://<IP>:3306/WSO2,user,password,com.mysql.cj.jdbc.Driver"/>
</class>
<propertyGroup>
<property name="TRIGGER_NAME" scope="default" type="STRING" value="TIG1"/>
<property expression="//soapenv:Envelope" name="payload" scope="default" type="STRING" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices"/>
<property expression="//soapenv:Envelope/soapenv:Body/wos:WorkOrderRequestMsg/WorkOrderRequest/wos:OrderParam[wos:Code='SubscriberNo']/wos:Value" name="SubscriberNo" scope="axis2" type="STRING" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices"/>
<property expression="//soapenv:Envelope/soapenv:Body/wos:WorkOrderRequestMsg/WorkOrderRequest/wos:OrderParam[wos:Code='RechargeAmount']/wos:Value" name="RechargeAmount" scope="axis2" type="STRING" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices"/>
<property expression="//soapenv:Envelope/soapenv:Body/wos:WorkOrderRequestMsg/WorkOrderRequest/wos:OrderParam[wos:Code='RechargeChannelID']/wos:Value" name="RechargeChannelID" scope="axis2" type="STRING" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices"/>
<property expression="//soapenv:Envelope/soapenv:Body/wos:WorkOrderRequestMsg/WorkOrderRequest/wos:OrderParam[wos:Code='RechargeType']/wos:Value" name="RechargeType" scope="axis2" type="STRING" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices"/>
<property expression="//soapenv:Envelope/soapenv:Body/wos:WorkOrderRequestMsg/WorkOrderRequest/wos:OrderParam[wos:Code='CurrencyID']/wos:Value" name="CurrencyID" scope="axis2" type="STRING" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices"/>
<property expression="//soapenv:Envelope/soapenv:Body/wos:WorkOrderRequestMsg/WorkOrderRequest/wos:OrderParam[wos:Code='RechargeTime']/wos:Value" name="RechargeTime" scope="axis2" type="STRING" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices"/>
</propertyGroup>
<class name="com.custom.wso2.plugin.ot.MvelExecuteMediator"/>
<script language="groovy"><![CDATA[def payload=mc.getProperty('RULE_PAYLOAD');
def curr_time=System.currentTimeMillis();
def time= (curr_time- mc.getProperty('start_time'));
mc.setProperty('mvel_exe_time',time);
mc.setProperty('db_report_time',curr_time);
mc.setPayloadXML(payload);]]></script>
<dbreport>
<connection>
<pool>
<driver>com.mysql.cj.jdbc.Driver</driver>
<url>jdbc:mysql://IP:3306/WSO2</url>
<user>user</user>
<password>password</password>
<property name="maxidle" value="10"/>
<property name="initialsize" value="10"/>
<property name="maxactive" value="10"/>
</pool>
</connection>
<statement>
<sql><![CDATA[INSERT INTO `payload_info`(payload,subscriberno,rechargeamount,rechargechannel,rechargetype,currency,rechargetime)VALUES(?,?,?,?,?,?,?);]]></sql>
<parameter expression="get-property('payload')" type="VARCHAR"/>
<parameter expression="get-property('axis2','SubscriberNo')" type="VARCHAR"/>
<parameter expression="get-property('axis2','RechargeAmount')" type="INTEGER"/>
<parameter expression="get-property('axis2','RechargeChannelID')" type="INTEGER"/>
<parameter expression="get-property('axis2','RechargeType')" type="INTEGER"/>
<parameter expression="get-property('axis2','CurrencyID')" type="INTEGER"/>
<parameter expression="get-property('axis2','RechargeTime')" type="VARCHAR"/>
</statement>
</dbreport>
<script language="groovy"><![CDATA[def start_time=mc.getProperty('db_report_time');
def curr_time=System.currentTimeMillis();
def time= (curr_time- start_time);
mc.setProperty('db_report_time',time);
mc.setProperty('end_point_time',curr_time);]]></script>
<filter description="Validate rule" xpath="boolean(get-property('FLOW_CONTINUE'))">
<then>
<class name="com.custom.wso2.plugin.ot.REParamAliasMediator">
<property name="SYNO_NAME_TAGS" value="RechargeAmount,RechargeChannelID,SubscriberNo,RechargeType"/>
</class>
<iterate expression="//rule" id="RULE_LIST_ITERATE">
<target>
<sequence>
<propertyGroup>
<property expression="$body/rule/id" name="rule_id" scope="default" type="STRING"/>
<property expression="$body/rule/url" name="uri.var.url" scope="default" type="STRING"/>
</propertyGroup>
<payloadFactory media-type="json">
<format>{
"requestId":"189898909090",
"timeStamp":"2021/06/28 19:45:52",
"msisdn":"889399977",
"keyWord":"RECHARGE_NOTIFICATION",
"campaignId":"658",
"scheduleId":"$5",
"dataSet":{
"parameters":[
{
"name":"$6",
"value":"$1"
},
{
"name":"$8",
"value":"$2"
},
{
"name":"$7",
"value":"$3"
},
{
"name":"$9",
"value":"0"
},
{
"name":"RECHARGE_DATE",
"value":"$4"
},
{
"name":"RULE_ID",
"value":"$5"
}
]
}
}</format>
<args>
<arg evaluator="xml" expression="get-property('axis2','RechargeAmount')" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices"/>
<arg evaluator="xml" expression="get-property('axis2','SubscriberNo')" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices"/>
<arg evaluator="xml" expression="get-property('axis2','RechargeChannelID')" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices"/>
<arg evaluator="xml" expression="get-property('axis2','RechargeTime')" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices"/>
<arg evaluator="xml" expression="get-property('rule_id') "/>
<arg evaluator="xml" expression="get-property('axis2','RechargeAmount_alias') "/>
<arg evaluator="xml" expression="get-property('axis2','RechargeChannelID_alias') "/>
<arg evaluator="xml" expression="get-property('axis2','SubscriberNo_alias') "/>
<arg evaluator="xml" expression="get-property('axis2','RechargeType_alias') "/>
</args>
</payloadFactory>
<send>
<endpoint>
<http method="post" uri-template="{uri.var.url}">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</send>
</sequence>
</target>
</iterate>
</then>
<else>
<property name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:cbs="http://www.huawei.com/bme/cbsinterface/cbscommon" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices">
<soapenv:Body>
<wos:WorkOrderResultMsg>
<ResultHeader>
<cbs:Version>1</cbs:Version>
<cbs:ResultCode>0</cbs:ResultCode>
<cbs:ResultDesc>Operation success.</cbs:ResultDesc>
</ResultHeader>
</wos:WorkOrderResultMsg>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<respond/>
</else>
</filter>
</inSequence>
<outSequence>
<propertyGroup>
<property name="Aggregated_Responses" scope="default">
<ResponseDetail xmlns=""/>
</property>
<property name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
</propertyGroup>
<aggregate id="RULE_LIST_ITERATE">
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete aggregateElementType="root" enclosingElementProperty="Aggregated_Responses" expression="$body/*[1]">
<script language="groovy"><![CDATA[def start_time=mc.getProperty('end_point_time');
def curr_time=System.currentTimeMillis();
def time= (curr_time- start_time);
mc.setProperty('end_point_time',time);
mc.setProperty('resp_switch_time', curr_time);]]></script>
<filter xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xpath="count( $body//ResponseDetail/jsonObject[responseCode!='SC0000']) >=1">
<then>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:cbs="http://www.huawei.com/bme/cbsinterface/cbscommon" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices">
<soapenv:Body>
<wos:WorkOrderResultMsg>
<ResultHeader>
<cbs:Version>1</cbs:Version>
<cbs:ResultCode>1</cbs:ResultCode>
<cbs:ResultDesc>Operation failed.</cbs:ResultDesc>
</ResultHeader>
</wos:WorkOrderResultMsg>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
</then>
<else>
<class name="com.custom.wso2.plugin.ot.REParamAliasMediator">
<property name="ATTRIBUTE_NAME_TAGS" value="Subscriber,Recharge_Amount,Recharge_Channel"/>
</class>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:cbs="http://www.huawei.com/bme/cbsinterface/cbscommon" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices">
<soapenv:Body>
<wos:WorkOrderResultMsg>
<ResultHeader>
<cbs:Version>1</cbs:Version>
<cbs:ResultCode>0</cbs:ResultCode>
<cbs:ResultDesc>Operation success.</cbs:ResultDesc>
</ResultHeader>
<WorkOrderResult>
<wos:OrderParam>
<wos:Code>$1</wos:Code>
<wos:Value>$4</wos:Value>
</wos:OrderParam>
<wos:OrderParam>
<wos:Code>$2</wos:Code>
<wos:Value>$5</wos:Value>
</wos:OrderParam>
<wos:OrderParam>
<wos:Code>$3</wos:Code>
<wos:Value>$6</wos:Value>
</wos:OrderParam>
</WorkOrderResult>
</wos:WorkOrderResultMsg>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('axis2','Subscriber_alias') "/>
<arg evaluator="xml" expression="get-property('axis2','Recharge_Amount_alias') "/>
<arg evaluator="xml" expression="get-property('axis2','Recharge_Channel_alias') "/>
<arg evaluator="xml" expression="$body//ResponseDetail/jsonObject/dataSets/parameters[name='Subscriber']/value"/>
<arg evaluator="xml" expression="$body//ResponseDetail/jsonObject/dataSets/parameters[name='Recharge_Amount']/value"/>
<arg evaluator="xml" expression="$body//ResponseDetail/jsonObject/dataSets/parameters[name='Recharge_Channel']/value"/>
</args>
</payloadFactory>
</else>
</filter>
<script language="groovy"><![CDATA[def cuur_time=System.currentTimeMillis();
mc.setProperty('total_time',(cuur_time-mc.getProperty('start_time')));
mc.setProperty('resp_switch_time',(cuur_time-mc.getProperty('resp_switch_time')));]]></script>
<log level="custom" separator="|">
<property expression="get-property('total_time')" name="Total time taken"/>
<property expression="get-property('mvel_exe_time')" name="Total Mvel exe time taken"/>
<property expression="get-property('db_report_time')" name="Total DB report time taken"/>
<property expression="get-property('end_point_time')" name="Total End point call time taken"/>
<property expression="get-property('resp_switch_time')" name="Total Resp switch time taken"/>
</log>
<respond/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence>
<property name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:cbs="http://www.huawei.com/bme/cbsinterface/cbscommon" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wos="http://www.huawei.com/bme/cbsinterface/woservices">
<soapenv:Body>
<wos:WorkOrderResultMsg>
<ResultHeader>
<cbs:Version>1</cbs:Version>
<cbs:ResultCode>1</cbs:ResultCode>
<cbs:ResultDesc>Operation failed.</cbs:ResultDesc>
</ResultHeader>
</wos:WorkOrderResultMsg>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<respond/>
</faultSequence>
</resource>
</api>