how to cache response from endpoint in wso2 ESB - wso2

I want to cache the response in my proxy and when i hit my proxy again then it should get me the cached data. I have tried using Cache mediator but am unable to find if my data is really getting cached or not.So basically what i am trying to achieve is if i have data in cache then it shouldn't hit the endpoint.It should send the response from cache. Looking forward to your answer. Thanks in advance
I have my service code as:
public class GetMirrorValue {
public String getValue(String data) throws Exception {
System.out.println("Inside Service code");
return data;
}
}
my inSequence is:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="CheckCacheSeq">
<cache scope="per-host" collector="false" hashGenerator="org.wso2.caching.digest.DOMHASHGenerator" timeout="20">
<implementation type="memory" maxSize="100"/>
</cache>
<send>
<endpoint key="DummyEP"/>
</send>
</sequence>
and my out sequence is:
<outSequence xmlns="http://ws.apache.org/ns/synapse">
<cache scope="per-host" collector="true"/>
<send/>
</outSequence>
but whenever i hit my proxy service consecutively through try-it tool, i get data from service but not from cache coz every time in my server System.out.println("Inside Service code"); gets printed?

You can modify your backend service (The endpoint invoked by proxy service), to print something in the server log, once a request got hit. First request should hit the backend. Then within the cached period, requests won't go to the backend service. It will go to backend service only after cache is expired. So looking at the print on the backend server log, you can observe the caching behavior.
http://docs.wso2.org/wiki/display/ESB460/Sample+420%3A+Simple+Cache+Implemented+on+ESB+for+the+Actual+Service

You can enable wirelogs in ESB to see the requests/responses going through ESB.

Related

WSO2 error code 500 when invoking the API at the first time

I'm doing a stress test on an API deployed in wso2 integrator server with a high number of requests. Every stress test session. I always get the first response as fault response with an
error code 500 (internal server error)
And the remaining responses are fine.
I noticed that if the session is expired and if I want to send a request with this session id, above problem is produced.
I'm using wso2ei 6.5.0 as my server application version.
Can anyone help me please to avoid this message?
Try adding the following properties to the API sequence.
<property name="NO_KEEPALIVE" value="true" scope="axis2"/>
<property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
This will make sure that connections are properly closed in-between the test sessions.

WSO2 - cookie on second call in Service Proxy

I need to make proxy service in wso2 esb, that would be redirect requests to external wsdl service with pre send auth request to separate operation.
I make sequence like this:
clone
payloadFactory (auth xml request)
call (auth operation)
property (value=get-property('transport', 'Set-Cookie'), name=ExtCookie scope=operation)
property (value=get-property('operation', 'ExtCookie') name=Cookie)
Send (target operation)
When I make first call to this proxy service - It's work fine. But on second call I see in tcpdump that there is Cookie HTTP Header in the clone request.
I try add "property remove" with different scope(transport, operation, Synapse, default, axis2, axis2-client), but no one work. Cookie-Header wasn't removed. I need remove it for correct work with ext service.
Try with the following properties.
<property name="EXCESS_TRANSPORT_HEADERS" scope="axis2" action="remove"/>
<property name="Set-Cookie" scope="transport" action="remove"/>

How do I pass a dynamic parameter as a part of the URL of a REST service while using WSO2 ESB Proxy Service?

I am trying to simply host a REST service as a proxy service in WSO2 ESB. I am using Custom Proxy to do this. When I run the created proxy, I am not able to pass parameters to the proxy service at run time. How do I do this?
My REST service will be hit on a URL of format:http://ip:host/requestMapping/{name}
The parameter 'name' has to be passed from the UI through the ESB to the service through a proxy service hosted on the ESB. Can you help me with the steps to follow to make this work?
I tried using this page:
http://wso2.com/library/articles/2013/12/restful-integration-with-wso2-esb/
But that is for creating APIs which I have been successfully in creating. But I am unable to do this using Proxy services.
Basically in my program, when the user interacts with the UI, he enters a name as input. This name has to be passed to the proxy service hosted in the ESB which should forward this as a path variable to my REST service.
Right now, my service body is:
<inSequence>
<send>
<endpoint>
<http method="POST" uri-template="http://ip:port/resourceMapping/{uri.var.name}"></http>
</endpoint>
</send>
</inSequence>
<outSequence>
<send></send>
</outSequence>
When I run this, instead of sending the name as entered by the user, it sends "uri.var.name" to the REST service. On the other hand, if I define a property tag and define a value for it and then do this, the REST service gets the value of the property that I have set. But I need this value to be sent dynamically by the user so I can't define property and value inside.
Please help me.
I think, the best approach is to use API in this case because the request to the ESB is REST and endpoint also accepting REST. This is the best practice.

WSO2 ESB Proxy to WSO2 IS RemoteUserStoreManagerService

I want to proxy RemoteUserStoreManagerService (exposed on WSO2 IS) over WSO2 ESB.
When I call getUserClaimValuesForClaims operation I get the response. I tested the WSO2 IS (connected to my Active Directory) for performance. I sent requests in 100 threads (each thread with 250ms delay) and it gave me an average response of 250ms (which is ok for me).
So I proxied the getUserClaimValuesForClaims operation using the Transformation proxy and it also worked. But during the performace testing (with the same or smaller load) I have got following errors and not all the messages have returned (on average 1 of 100 messages).
[2014-01-06 19:28:21,047] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:d2b85c03-beaf-409b-bf39-2e8143bd9e0b, Direction: response
[2014-01-06 19:28:38,441] ERROR - SourceHandler I/O error: An established connection was aborted by the software in your host machine
java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:202)
at sun.nio.ch.IOUtil.read(IOUtil.java:175)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:243)
at org.apache.http.nio.reactor.ssl.SSLIOSession.receiveEncryptedData(SSLIOSession.java:348)
at org.apache.http.nio.reactor.ssl.SSLIOSession.isAppInputReady(SSLIOSession.java:376)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady
[2014-01-06 19:29:14,051] WARN - TargetHandler http-outgoing-66: Connection time out while in state: REQUEST_DONE
[2014-01-06 19:29:14,061] WARN - EndpointContext Endpoint : AnonymousEndpoint will be marked SUSPENDED as it failed
[2014-01-06 19:29:15,041] WARN - EndpointContext Suspending endpoint : AnonymousEndpoint - last suspend duration was : 30000ms and current suspend duration is : 30000ms - Next retry after : Mon
[2014-01-06 19:29:14,451] WARN - SourceHandler Connection time out after request is read: http-incoming-57
I thing that it says, it timeouts on backend; but I get the response logged in faultSeuence.
I noticed that the problem is caused by the XSLT mediator in proxy implementation, because when I removed the xslt mediators the log is empty. I tried xquery and it was the same. Even the log mediator in outSequence causes this issues.
Here is my final Proxy.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="GetUserProxy" transports="https http" startOnLoad="true" trace="disable">
<target>
<endpoint>
<address uri="https://localhost:9443/services/RemoteUserStoreManagerService.RemoteUserStoreManagerServiceHttpsSoap12Endpoint/"/>
</endpoint>
<inSequence/>
<outSequence>
<log/>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
When I remove the log mediator, the WARN messages disapears from log and ALL response messages are returned to SoapUI.
Could anybody tell me why it behaves this way?
Thank you very much.
David
RemoteUserStoreManagerService is an admin service. Therefore, you need to send Identity Server's user name/password in a basic authentication header or session cookie. I can not see setting of authorization headers in your proxy configuration such as following
<property expression="fn:concat('Basic ', base64Encode('username:password'))" name="Authorization" scope="transport"></property>
More details would be here. Also you need to create a message body to send to the "RemoteUserStoreManagerService" and read the response messages. These must be implemented using ESB configuration. However, you can write an custom ESB mediator to do this also. Sample java code to call this service can be found here. You can find the detail on writing custom mediator from here
We have figured out, that the problem is probably more general and doesn't relate only to WSO2 IS, because we have the same problem when similating the WSO2 IS service as SoapUI mock.
The problem is probably in HTTP-passthru transport in axis configuration, because when we switched to HTTP-NIO the problem disapears and it is even faster.
There is a post about performance tunnig that helped us.
Howevever, I would like to know what transport we should use in production or where the problem is. Because now it seems that we cannot use HTTP-passthru transport for production environment.
Is anyone experiencing this problem?
what are the versions of ESB and IS your working with..?
try to restart the ESB and call the Service again. Do remember call to Identity server is a secure call.

How to check if the reponse from one proxy service to other is FAULT message?

I am using WSO2 ESB 4.0.3 with Java 6 on MAC OSX 10.7.4. I have also installed Data Services Features.
In the typical scenario I have one proxy service which the client calls and I pass one the request to Data Service. Now if I have FAULT message from the Data service back to proxy how do I check in proxy service whether the response from Data Service is Fault or normal valid response?
Currently I am using following filter mediator logic in outsequence of proxy service
<filter xpath="get-property('FAULT')">
<then>
<log category="ERROR" level="custom" separator=",">
<property name="OWCHECK-faultMessage" value="TQS_OWCHECK - Received Fault From OWCHECK Data Service !!!!"/>
<property expression="$body" name="Fault-I-Got-Is"/>
<property name="OWCHECK-Forwading-Error" value="TQS_OWCHECK - Forwarding the Fault to Error Handler !!!!"/>
</log>
<else>
<xslt key="conf:/tqs/owcheck/proxy-output-transform.xslt"/>
<log category="INFO" level="custom" separator=",">
<property name="ValidResponse" value="TQS_OWCHECK - Sending Valid Response Back."/>
</log>
<send/>
</else>
</filter>
But this logic of checking the "FAULT" property works when axis2 has NIO senders & receivers in axis2.xml.
How ever if I switch the receivers & senders in axis2.xml from NIO to standard servlet one's (org.wso2.carbon.core.transports.http.HttpTransportListener / org.wso2.carbon.core.transports.http.HttpTransportListener) I do not get the "FAULT" property set and my error handling does not work.
Is there a standard way of checking if the response from one proxy service to another or response from data service to proxy is FAULT or not? I am looking for something which is independent of transport senders and receivers, at least HTTP ones.
Please help.
thanks
Abhijit
It is not good documentation I believe where none of the samples talk about how to handle the faults from Data service to Proxy service or am I missing something?
I would be thankful if I know the best practices to handle the errors from Data service as well as from one proxy to another proxy service.
Please help. This is big project at very prestigious company.
I think you need to check whether the soap body element has a soap:fault message or not. you can use the filter mediator with some xpath expression to check that.