WSO2ESB- The 'name' attribute is required for a Proxy service definition - wso2

I have a problem in deploying this sample: "Complex Event Processing and Business Rule Management With SOA" (Link: http://wso2.org/library/articles/2011/07/complex-event-processing-business-rule-management-soa)
I did all the details, but when I copy "cepSample.xml" file in the location "wso2esb-4.6.0/repository/deployment/server/synapse-configs/default/proxy-services" I get this error in the console and I won't be deployed:
/WSO2/wso2esb-4.6.0/repository/deployment/server/synapse-configs/default/proxy-services/cepSample.xml failed - Continue in fail-safe mode
org.apache.synapse.SynapseException: The 'name' attribute is required for a Proxy service definition

I try to create Proxy Service manually - and get this file (in ESB 4.8.1.)
May be it help you:
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="cepSample"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
<property name="txAmount" expression="//reqFinancTx/amount/text()"/>
<property name="financTx" expression="//reqFinancTx/financTx/text()"/>
<dblookup>
<connection>
<pool>
<password>esb</password>
<user>esb</user>
<url>jdbc:mysql://localhost:3306/brms_db</url>
<driver>com.mysql.jdbc.Driver</driver>
</pool>
</connection>
<statement>
<sql>
SELECT * FROM `BRMS_USER_INFO` where `user_id`=? </sql>
<parameter expression="//reqFinancTx/userID" type="VARCHAR"/>
<result name="balance" column="account_balance"/>
<result name="userId" column="user_id"/>
<result name="userName" column="name"/>
<result name="access" column="accessability"/>
</statement>
</dblookup>
<log>
<property name="userId" expression="get-property('userId')"/>
<property name="userName" expression="get-property('userName')"/>
<property name="access" expression="get-property('access')"/>
<property name="balance" expression="get-property('balance')"/>
<property name="txAmount" expression="get-property('txAmount')"/>
<property name="financTx" expression="get-property('financTx')"/>
</log>
<xslt key="sampleXSLT">
<property name="accountBalance" expression="get-property('balance')"/>
</xslt>
<log level="full"/>
<property name="STATE" value="PERSON_INFO_REQUEST"/>
<send>
<endpoint>
<address uri="http://localhost:9764/services/transactionValidatorService"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log>
<property name="xxxxxx" expression="get-property('STATE')"/>
</log>
<switch source="get-property('STATE')">
<case regex="PERSON_INFO_REQUEST">
<log level="full"/>
<property xmlns:brs="http://brs.carbon.wso2.org"
xmlns:ax26="http://transactionApprovalService.samples/xsd"
name="RESULT"
expression="//brs:processTransactionResponse/brs:TransactionResult/ax26:transactionCanProceed"/>
<log>
<property name="RESULT" expression="get-property('RESULT')"/>
</log>
<switch source="get-property('RESULT')">
<case regex="true">
<clone>
<target>
<sequence>
<xslt key="cepXSLT">
<property name="userId" expression="get-property('userId')"/>
<property name="financTx" expression="get-property('financTx')"/>
</xslt>
<log level="full"/>
<send>
<endpoint>
<address uri="http://localhost:9766/services/localBrokerService/AllTransactions"/>
</endpoint>
</send>
</sequence>
</target>
<target>
<sequence>
<dblookup>
<connection>
<pool>
<password>esb</password>
<user>esb</user>
<url>jdbc:mysql://localhost:3306/brms_db</url>
<driver>com.mysql.jdbc.Driver</driver>
</pool>
</connection>
<statement>
<sql> SELECT * FROM `BRMS_USER_INFO` where `user_id`=? </sql>
<parameter expression="//reqFinancTx/userID" type="VARCHAR"/>
<result name="balance" column="account_balance"/>
<result name="userId" column="user_id"/>
<result name="userName" column="name"/>
<result name="access" column="accessability"/>
</statement>
</dblookup>
<log>
<property name="userId" expression="get-property('userId')"/>
<property name="userName" expression="get-property('userName')"/>
<property name="access" expression="get-property('access')"/>
</log>
<switch source="get-property('access')">
<case regex="false">
<xslt key="accLockedXSLT"/>
<send/>
</case>
<case regex="true">
<xslt key="txProceedXSLT"/>
<send/>
</case>
</switch>
</sequence>
</target>
</clone>
</case>
<case regex="false">
<log level="full">
<property name="sequence"
value="outSequence - STATE 02 - response from CreditService"/>
</log>
<send/>
</case>
</switch>
<send>
<endpoint key="CreditEpr"/>
</send>
</case>
<case regex="CREDIT_REQUEST">
<log level="full">
<property name="sequence"
value="outSequence - STATE 02 - response from CreditService"/>
</log>
<send/>
</case>
</switch>
</outSequence>
</target>
</proxy>

Related

WSO2 ESB how to sending array list empty error

I Configurate url like:
https://htygnfgvsccl.com:6753/intellige/vehicle/getAlerts
this url some times getting data like
{
"alertsList": [
{
"vehicleNo": "45342",
"alertName": "Stop Skipped",
"depotName": "akividu"
},
{
"vehicleNo": "674894",
"alertName": "Stop Skipped",
"depotName": "guntur"
}
]
}
but some times getting data like
{
"alertsList": []
}
every time response code is 200 but how to send with error message in the case of alertsList empty
vehiclegetAlertsapi
<?xml version="1.0" encoding="UTF-8"?>
<api context="/intellige/vehicle/getAlerts" name="vehiclegetAlertsapi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<property description="http" name="HTTP_SC" scope="axis2" type="STRING" value="404"/>
<log level="full"/>
<send>
<endpoint key="vehiclegetAlertsendpoint"/>
</send>
</inSequence>
<outSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
</log>
<send/>
</case>
<default>
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
<clone continueParent="true">
<target>
<sequence>
<sequence key="vehiclegetAlertsmail"/>
</sequence>
</target>
</clone>
<send/>
</outSequence>
<faultSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
</log>
</case>
<default>
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
<clone continueParent="true">
<target>
<sequence>
<sequence key="vehiclegetAlertsmail"/>
</sequence>
</target>
</clone>
<send/>
</faultSequence>
</resource>
</api>
vehiclegetAlertsendpoint
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="vehiclegetAlertsendpoint" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="https://htygnfgvsccl.com:6753/intellige/vehicle/getAlerts "/>
</endpoint>
vehiclegetAlertsmail:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="vehiclegetAlertsmail" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="custom">
<property name="status" value=" vehileget alert Details Sending mail"/>
</log>
<property expression="get-property('axis2','HTTP_SC')" name="ErrorMessage" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property name="ContentType" scope="axis2" type="STRING" value="text/plain"/>
<property name="Subject" scope="transport" type="STRING" value="vehileget alert api not working"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<payloadFactory media-type="json">
<format>{"vehileget alert api not working":"$1"}</format>
<args>
<arg evaluator="xml" expression="$ctx:ErrorMessage" xmlns:ns="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
<call>
<endpoint key="vehiclegetAlertsmailid"/>
</call>
<drop/>
</sequence>
vehiclegetAlertsmailid:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="vehiclegetAlertsmailid" xmlns="http://ws.apache.org/ns/synapse">
<recipientlist>
<endpoint>
<address uri="mailto:aisha#gmail.com"/>
</endpoint>
</recipientlist>
</endpoint>
get 200 response code send the data automatically in case if any other reponse to send the mail my mail id ,prsent my problem is my rest url some time total data like alertsList with data comming some times only alertsList comming not comming data that case how to send mail

WSO2-how to pass two parameters at a time with WSO2 ESB configuration

I have created a API in API manager. I can invoke it with
http://localhost:6547/generatereports/1.0/Reports/dcuid/vcid
I am passing two parameters with "dcuid and vcid" at a time but not passing.
reportsapi:
<?xml version="1.0" encoding="UTF-8"?>
<api context="generatereports/1.0/Reports" name="reportsdataapi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" protocol="http" uri-template="/{dcuid}/{vcid}">
<inSequence>
<property description="http" name="HTTP_SC" scope="axis2" type="STRING" value="404"/>
<log level="full"/>
<send>
<endpoint key="reportsendpoint"/>
</send>
</inSequence>
<outSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
</log>
<send/>
</case>
<default>
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
<send/>
</outSequence>
<faultSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
</log>
</case>
<default>
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
<send/>
</faultSequence>
</resource>
</api>
wso2 configuration process with to send the response is other than 200 response code
reportsendpoint:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="reporsendpoint" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="http://localhost:6547/generatereports/1.0/Reports/{uri.var.dcuid}/{uri.var.vcid}"/>
</endpoint>
I assume you want to send a mail if the status code is other than 200. Then you can use mailto transport or mail connectors such as gmail connector outlook connector and add the configuration in the default section in the configured switch mediator.

WSO2 ESB How to see the outsequence log

I have wrote a proxy in WSO2 ESB. using the log files or the Monitor functionality I can see the logs for all the message mediation in the inSequence sequence mediator, but I can't find the logs for the outSequence. My Proxy example is:
<proxy name="FlightStatusService"
transports="https http"
startOnLoad="true"
trace="enable">
<description/>
<target>
<inSequence>
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
<property name="OUT_ONLY" value="true"/>
<property name="TIME_1"
expression="get-property('SYSTEM_TIME')"
scope="default"
type="LONG"/>
<property xmlns:air="http://airline.services.esb.wso2.packt.com"
name="airlineInTransport"
expression="fn:concat('Airline Company - ', //air:updateStatus/air:airline)"
scope="transport"/>
<property name="airlineInDefault"
expression="get-property('transport','airlineInTransport')"
scope="default"/>
<switch xmlns:air="http://airline.services.esb.wso2.packt.com"
source="//air:updateStatus/air:airline">
<case regex="EK">
<event topic="flightStatus/emirates"/>
</case>
<case regex="AA">
<event topic="flightStatus/aa"/>
</case>
<case regex="DL">
<event topic="flightStatus/delta"/>
</case>
<default>
<log level="custom">
<property name="noAirline" value="There is no Airline with these letters"/>
</log>
</default>
</switch>
</inSequence>
<outSequence>
<property name="TIME_2"
expression="get-property('SYSTEM_TIME')"
scope="default"
type="LONG"/>
<script language="js">var time1 = mc.getProperty("TIME_1");
var time2 = mc.getProperty("TIME_2");
var timeTaken = time2 - time1;
print("-------------- " + timeTaken + " ms -----------------");
mc.setProperty("RESPONSE_TIME", timeTaken);</script>
<log level="full" category="DEBUG">
<property name="airlineInTransport"
expression="get-property('default', 'airlineInDefault')"/>
<property name="Time Duration in ms: " expression="get-property('RESPONSE_TIME')"/>
</log>
<send/>
</outSequence>
</proxy>
Since your proxy is support for OUT_ONLY Activity, outSequence will not get hit.
EDITED -> Added a proxy for reference
Please refer the proxy
<proxy name="FlightStatusService"
transports="https http"
startOnLoad="true"
trace="enable">
<description/>
<target>
<inSequence>
<property name="TIME_1"
expression="get-property('SYSTEM_TIME')"
scope="default"
type="LONG"/>
<property xmlns:air="http://airline.services.esb.wso2.packt.com"
name="airlineInTransport"
expression="fn:concat('Airline Company - ', //air:updateStatus/air:airline)"
scope="transport"/>
<property name="airlineInDefault"
expression="get-property('transport','airlineInTransport')"
scope="default"/>
<switch xmlns:air="http://airline.services.esb.wso2.packt.com"
source="//air:updateStatus/air:airline">
<case regex="EK">
<event topic="flightStatus/emirates"/>
</case>
<case regex="AA">
<event topic="flightStatus/aa"/>
</case>
<case regex="DL">
<event topic="flightStatus/delta"/>
</case>
<default>
<log level="custom">
<property name="noAirline" value="There is no Airline with these letters"/>
</log>
</default>
</switch>
<loopback/>
</inSequence>
<outSequence>
<property name="TIME_2"
expression="get-property('SYSTEM_TIME')"
scope="default"
type="LONG"/>
<script language="js">var time1 = mc.getProperty("TIME_1");
var time2 = mc.getProperty("TIME_2");
var timeTaken = time2 - time1;
print("-------------- " + timeTaken + " ms -----------------");
mc.setProperty("RESPONSE_TIME", timeTaken);</script>
<log level="full" category="DEBUG">
<property name="airlineInTransport"
expression="get-property('default', 'airlineInDefault')"/>
<property name="Time Duration in ms: " expression="get-property('RESPONSE_TIME')"/>
</log>
<send/>
</outSequence>
</proxy>

wso2 esb - How to handle request in case of mediator returning false

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

How can I retrieve HTTP status returned by REST service in WSO2 ESB?

My Proxy Service deployed on ESB is calling another standalone REST service. This service returns HTTP status 200 along with some data in the response body. My question is how I can retrieve HTTP status from response. Here is my configuration:
<proxy name="CQProxy"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<switch source="get-property('Action')">
<case regex="getTaskTicket">
<sequence key="GetTaskTicket"/>
</case>
<default/>
</switch>
</inSequence>
<outSequence>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Status"
expression="get-property('HTTP_SC')"/>
</log>
<send/>
</outSequence>
<faultSequence/>
</target>
<publishWSDL key="gov:/services/cqproxy/CQProxy.wsdl">
<resource location="CQProxy.xsd" key="gov:/services/cqproxy/CQProxy.xsd"/>
</publishWSDL>
</proxy>
<sequence name="GetTaskTicket">
...
<property name="REST_URL_POSTFIX"
value="/16783484?oslc.select=dcterms:title,oslc_cm:status"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="http://.../simpleQuery"
format="rest"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
</sequence>
...
I tried the following code:
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('HTTP_SC')"/>
</log>
And this one too:
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('axis2', 'HTTP_SC')"/>
</log>
But all of them returned null.
After reading WSO2 documentation in more details, I found the right answer:
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="$axis2:HTTP_SC"/>
It is weird that the documented get-property('axis2', 'HTTP_SC') does not work.
Posting the solution that worked for me:
<property scope="default" type="STRING" name="HTTP_STATUS_CODE" expression="get-property('axis2', 'HTTP_SC')"/>
<log level="custom">
<property expression="get-property('HTTP_STATUS_CODE')" name="HTTP status code received: "/>
</log>