WSO2 calling a sequence from another one - wso2

I want to call a sequence in another one when the http return code is 401
I tried to handle that in this way but I could not call other one.
<filter regex=".*401" source="get-property('axis2', 'HTTP_SC')" xmlns:ns="http://org.apache.synapse/xsd">
<then>
<call-template target="conf:sequences/otherSequence.xml"></call-template>
</then>
</filter>
WSO2 version 6.4.0
Thanks for any idea!

<sequence key="conf:sequences/bsi.otherSequence.xml"></sequence>

Related

In wso2 esb how to get a single number(integer) value

In wso2 ESB after calling an endpoint I am getting the response as number(ex: 78) with header application/json, if without processing the response if i send in out sequence it works fine i'll get the same response. But if I include any mediators for processing in between it'll throw exceptions like Could not save JSON payload. Invalid input stream found. A single string or number is not valid in some cases So, it may throwing the exception but this bug is resolved in wso2 EI 6.2.
So now I am able to process the response but if I use script mediator to get that value it shows {}. If i use json-eval($.) then also i am not able to get the value, also with xpath i am not able to get.
So how to get that response(the value in number) for further processing in wso2 ei, by using script mediator or by using json path.
If you are certain that the response only contains a number with the content-type header with application/json. you can take the value to a property as below.
<property name="RESPONSE_NUMBER" expression="//jsonValue" scope="default" type="INTEGER"/>
When you need this value somewhere else in the mediation flow you can take the value from the property(in this case RESPONSE_NUMBER) as below.
$ctx:RESPONSE_NUMBER
Here is a sample API which demonstrates how you can take the response value and use it in the mediation flow.
<api xmlns="http://ws.apache.org/ns/synapse" name="SampleAPI" context="/getNumber">
<resource methods="GET">
<inSequence>
<send>
<endpoint>
<http method="GET" uri-template="http://www.mocky.io/v2/5b02cc2c3000006600cee384"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="RESPONSE_NUMBER" expression="//jsonValue" scope="default" type="INTEGER"/>
<payloadFactory media-type="json">
<format>{"Id": $1}</format>
<args>
<arg evaluator="xml" expression="$ctx:RESPONSE_NUMBER"/>
</args>
</payloadFactory>
<send/>
</outSequence>
</resource>
</api>
You can call the API with below curl command:
curl -v http://localhost:8280/getNumber

save a dynamic value in wso2 esb for next use

i need to save result of web service login method as a property in wso2 esb. and use it whenever i want. token will be expired in 20 min so i want to save token in wso2 esb and when it expire regenerate it. how can i save a property dynamic in wso2 esb and retrieve it. my sequence to generate tokekn is :
<sequence name="x" xmlns="http://ws.apache.org/ns/synapse">
<payloadFactory media-type="xml">
<format>
<p:login xmlns:p="http://corebankingservice.endpoint.webservicegateway.core.channelmanager.caspian.com/">
<chUserInfoRequestBean xmlns="">
<password>****</password>
<username>user</username>
</chUserInfoRequestBean>
<channelServiceType xmlns="">***</channelServiceType>
</p:login>
</format>
</payloadFactory>
<send>
<endpoint>
<address uri="http://x.x.x.x:8280/services/..."/>
</endpoint>
</send>
</property name="SessionId" value = ...>
</sequence>
result of this sequence is SessionId so i need to save SessionId in memory or db or .... and use it for another method until it will be expired. how can i save such a this property in registery or cashe or database and use it later.
The only "official" way I know (which I used), is to use the dblookup mediator (retrieve the value later) and dbreport meditaor (to store the value) in a database.
Write value to a db:
<dbreport>
<connection>
<pool>
<dsName>datasource_name</dsName>
</pool>
</connection>
<statement>
<sql>
insert into table (attributName1, attributName2) values ('value1','value2')</sql>
</statement>
</dbreport>
The values can be passed from a property like in this example.
<sql>
insert into dbo.sais_config_db (serviceName, configKey, configValue) values ('staticVal1','staticVal2',?)</sql>
<parameter expression="get-property('myPropertyName')" type="CHAR"/>
Read value:
<dblookup>
<connection>
<pool>
<dsName>sais_config_db</dsName>
</pool>
</connection>
<statement>
<sql>
SELECT value1 FROM tableName where ....</sql>
<result name="resultFromDb" column="value1"/>
</statement>
</dblookup>
Hope that helps. There is another option, but I don't know if that works (haven't tried it).
Link
With WSO2 Enterprise Integrator 6.x.x and up, it's possible to set a property with scope "registry" that will persist the value between calls and being globally visible.
For example to persist the access token received in the JSON response:
<property description="propAccessToken" expression="json-eval($.access_token)" name="access_token" scope="registry" type="STRING"/>
Then to get the property use the following expression:
get-property('registry', 'access_token')

Push Smook's response to Sequence

I've used Smook Mediator in WSO2ESB to transform content in 'plain/text' to 'XML'. I don't know the output is pushed to sequence by default or not. So I tried to send output of Smook to a WS by Send Mediator like this, but nothing's happended. This is my PS's configuration:
<inSequence>
<log/>
<smooks config-key="conf:/smooksccconfig.xml">
<input type="text"/>
<output type="xml"/>
</smooks>
<log level="full"/>
<send receive="Testing">
<endpoint key="GeoEP"/>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
Is there any needed mediator to push result of transformation to the Sequence?
Can u give me some advises?
Thank,
Your approach seems fine. You don't need any mediator to push the results of Smooks transformation to a sequence. Anyway to figure out the error you can enable wirelogs in ESB. Please do the following steps.
Shotdown the ESB instance
Locate log4j.properties file under $ESB_HOME/repository/conf directory
Uncomment the line log4j.logger.org.apache.synapse.transport.http.wire=DEBUG
Then restart the ESB instance
symbol << represents contents going out of the ESB where as >> represents things comes into the ESB
Also please check whether your logfull mediator logs the correct output after the transformation. If that is the case, then you have to look into your endpoint config.
If you have any error messages in ESB console, then please attach them here so that we can have some more insight into your issue using them.

Http PassThrough and Http NIO in WSO2 ESB 4.7

I am migrating a service that was built to run on WSO2 ESB 4.0 to WSO2 ESB 4.7 and have run into a problem. The service I am migrating is a custom proxy with a SOAP 1.2 binding interface. This proxy makes outbound calls to a SOAP 1.1 based service.
The ESB 4.0 server is using the Http NIO transport and it appears that transport would use a message formatter (I'm guessing) to manage the SOAP message conversion in the ESB between SOAP 1.1 and 1.2 when sending a response message back to the client.
The ESB 4.7 is using the Http PassThrough transport, which does not have the SOAP message conversion capabilities, so SOAP envelope namespaces and HTTP header information has to be changed manually in a sequence.
Is it possible to configure both Http PassThrough and Http NIO to be active on the same ESB and configure individual services to use one or the other? I've tried, and have been unsuccessful, and my research so far seems to indicate one or the other.
EDIT1 - Response to RaviU:
Thanks RaviU. The ESB 4.7.0 will support automatic conversion of SOAP 1.1 to 1.2 if it is configured to use the HTTP NIO transport. In other words, it behaves like the ESB 4.0 server. The automatic conversion of SOAP 1.1 to 1.2 does not appear to occur when the ESB 4.7.0 is configured to use HttpPassThrough transport. This makes sense because that transport does not care about content type. The problem I have when using HttpPassThrough is that I have to manually change the SOAP envelope to 1.2 and set the appropriate http headers before sending back to the client. This is because they are changed when the service calls the SOAP 1.1 service. If I use the HTTP NIO transport, the manual steps are taken care of automatically by the ESB. I'm assuming this is done by a message formatter before the message is returned to the client.
Apologies with the late response. You can fix your conversion issue doing something like:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<filter xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
source="namespace-uri(/*)"
regex="http://www.w3.org/2003/05/soap-envelope">
<then>
<property name="incomingSOAPVersion" value="soap12"/>
</then>
<else>
<property name="incomingSOAPVersion" value="soap11"/>
</else>
</filter>
<log level="custom">
<property name="SOAP_VERSION_LOG" expression="$ctx:incomingSOAPVersion"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:8280/services/echo.echoHttpSoap11Endpoint"
format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<filter source="$ctx:incomingSOAPVersion" regex="soap11">
<then>
<send>
<endpoint>
<default format="soap11"/>
</endpoint>
</send>
</then>
<else>
<send>
<endpoint>
<default format="soap12"/>
</endpoint>
</send>
</else>
</filter>
</outSequence>
</target>
<publishWSDL uri="http://localhost:8280/services/echo?wsdl"/>
<description/>
</proxy>
You can also set the messageType instead of using default endpoint. This is also a possible solution:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="soapVersion">
<filter xmlns:ns="http://org.apache.synapse/xsd" source="$axis2:messageType" regex="application\/soap\+xml">
<then>
<property name="incomingSOAPVersion" value="soap12"/>
</then>
<else>
<property name="incomingSOAPVersion" value="soap11"/>
</else>
</filter>
</sequence>
Either should work, but the second solution should be slightly better performing since it does not evaluate xPath.

WSO2 ESB: How to make Sequence mediator wait for response before proceeding

I have the following logic in my Proxy Service:
<proxy>
<inSequence>
<switch source="get-property('Action')">
<case regex="getTaskTicket">
<sequence key="CQProxy_GetTaskTicket"/>
</case>
<case regex="updateTaskTicket">
<sequence key="CQProxy_UpdateTaskTicket"/>
</case>
...
<default/>
</switch>
</inSequence>
<outSequence>
<send/>
</outSequence>
</proxy>
Now my CQProxy_UpdateTaskTicket calls another sequence:
<sequence name="CQProxy_UpdateTaskTicket">
... some logic goes here ...
<sequence key="CQProxy_GetTicketDetails"/>
... here I need to wait for response from CQProxy_GetTicketDetails
before further processing ...
</sequence>
CQProxy_GetTicketDetails is used by various other sequences and in its turn defines OUT sequence to process its response:
<sequence name="CQProxy_GetTicketDetails">
... some logic ...
<send receive="CQProxy_GetTicketDetails2">
<endpoint key="CQ"/>
</send>
</sequence>
The problem is that after CQProxy_UpdateTaskTicket sequence calls CQProxy_GetTicketDetails sub-sequence, it does not wait for response from that sub-seq but instead continues message processing.
How is it possible to make CQProxy_UpdateTaskTicket wait for response before proceeding?
I was able to get around this issue by passing the response sequence name to the sub-sequence.
You can use the Callout mediator for the blocking kind of operations within the WSO2 ESB. Instead of using the Send mediator (which is non-blocking) you can easily use callout mediator as mentioned below.
http://docs.wso2.org/wiki/display/ESB460/Callout+Mediator