I have an API that will return XML data, I want to use datamapper to map some data and then return it to the client, but the API after using DataMapper keeps returning null.
see below
<?xml version="1.0" encoding="UTF-8"?>
<api context="/AllAdByCRN" name="AllAdByCRN" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope format="soap11" 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/>
<soapenv:Body>
<GetCustomerWaselNotCancelled xmlns="http://tempuri.org/">
<userName></userName>
<password></password>
<id></id>
<idType></idType>
<sequenceNumber></sequenceNumber>
<laborOffice></laborOffice>
</GetCustomerWaselNotCancelled>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<header name="Action" scope="default" value=""/>
<call>
<endpoint>
<http format="soap11" method="post" uri-template="">
<timeout>
<duration>17000000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<property expression="json-eval($.*)" name="responseData" scope="default" type="STRING"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<datamapper config="gov:datamapper/NewConfig.dmc" inputSchema="gov:datamapper/NewConfig_inputSchema.json" inputType="JSON" outputSchema="gov:datamapper/NewConfig_outputSchema.json" outputType="XML" xsltStyleSheet="gov:datamapper/NewConfig_xsltStyleSheet.xml"/>
<log level="custom">
<property expression="json-eval($.*)" name="responseData"/>
</log>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
I want to map data only not converting from XML to JSON.
You have to choose XML as input and output :
<datamapper config="gov:datamapper/NewConfig.dmc" inputSchema="gov:datamapper/NewConfig_inputSchema.json" inputType="XML" outputSchema="gov:datamapper/NewConfig_outputSchema.json" outputType="XML" xsltStyleSheet="gov:datamapper/NewConfig_xsltStyleSheet.xml"/>
Related
I have a resource in my wso2 esb
<resource methods="POST" protocol="http" uri-template="/ft">
<inSequence>
<sequence key="T24InSequence"/>
</inSequence>
<outSequence>
<sequence key="T24OutSequence"/>
</outSequence>
</resorce>
I have a wsdl endpoint that is being called in the T24 Sequence
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="operationsDbWsdlEndpoint" xmlns="http://ws.apache.org/ns/synapse">
<wsdl port="HTTPEndpoint" service="mfb_transact_service" uri="http://localhost:8290/services/mfb_transact_service?wsdl">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</wsdl>
</endpoint>
and I call the endpoint in the following manner
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="T24InsertCashinDBSquence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="DBACTION" value="=================== INSERT INTO CASHIN DB =================="/>
</log>
<property expression="get-property('SYSTEM_DATE','yyyy-MM-dd HH:mm:ss')" name="requestTime" scope="default" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<p:insert_sop_t24FT_operation xmlns:p="t24FT">
<!--Exactly 1 occurrence -->
<xs:sopRequestId xmlns:xs="t24FT">$1</xs:sopRequestId>
<!--Exactly 1 occurrence -->
<xs:destinationInstitutionCode xmlns:xs="t24FT">$2</xs:destinationInstitutionCode>
<!--Exactly 1 occurrence -->
<xs:destinationAccountNumber xmlns:xs="t24FT">$3
</xs:destinationAccountNumber>
<!--Exactly 1 occurrence -->
<xs:sourceInstitutionCode xmlns:xs="t24FT">$4
</xs:sourceInstitutionCode>
...
</p:insert_sop_t24FT_operation>
</format>
<args>
<arg evaluator="json" expression="$.requestID"/>
<arg evaluator="json" expression="$.destinationInstitutionCode"/>
<arg evaluator="json" expression="$.destinationAccountNumber"/>
<arg evaluator="json" expression="$.sourceInstitutionCode"/>
...
</args>
</payloadFactory>
<property name="FORCE_ERROR_ON_SOAP_FAULT" scope="default" type="STRING" value="true"/>
<callout endpointKey="operationsDbWsdlEndpoint">
<source type="envelope"/>
<target key="response"/>
</callout>
</sequence>
I can not figure out why when I call the endpoint I get the following error
Error processing POST request for : /services/mfb_transact_service.HTTPEndpoint/ft org.apache.axis2.AxisFault: The endpoint reference (EPR) for the Operation not found is /services/mfb_transact_service.HTTPEndpoint/ft and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator.
So it seems like wso2 is appending the /ft to the wsdl url
Can you try adding the following before the callout mediator?
<property name="REST_URL_POSTFIX" action="remove" scope="axis2"/>
I´m noob to that application, but I´ve been trying some tutorials and all of them had no response, nothing happens. I just send a request and nothing. I deployed and all looks as the tutorials explained, but when I try to execute, nothing appears in my browse or curl.
Here is a example:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/healthcare" name="HealthcareAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/querydoctor/{category}">
<inSequence>
<log description="RequestLog"/>
<send/>
</inSequence>
<outSequence>
<log description="ResponseLog"/>
<send/>
</outSequence>
<faultSequence>
<log description="ErrorLog"/>
</faultSequence>
</resource>
<resource methods="POST" uri-template=" /categories/{category}/reserve">
<inSequence>
<property description="GetHospital" expression="json-eval($.hospital)" name="Hospital" scope="default" type="STRING"/>
<switch source="get-property('Hospital')">
<case regex="grand oak community hospital">
<log description="GrandOakLog" level="custom">
<property expression="fn:concat('Routing to ', get-property('Hospital'))" name="message"/>
</log>
<send/>
</case>
<case regex="clemency medical center">
<log description="ClemencyLog" level="custom">
<property expression="fn:concat('Routing to ', get-property('Hospital'))" name="message"/>
</log>
<send/>
</case>
<case regex="pine valley community hospital">
<log description="PineValleyLog" level="custom">
<property expression="fn:concat('Routing to ', get-property('Hospital'))" name="message"/>
</log>
<send/>
</case>
<default>
<log description="ErrorLog" level="custom">
<property expression="fn:concat('Invalid hospital - ', get-property('Hospital'))" name="message"/>
</log>
<respond description="RespondError"/>
</default>
</switch>
</inSequence>
<outSequence/>
<faultSequence>
<log description="ErrorLog"/>
</faultSequence>
</resource>
</api>
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="ClemencyEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="post" uri-template="http://wso2training-restsamples.wso2apps.com/clemency/categories/{uri.var.category}/reserve"/>
</endpoint>
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="GrandOakEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="post" uri-template="http://wso2training-restsamples.wso2apps.com/grandoaks/categories/{uri.var.category}/reserve"/>
</endpoint>
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="PineValleyEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="post" uri-template="http://wso2training-restsamples.wso2apps.com/pinevalley/categories/{uri.var.category}/reserve"/>
</endpoint>
And here is the request to make that application work:
{
"patient": {
"name": "John Doe",
"dob": "1940-03-19",
"ssn": "234-23-525",
"address": "California",
"phone": "8770586755",
"email": "johndoe#gmail.com"
},
"doctor": "thomas collins",
"hospital": "grand oak community hospital"
}
You should have the endpoint call in the send mediator
<case regex="grand oak community hospital">
<log description="GrandOakLog" level="custom">
<property expression="fn:concat('Routing to ', get-property('Hospital'))" name="message"/>
</log>
<send>
<endpoint name="GrandOakEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="post" uri-template="http://wso2training-restsamples.wso2apps.com/grandoaks/categories/{uri.var.category}/reserve"/>
</endpoint>
</send>
</case>
And also the outSequence should have a <send/> mediator
I have this proxy service in ESB 4.8.1, when I test it with SoapUI 5.2.1. I got this problem:
Does not write the full log in the server console when a timeout rise, but when I change it to custom it works.
Does not return any response to SoapUI (payloadFactory does not work)
When I deploy it in ESB 4.9.0 it works perfectly. Its a bug from the older version? How can I fix it?
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="StockQuoteProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<send>
<endpoint>
<address uri="http://localhost:8089/mockStockQuoteProxySoap11Binding"
format="soap11">
<timeout>
<duration>1000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>101500,101501,101506,101507,101508</errorCodes>
<initialDuration>2000</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>3000</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>101504,101505</errorCodes>
<retriesBeforeSuspension>3</retriesBeforeSuspension>
<retryDelay>1</retryDelay>
</markForSuspension>
</address>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence>
<log level="full">
<property name="FALLO" value="DETALLES DEL ERROR!!"/>
<property name="message" expression="get-property('ERROR_MESSAGE')"/>
<property name="code" expression="get-property('ERROR_CODE')"/>
<property name="detail" expression="get-property('ERROR_DETAIL')"/>
<property name="exception" expression="get-property('ERROR_EXCEPTION')"/>
</log>
<payloadFactory>
<format>
<ns:MyResponse xmlns:ns="http://services.samples">
<ns:Error>Execution Error</ns:Error>
</ns:MyResponse>
</format>
</payloadFactory>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<send/>
</faultSequence>
</target>
<description/>
</proxy>
Thanks in advance.
Try with this fault sequence:
Steps:
Create my response message.
Use the enrich mediator to store the body in property OK.
Create a fault message.
Override the body with the property OK using the enrich mediator.
<payloadFactory>
<format>
<ns:getQuoteResponse xmlns:ns="http://services.samples">
<ns:return xmlns:ax21="http://services.samples/xsd">
<status>ERROR</status>
</ns:return>
</ns:getQuoteResponse>
</format>
</payloadFactory>
<log level="full">
<property name="MESSAGE" value="Mensaje despues del payloadFactory"></property>
</log>
<enrich>
<source clone="true" type="body"></source>
<target action="replace" type="property" property="OK"></target>
</enrich>
<makefault version="soap11">
<code xmlns:soap11Env="schemas.xmlsoap.org/soap/envelope/" value="soap11Env:EdnpointTimeout"/>
<reason value="timeout fault"/>
<role/>
</makefault>
<enrich>
<source type="property" clone="true" property="OK"/>
<target type="body"/>
</enrich>
<log level="full">
<property name="MESSAGE" value="Mensaje despues del enrich"></property>
</log>
<send/>
When I run this proxy this is what I get as the response and the console log. Were you expecting something like this?
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<ns:MyResponse xmlns:ns="http://services.samples">
<ns:Error>Execution Error</ns:Error>
</ns:MyResponse>
</soap:Body>
</soap:Envelope>
INFO - LogMediator To: /services/StockQuoteProxy.StockQuoteProxyHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:44da8426-00fc-442a-b4e9-1a9a1dd948f2, Direction: request, FALLO = DETALLES DEL ERROR!!, message = Error connecting to the back end, code = 101503, detail = Error connecting to the back end, exception = null, Envelope: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body></soap:Body></soap:Envelope>
I want to get text from following Envelope so that I can use it as REST_URL_POSTFIX.
I am sending a plain text message to a JMS queue and following WSO2-ESB proxy service is used as a receiver/listener of JMS queue. I have tried following expressions but they does not work :
$body
$body/text
$body/text()
The SOAP 1.1 or 1.2 body element. For example, the expression
$body/getQuote refers to the first getQuote element in a SOAP body,
regardless of whether the message is SOAP-11 or SOAP-12.
and
//Envelope//Body//text
//Envelope//Body//text()
INFO - (Send
LogMediator To: , MessageID: ID:sunnydyal-K55VM-44230-1439804805911-3:2:1:1:9,
Direction: request, ##### Message = ,
Envelope:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<axis2ns8:text xmlns:axis2ns8="http://ws.apache.org/commons/ns/payload">Test</axis2ns8:text>
</soapenv:Body>
</soapenv:Envelope>
#Proxy Service:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="JmsToRestProxy"
transports="jms"
statistics="enable"
trace="enable"
startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<property name="SOAPAction" scope="default" action="remove"/>
<header name="Action" scope="default" action="remove"/>
<property name="REST_URL_POSTFIX"
expression="//Envelope//Body//text"
scope="axis2"
type="STRING"/>
<switch source="$axis2:HTTP_METHOD">
<case regex="GET">
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
</case>
<case regex="POST">
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
</case>
<default/>
</switch>
<log level="full">
<property name="##### Message" expression="$body/text"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:8080/Rest/rest" format="rest"/>
</endpoint>
</send>
</inSequence>
</target>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>text/plain</default>
</rules>
</parameter>
<description/>
</proxy>
text node belong to a specific namespace "http://ws.apache.org/commons/ns/payload" :
<log level="full">
<property xmlns:syn="http://ws.apache.org/commons/ns/payload" name="##### Message" expression="$body/syn:text/text()"/>
</log>
You can get the body using the $body variable[1]. /text() is trying to access the text element of the body which doesn't exist.
<log level="custom">
<property name="Body" expression="$body" />
</log>
[1] - https://docs.wso2.com/display/ESB481/Synapse+XPath+Variables#SynapseXPathVariables-$body
I have custom mediator where we are validating internal authentication system. If authentication fails, mediator return false. Client receiving response as HTTP status code 202. This I want to override with some JSON response like { "authError" : "Authetication failed - TOKEN_INVALID" }. Please let me know how to handle such scenarios.
ESB Version - 4.81.
Here is my proxy configuration -
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="UGCGetJSONFileList"
transports="https,http"
statistics="enable"
trace="disable"
startOnLoad="true">
<target outSequence="WEB_OUT_Sequence">
<inSequence>
<log level="full" separator=","/>
<class name="com.hc.synapse.mediator.HCAuthenticationMediator"/>
<property name="RESPONSE" value="true" scope="axis2"/>
<property name="uri.var.querystrings"
expression="substring-after(get-property('To'), '?')"
scope="axis2"
type="STRING"/>
<log level="full" separator=","/>
<switch source="$axis2:HTTP_METHOD">
<case regex="GET">
<property name="uri.var.querystrings"
expression="substring-after(get-property('To'), '?')"
scope="default"
type="STRING"/>
<log level="full" separator=","/>
<send>
<endpoint>
<http method="get"
uri-template="http://dalx-entsvc-d1:9660/ugc/getJSONFileList?{uri.var.querystrings}"/>
</endpoint>
</send>
</case>
<case regex="POST">
<log level="full" separator=","/>
<send>
<endpoint>
<address uri="http://dalx-entsvc-d1:9660/ugc/getJSONFileList?{uri.var.querystrings};content"
trace="enable"
statistics="enable">
<timeout>
<duration>30000</duration>
<responseAction>discard</responseAction>
</timeout>
<suspendOnFailure>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
</address>
</endpoint>
</send>
</case>
<default/>
</switch>
</inSequence>
<faultSequence>
<log level="full" separator=",">
<property name="trace" expression="get-property('ERROR_MESSAGE')"/>
</log>
<payloadFactory media-type="json">
<format>{ "authError" : "Authetication failed - TOKEN_INVALID" }</format>
<args/>
</payloadFactory>
<property name="RESPONSE" value="true"/>
<header name="To" action="remove"/>
<send/>
</faultSequence>
</target>
<description/>
</proxy>
In your class mediator, you can throw a SynapseException
In this case, inSequence mediation stop and faultSequence will be executed
In the faultSequence, your can use mediator payloadFactory with media-type="json" to build your json message and send it to the client with <send/>