How to get Digest vlue generated from Cache Mediator? - wso2-esb

I am working on Cache Mediator in wso2esb. My requirement is to get Hash Digest value generated by org.wso2.carbon.mediator.cache.digest.DOMHASHGenerator class in this mediator.
<sequence name="In_Seq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<cache collector="false"
hashGenerator="org.wso2.carbon.mediator.cache.digest.DOMHASHGenerator"
id="MyCache" maxMessageSize="2000" scope="per-host" timeout="120">
<onCacheHit/>
<implementation maxSize="1000" type="memory"/>
</cache></sequence>
<sequence name="Out_Seq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<cache collector="true" id="MyCache" scope="per-host"/>
</sequence>
Can you tell me how to do that?

Related

wso2esb remove context path from uri

I'm defining an API in wso2esb for one of the tenants. This tenant automatically gets it's own context path when defining an API (e.g. http://127.0.0.1:8280/tenant1/api-identifier/).
The next step is that this request gets forwarded to an http endpoint (e.g. http://127.0.0.1:9191/v1/). But when looking at the logs the esb tries to send this request to http://127.0.0.1:9191/v1/tenant1/api-identifier/ which can't give a response. Can I remove this part from the url. It feels like this should work out of the box.
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
<registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
<parameter name="cachableDuration">1500</parameter>
</registry>
<taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"/>
<sequence name="In">
<log category="TRACE" level="full"/>
<send>
<endpoint key="gov:/HelloWorld"/>
</send>
</sequence>
<sequence name="fault">
<log level="full"/>
</sequence>
<sequence name="main">
<in>
<log/>
<sequence key="conf:/InSecure"/>
</in>
<out>
<send/>
</out>
</sequence>
<sequence name="Out">
<send/>
</sequence>
<sequence name="InSecure">
<log/>
<send>
<endpoint key="gov:/HelloWorld"/>
</send>
</sequence>
<api context="/lensworld.be/hw" hostname="192.168.1.100"
name="HelloWorld" port="9191">
<resource inSequence="InSecure" methods="GET" outSequence="Out"/>
</api>
Try removing the REST_URL_POSTFIX property:
<property name="REST_URL_POSTFIX" action="remove" scope="axis2"/>
From the docs:
The value of this property will be appended to the target URL when sending messages out in a RESTful manner through an address endpoint. This is useful when you need to append a context to the target URL in case of RESTful invocations. If you are using an HTTP endpoint instead of an address endpoint, specify variables in the format of "uri.var.*" instead of using this property.

WSO2 ESB iterate mediator joining

i'm facing some problems with this process.. let me explain:
i want to call two services and join the responses in this order:
i have the first service's response:
<locations xmlns="http://ssocial.com/traceit/services/location">
<location>
<latitude>-33.45209980</latitude>
<longitude>-70.66241990</longitude>
<altitude>0.0</altitude>
<creation>2016-09-04T14:59:48.000-03:00</creation>
<updated>2016-09-04T14:59:48.000-03:00</updated>
<deviceId>25</deviceId>
</location>
<location>
<latitude>-33.45149521</latitude>
<longitude>-70.66146224</longitude>
<altitude>817.0</altitude>
<creation>2016-09-04T13:18:43.000-03:00</creation>
<updated>2016-09-04T13:18:43.000-03:00</updated>
<deviceId>25</deviceId>
</location>
</locations>
then i have the secon service's response :
<device xmlns="http://ssocial.com/traceit/services/device">
<id>25</id>
<code>mobile_02</code>
<type>
<id>1</id>
<name>MOBILE</name>
</type>
And then, the final response that i would like to have is :
<locations xmlns="http://ssocial.com/traceit/services/location">
<location>
<latitude>-33.45209980</latitude>
<longitude>-70.66241990</longitude>
<altitude>0.0</altitude>
<creation>2016-09-04T14:59:48.000-03:00</creation>
<updated>2016-09-04T14:59:48.000-03:00</updated>
<deviceId>25</deviceId>
<device xmlns="http://ssocial.com/traceit/services/device">
<id>25</id>
<code>mobile_02</code>
<type>
<id>1</id>
<name>MOBILE</name>
</type>
</device>
</location>
<location>
<latitude>-33.45149521</latitude>
<longitude>-70.66146224</longitude>
<altitude>817.0</altitude>
<creation>2016-09-04T13:18:43.000-03:00</creation>
<updated>2016-09-04T13:18:43.000-03:00</updated>
<deviceId>25</deviceId>
<device xmlns="http://ssocial.com/traceit/services/device">
<id>25</id>
<code>mobile_02</code>
<type>
<id>1</id>
<name>MOBILE</name>
</type>
</device>
</location>
</locations>
i'm really having lot of troubles trying to join both responses like that, and this is my sequence in wso2:
<sequence name="getDeviceInfoByLocationProcess" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="count(//ns1:locations/ns1:location)" name="LOCATIONS_COUNT" scope="default" type="STRING" xmlns:ns1="http://ssocial.com/traceit/services/location"/>
<iterate description="" expression="//ns1:locations/ns1:location/ns1:deviceId" id="LOCATIONS_ITERATOR" xmlns:ns1="http://ssocial.com/traceit/services/location">
<target>
<sequence>
<property description="device_id" expression="//ns1:deviceId" name="device_id" scope="default" type="STRING"/>
<sequence key="getDeviceInfoProcess"/>
</sequence>
</target>
</iterate>
<log level="custom">
<property expression="//ns1:locations" name="LOCATIONS" xmlns:ns1="http://ssocial.com/traceit/services/location"/>
<property expression="//ns2:device" name="DEVICE_INFO" xmlns:ns2="http://ssocial.com/traceit/services/device"/>
</log>
<property name="ECNCLOSING_ELEMENT" scope="default">
<wrapper xmlns=""/>
</property>
<aggregate id="AGG_01">
<completeCondition>
<messageCount max="-1" min="{get-property('LOCATIONS_COUNT')}"/>
</completeCondition>
<onComplete expression="//ns2:device" xmlns:ns2="http://ssocial.com/traceit/services/device">
<log level="full">
<property expression="$ctx:LOCATIONS_COUNT" name="COUNTER"/>
<property expression="$ctx:ECNCLOSING_ELEMENT" name="ENCLOSING"/>
</log>
<call/>
</onComplete>
</aggregate>
and actually with this sequence, i'm just getting this:
<device xmlns="http://ssocial.com/traceit/services/device">
<id>25</id>
<code>mobile_02</code>
<type>
<id>1</id>
<name>MOBILE</name>
</type>
In advance , thank you very much for the help
I can't see the content of "getDeviceInfoProcess" sequence, but I guess your are using call mediator. So, as a result of those requests (multiple requests because of iterate mediator), you receive some responses and that what you have to deal with in the rest of the initial mediation : aggregate offers you a way to wait for all the responses, but the initial message is lost : you should save it in a property (type OM) and use something like payloadMediator inside aggregate/onComplete to compose the final message.

WSO2 ESB 4.9 Call mediator is not working fine in same situations

I have a proxy service with below definition:
<?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>
<header name="Action" value="urn:loadPerson"/>
<payloadFactory media-type="xml">
<format>
<sear:loadPerson xmlns:sear="http://localhost/SearchService">
<sear:Id>1234</sear:Id>
</sear:loadPerson>
</format>
<args/>
</payloadFactory>
<log level="full"/>
<call>
<endpoint key="SearchService"/>
</call>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
So it's work fine when I call the proxy service(by tryIt) first time and I get right response of proxy service but for the next time it faces a problem and show me fault response:
<soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>axis2ns11:Server</faultcode>
<faultstring>Missing operation for soapAction [urn:loadPerson] and body element [null] with SOAP Version [SOAP 1.1]</faultstring>
</soapenv:Fault>
As you can see I log the message and it's the same for every proxy call:
INFO - LogMediator To: /services/TestProxy.TestProxyHttpSoap11Endpoint, WSAction: urn:loadPerson, SOAPAction: urn:loadPerson, MessageID: urn:uuid:cc9557cc-e2a0-4b8d-97a8-ae393a411157, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><sear:loadPerson xmlns:sear="http://localhost/SearchService"><sear:Id>1234</sear:Id></sear:loadPerson></soapenv:Body></soapenv:Envelope>
I found that the problem resolved by restarting the server(not redeploying the proxy service) or leave it for few minutes!
any idea?!

Simple WSOESB Proxy doen't response

Very simple example. Request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<T>
<m1>bysy</m1>
<m1>momo</m1>
<m1>gigi</m1>
</T>
</soapenv:Body>
</soapenv:Envelope>
I want to iterate and log every element in tag m1.
Proxy code:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Loopback" transports="https,http"
<target>
<inSequence>
<property name="OUT_ONLY" value="true" scope="axis2"/>
<iterate expression="//T/m1">
<target>
<sequence>
<property name="OUT_ONLY" value="true" scope="axis2"/>
<log level="custom">
<property name="M1" expression="//text()"/>
</log>
<drop/>
</sequence>
</target>
</iterate>
</inSequence>
</target>
</proxy>
It work as expected and logs all values. But WSO2ESB server doesn't close connection, until it falls with timeout. (I use SOAPUI for testing)
I tried to put properties OUT_ONLY RESPOND NO_KEEPALIVE in different part of proxy but it didn't help, as well I tried to use , with same result.
It looks like problem in iterate mediator which doesn't let to inSequence to terminate and send response to client. Once i remove it, proxy disconnect immediately with status code '202' message accepted.
This is because, by default, attribute "continueParent" is set to false with iterate mediator : change to <iterate continueParent="true" expression="//T/m1">
And you should explicitly send a 202 inside your inSequence, set this property : <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>

WSO2 ESB Store and Forward Processor not obeying endpoint message format

We have been testing the message processors and queues on wso2 esb. We have been using the sampling processor quite successfully to just log data to a DB. This POX end to end. The sampling processor correctly dequeues a message and sends it to the endpoint. The endpoint is defined as POX and non-chunked, and all this works well.
We decided to try the store and forward processor as we wanted to test out the guaranteed delivery mechanism. So we created a new processor and defined it as store and forward. In the main sequence that stores the message, we added the target.endpoint property before storing the message. The property was set to the same endpoint that was being used in the sampling scenario.
However - what have found is that in this mode, the message transformation does not happen correctly. The content type is set to text/html and the output is chunked. This causes our service to return a 415 error.
We have tried adding messageType, contentType etc to multiple place, to the axis http sender transport, etc, but it seems to make no difference at all.
Any guidance on this would be appreciated
Define the following property in the sequence before sending to the endpoint
<property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
The JS code below simply inserts the messageID into the return payload to the caller. Using this with a sampling processor and sequence that simply sends to the same endpoint works fine.
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
<registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
<parameter name="cachableDuration">15000</parameter>
</registry>
<endpoint name="test_e">
<address uri="http://192.168.45.168:8080/cgi-bin/esbcgi.pl" format="pox"/>
<property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
</endpoint>
<sequence name="fault" trace="enable">
<log level="full">
<property name="MESSAGE" value="Executing default 'fault' sequence"/>
<property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
<property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
</log>
<drop/>
</sequence>
<sequence name="main" onError="fault" trace="enable">
<in>
<log level="full"/>
<property name="OUT_ONLY" value="true"/>
<property name="FORCE_HTTP_1.0" value="true" scope="axis2"/>
<script language="js">
var message = mc.getMessageID();
var messageId = message.substring(9,45);
var payload = mc.getPayloadXML().*;
mc.setPayloadXML(
<payload> <messageId>{messageId}</messageId>{payload}
</payload>);
</script>
<switch xmlns:ns="http://org.apache.synapse/xsd" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:ns3="http://org.apache.synapse/xsd" source="get-property('To')">
<case regex=".*/TEST/.*">
<property name="target.endpoint" value="test_e" scope="default"/>
<store messageStore="TEST"/>
</case>
<default/>
</switch>
<property name="OUT_ONLY" value="false"/>
<script language="js">var serviceMessageId = mc.getMessageID();
mc.setPayloadXML(
<tag xmlns="http://tagcmd.com">
<messageId>{serviceMessageId}</messageId> </tag>);
</script>
<send>
<endpoint key="MessageService"/>
</send>
</in>
<out>
<script language="js">
var messagePayload= mc.getPayloadXML().*.*;
mc.setPayloadXML(
<eventResponse> <messageId>{messagePayload}</messageId> </eventResponse>);
</script>
<send/>
</out>
<description>The main sequence for the message mediation</description>
</sequence>
<messageStore class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore" name="TEST">
<parameter name="java.naming.factory.initial">org.apache.qpid.jndi.PropertiesFileInitialContextFactory</parameter>
<parameter name="java.naming.provider.url">repository/conf/jndi.properties</parameter>
<parameter name="store.jms.destination">APP8</parameter>
</messageStore>
<messageProcessor class="org.apache.synapse.message.processors.forward.ScheduledMessageForwardingProcessor" name="test_p2" messageStore="TEST">
<parameter name="max.deliver.attempts">1</parameter>
</messageProcessor>
</definitions>