Querying the cached response in WSO2 DSS/ESB - caching

I have a Oracle database view containing details of around 8000 employees. I need to populate employee search suggestions from that view. I'm planning to use WSO2 DSS/ DSS+ESB to create a data service for that. Rather querying the view for each and every service call, i'm thinking of caching the whole view in DSS/ESB and query the cache for all the filter queries("like", "where" queries) until cache expires.
Is there any possibilities around ESB/DSS related to the above scenario?
Thanks in advance.

You can use cache mediator with WSO2 ESB :
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Test" transports="https http" startOnLoad="true" trace="disable">
<description/>
<target>
<inSequence>
<cache id="someCache" scope="per-host" collector="false" hashGenerator="org.wso2.caching.digest.DOMHASHGenerator" timeout="10">
<onCacheHit>
<log level="custom">
<property name="debug" value="incache"/>
</log>
<header name='To' action="remove"/>
<send/> <!-- send back previous reponse, outSequence will not be executed -->
</onCacheHit>
<implementation type="memory" maxSize="1000"/>
</cache>
<send> <!-- Current request (hash) has not been found in the cache -->
<endpoint>
<address uri="http://myhost:8080/myapp/MyService"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<cache id="someCache" scope="per-host" collector="true"/> <!-- Add this response to the cache -->
<log level="custom">
<property name="debug" value="outseq"/>
</log>
<send/>
</outSequence>
</target>
</proxy>
Inside the inSequence, if current request exists in the cache, 'onCacheHit' mediation will be executed with previous response. Otherwise, the 'send' to the endpoint will be executed
Inside outSequence, you add the response to the cache

Related

WSo2 Esb filtering messages to an output file

I am working with a filter mediator attempting to send messages to an output xml file. I have my sequence using a filter mediator based on a attribute value, if it is true I want to write the message to a new xml file in a certain directory. If it is false I will drop the record.
Here is my sequence:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="RenaissanceIqtFilterSequence">
<log level="custom">
<property name="sequence" value="FilterSequence"></property>
</log>
<filter xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:ns="http://org.apache.synapse/xsd" xmlns:z="RowsetSchema" xpath="//z:row/#name='RP'">
<then>
<log level="custom">
<property name="sequence" value="Condition Write"></property>
</log>
<call-template target="FileWriteTemplate">
<with-param name="targetFileName" value="NEW_MESSAGE_FILE"></with-param>
<with-param name="addressUri" value="vfs:file:///var/process/rrout"></with-param>
</call-template>
</then>
<else>
<log level="custom">
<property name="sequence" value="Condition Drop"></property>
</log>
<drop></drop>
</else>
</filter>
</sequence>
*I am using a template as you can see to write out to my new output file setting parameters for the file name and uri.
The result is the whole file is being written out to the directory not just the messages I want. I have been running google searches trying to see where I am going wrong. I assume at this point I may be using the Filter mediator incorrectly? Maybe there is a better way or mediator to use to accomplish this task? I would appreciate any thoughts or recommendations folks may have. Thanks for your time!

Proxy Service: AdminProxy Admin Exception in wso2 esb 4.8.1

I have defined a simple proxy service in WSO2 ESB(4.8.1) which is listening over a QUEUE via JMS. This service after reading the message send it to another queue.
Problem:
When i define inline endpoint then it works fine, but if i refer to a registry endpoint then WSO2 ESB gives me error and does not allow me to modify the service.
Proxy Service:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="FailOverTest"
transports="jms"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<log level="full"/>
<property name="ClientApiNonBlocking" action="remove" scope="axis2"/>
<send>
<endpoint key="gov:/repository/Endpoints/EndpointFailover.xml"/>
</send>
<log level="full"/>
</inSequence>
<faultSequence>
<property name="SET_ROLLBACK_ONLY"
value="true"
scope="axis2"
type="STRING"/>
<log level="custom">
<property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
<property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
<property name="ERROR_DETAIL" expression="get-property('ERROR_DETAIL')"/>
<property name="ERROR_EXCEPTION" expression="get-property('ERROR_EXCEPTION')"/>
<property name="Transaction Action" value="Rollbacked"/>
</log>
</faultSequence>
</target>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>application/xml</default>
</rules>
</parameter>
<parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
<parameter name="transport.jms.DestinationType">queue</parameter>
<parameter name="transport.jms.Destination">FailOverRequest</parameter>
<parameter name="originator">ServiceAdmin</parameter>
<description/>
</proxy>
Registry Endpoint XML:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint>
<address uri="jms:/FailOverResponse?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue" format="pox">
</address>
</endpoint>
Error WSO2 ESB Displaying:
This error may occur if you are attempting to modify the endpoint through Source View. The Design-View endpoint modification has a nice feature that allows browsing of the registry, and it will format the link to registry endpoints successfully every time. Please try that Design-view to modify your endpoint.

WSO2ESB Simple Passthrough Proxy doesnt forward the url extensions

I implemented a simple pass through proxy i.e. when i call
"http://wso2esb:9443/services/proxy"
it should forward the request to
"http://destinationserver:80/" .
The question is the url extensions are not carried while forwarding.. i.e.
when i do a HTTP POST in
http://wso2esb:9443/services/proxy/path1/path2
the request is forwarded to
http://destinationserver:80
rather than to
http://destinationserver:80/path1/path2.
but HTTP GET behaves as expected. Could anyone help in where i am going wrong?
My Proxy.xml
<proxy xmlns="http://ws.apache.org/ns/synapse" name="proxy" transports="https,http"
statistics="disable" trace="disable" startOnLoad="true">
<target>
<outSequence>
<send/>
</outSequence>
<endpoint>
<address uri="http://destinationserver:80/"/>
</endpoint>
</target>
<description/>
</proxy>
Thanks in advance!
P.S: my WSO2ESB version : 4.8.1
If you really need that, one way (not sure this is the best) to achieve your goal would be :
<proxy xmlns="http://ws.apache.org/ns/synapse" name="proxy" transports="https,http"
statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<header name="To"
expression="concat('http://destinationserver:80',substring-after(syn:get-property('To'),'/services/proxy'))"/>
<send/>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<description/>
</proxy>
Send a post request to http://wso2esb:8280/services/proxy/path1/path2 and it should be forwarded to http://destinationserver:80/path1/path2
Things worked as per Jeans answer but Htttp HEAD request is not forwarded except it is returning 400 Bad Request. Testing with direct link on the destination server returns expected response.

How to retrive the value in Wso2esb using Xpath

I am using wso2esb4.7.0 i have written jms proxy so i wish send my data to endpoint but i am unable process this
my proxy is
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="MediaMoveQueue"
transports="jms"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property name="readingspayload" expression="$body"/>
<payloadFactory media-type="xml">
<format>
<p:hello xmlns:p="http://jaxws.youtility.in/">
<arg0 xmlns="">$1</arg0>
</p:hello>
</format>
<args>
<arg evaluator="xml" expression="get-property('readingspayload')"/>
</args>
</payloadFactory>
<!--header name="Action" value="hello"/-->
<log level="full"/>
<send>
<endpoint>
<address uri="http://192.168.1.2:8282/services/media_move_service_i_f"
format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
</target>
</proxy>
in this proxy i am getting the data like this if i log this esb
my log is look like this
{"timestamp":1383715637698,"tmpfilename":"313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","objecttype":"Punch","filename":"enterprisedb_order.pdf","totalfilesize":994086,"uuid":"313d79a7-c29b-4e1a-9609-818610a6a66b","objectid":"313d79a7-c29b-4e1a-9609-818610a6a66b","fullpath":"/tmp/tmpmedia//313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","deviceId":"911202500210109","filemimetype":"PNG"}
but i need to just send that json format of data to my endpoint for that i have tried this xpath but its showing errors of name space how would i get this
$axis2ns58:text
but its throwing errors i wish to send that data to my endpoint
i have tried this but i need above format of data only
//soapenv:Body
its giving like this result
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<axis2ns58:text xmlns:axis2ns58="http://ws.apache.org/commons/ns/payload">{"timestamp":1383715637698,"tmpfilename":"313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","objecttype":"Punch","filename":"enterprisedb_order.pdf","totalfilesize":994086,"uuid":"313d79a7-c29b-4e1a-9609-818610a6a66b","objectid":"313d79a7-c29b-4e1a-9609-818610a6a66b","fullpath":"/tmp/tmpmedia//313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","deviceId":"911202500210109","filemimetype":"PNG"}</axis2ns58:text>
</soapenv:Body>
but i wish to send below data to my endpoint even payload also not supporting for this
{"timestamp":1383715637698,"tmpfilename":"313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","objecttype":"Punch","filename":"enterprisedb_order.pdf","totalfilesize":994086,"uuid":"313d79a7-c29b-4e1a-9609-818610a6a66b","objectid":"313d79a7-c29b-4e1a-9609-818610a6a66b","fullpath":"/tmp/tmpmedia//313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","deviceId":"911202500210109","filemimetype":"PNG"}
You could try doing
//soapenv:Body/ns:text
and set the namespace
ns="http://ws.apache.org/commons/ns/payload"
Try this:
Modify your Proxy service as below :
Instead of <property name="readingspayload" expression="$body"/> , modify it to below,
<property xmlns:ns="http://ws.apache.org/commons/ns/payload" name="readingspayload" expression="$body/ns:text/text()"/>
****
Hope this should work!!!

How to get URL in outSequence?

I use clone to send a request to different servers, and use aggregate in outSequence. It can receive all response. Some may success, and some may response error. But I don't know which server response error. I think I need get URL for any response messages.
Anyone can help me?
My service config code is here:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="CloneTest" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<clone id="12345">
<target>
<endpoint>
<address uri="http://172.21.11.21:28888/usm/services/receiveMsg" format="pox" />
</endpoint>
</target>
<target>
<endpoint>
<address uri="http://172.21.11.22:28888/usm/services/receiveMsg" format="pox" />
</endpoint>
</target>
</clone>
</inSequence>
<outSequence>
<aggregate>
<completeCondition>
<messageCount min="10" max="10"/>
</completeCondition>
<send/>
</outSequence>
</target>
</proxy>
Best regards.
You can retrieve the Remote address/ host using following properties. Use to filter based on those values.
<property name="Remote address --> " expression="get-property('axis2','REMOTE_ADDR')"/>
<property name=" Remote host ---->" expression="get-property('axis2','REMOTE_HOST')"

Resources