I have an api that allows get all tables that are between two specific dates ,at first i tried to put query parameters comme ci-dessous
I used enrich mediator to display table to the do substring
this my code
<inSequence>
<script language="js"><![CDATA[var table = mc.getProperty('query.param.table');
table =table.toString();
mc.setProperty('table',table);]]></script>
<property expression="get-property('table')" name="uri.var.table" scope="default" type="STRING"/>
<call>
<endpoint>
<http method="get" uri-template="http://ITMTNF3RRJSJ:8290/services/studenttest/readtable?table={uri.var.table}">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<enrich>
<source clone="true" type="inline">
{"nomtable":""
}
</source>
<target action="child" xpath="json-eval($.tables)"/>
</enrich>
<enrich>
<source clone="true" property="uri.var.table" type="property"/>
<target xpath="json-eval($.tables.nomtable)"/>
</enrich>
<iterate expression="//tables">
<target>
<sequence>
<property expression="json-eval($.tables.nomtable)" name="nomtable" scope="default" type="STRING"/>
<log level="custom">
<property expression="get-property('nomtable')" name="m"/>
</log>
<script language="js"><![CDATA[var str = mc.getProperty('nomtable');
var annee= str.substr(1, 4);
annee==annee.toString();
var mois=str.substr(5, 2);
var jour=str.substr(7, 2);
mc.setProperty('annee',annee);
mc.setProperty('mois',mois);
mc.setProperty('jour',jour);]]></script>
<log level="custom">
<property expression="get-property('annee')" name="annee" />
</log>
<log level="custom">
<property expression="get-property('mois')" name="mois" />
</log>
<log level="custom">
<property expression="get-property('jour')" name="jour" />
</log>
</sequence>
</target>
</iterate>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property name="ContentType" scope="axis2" type="STRING" value="application/json"/>
<respond/>
but i have the result
INFO {LogMediator} - m = `20221018`,`20221211` INFO {LogMediator} - {api:student} annee = 2022 mois = 10 jour = 18
the problem i have two name of table as a date 20221018and 20221211i want extract annee mois and jour of the two table but i can't browse both tables .
Related
I'm trying to send a put request to my backend api, but I need a token and its working on the get request so the problem isn't with the token but when I make the request the response is 202 accepted and don't update the database.
Here is the code
<resource methods="PUT" uri-template="/Nurse">
<inSequence>
<enrich>
<source clone="true" type="body"/>
<target property="payload" type="property"/>
</enrich>
<property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
<call blocking="true" description="">
<endpoint>
<address format="get" uri="http://192.168.20.1:8280/loginAPI/login"/>
</endpoint>
</call>
<property expression="json-eval($.accessToken)" name="token" scope="default" type="STRING"/>
<property expression="fn:concat('Bearer ',$ctx:token)" name="Authorization" scope="transport" type="STRING"/>
<enrich description="Restore original payload">
<source property="payload" type="property"/>
<target type="body"/>
</enrich>
<send>
<endpoint key="PutNurseEp"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
Can anyone help what is the problem here?
Solved the question, the error was on the postman request, I was adding a space on the beggining of the url
How to create Proxy Service which is capable to download XML file from specific address and save it to the Folder?
I tried below answer : But it is not working VFS throws error :
<call>
<endpoint>
<address format="soap11"
uri="https://scsanctions.un.org/resources/xml/en/consolidated.xml"/>
</endpoint>
</call>
<property expression="fn:concat('consolidated-', get-property('SYSTEM_DATE', 'yyyy-MM-dd'),'.xml')"
name="transport.vfs.ReplyFileName"
scope="transport"/>
<log level="custom">
<property name="Step 1" value="---------Writing response to file ---------"/>
</log>
<property name="FORCE_SC_ACCEPTED"
scope="axis2"
type="STRING"
value="true"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<call>
<endpoint>
<address uri="vfs:file://C:/output"/>
</endpoint>
</call>
<log level="custom">
<property name="Step 2" value="---------Service is called ---------"/>
</log>
<property expression="fn:concat('treasury-',get-property('SYSTEM_DATE', 'yyyy-MM-dd'), '.xml' )"
name="transport.vfs.ReplyFileName"
scope="transport"/>
<log level="custom">
<property name="Step 2"
value="---------sending request to treasure site ---------"/>
</log>
<call>
<endpoint>
<address format="soap11" uri="https://www.treasury.gov/ofac/downloads/sdn.xml"/>
</endpoint>
</call>
<log level="custom">
<property name="Step 2" value="---------Writing response to file ---------"/>
</log>
<property name="FORCE_SC_ACCEPTED"
scope="axis2"
type="STRING"
value="true"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<call>
<endpoint>
<address uri="vfs:file://C:/output"/>
</endpoint>
</call>
enter code here
WSO2 ESB: How to download a file over HTTP?
Im trying to calling multiple endpoint to receive response which is supposed to be saved in this folder file://C:/output
Regards
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
I'm trying to edit an api resource in WSO2 ESB to put query params dinamically in the end of endpoint URL.
At this moment, the resource is like this:
<resource methods="GET" uri-template="/searchEngine/sortAndFilterBeneficiaries*">
<inSequence>
<log level="custom">
<property name="Access token value" expression="$trp:Authorization"/>
</log>
<oauthService remoteServiceUrl="https://server:port/services/" username="admin#wso2.com" password="admin"/>
<header name="Authorization" scope="transport" action="remove"/>
<send>
<endpoint>
<http method="get"
uri-template="http://server:port/project-web-services/services/project-rs/searchEngine/sortAndFilterBeneficiaries?criterioOrdenacion={query.param.criterioOrdenacion}®istrosPorPagina={query.param.registrosPorPagina}&numPagina={query.param.numPagina}&userId={query.param.userId}&serviciosSeleccionados={query.param.serviciosSeleccionados}&fechaRequerida={query.param.fechaRequerida}&limiteInfDias={query.param.limiteInfDias}&limiteSupDias={query.param.limiteSupDias}&ubicacion={query.param.ubicacion}&limiteDistancia={query.param.limiteDistancia}&valoraciones={query.param.valoraciones}&competencias={query.param.competencias}"/>
</endpoint>
</send>
</inSequence>
But, I'm doing this:
<resource methods="GET" url-mapping="/searchEngine/sortAndFilterBeneficiaries*">
<inSequence>
<filter source="$ctx:query.param.criterioOrdenacion" regex="PRODUCTION">
<then>
<property name="REST_URL_POSTFIX" expression="fn:concat(get-property('axis2','REST_URL_POSTFIX'), '&criterioOrdenacion={query.param.type}')" scope="axis2" type="STRING"/>
</then>
</filter>
<log level="custom">
<property name="Access token value" expression="$trp:Authorization"/>
</log>
<oauthService remoteServiceUrl="https://server:port/services/" username="admin#wso2.com" password="admin"/>
<header name="Authorization" scope="transport" action="remove"/>
<send>
<endpoint>
<http method="get"
uri-template="http://server:port/project-web-services/services/project-rs"/>
</endpoint>
</send>
</inSequence>
Is this correct?
This is correct. When you want to change base path only one endpoint will be affected, but in first case you must update all dynamic endpoint.
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>