Wednesday Aug 06, 2008

EHCache using Jersey

Ehcache is a general purpose distributed caching framework and server written in Java. Greg Luck has reported in a blog entry that the newly released Ehcache 0.3 now supports a RESTful interface using Jersey. Very nice! Greg provides more details on the interface in the blog entry.

Greg also goes into details on how to use this from the client-side. Using the Jersey client API makes it very easy to use the service, for example creating or updating a new cache entry:

String xmlDocument = "...";
Client c = Client.create();
WebResource r = c.resource("http://localhost:8080/ehcache/rest/sampleCache2/2");
r.type("application/xml").put(xmlDocument);

Anything other than a 2xx response will result in an UniformInterfaceException being thrown. This makes it easier to manage errors returned from services.

Retrieving the cached entry as a DOM object can be performed as follows: 

Node n = r.accept("application/xml").get(DOMSource.class).getNode();

Again, anything other than a 2xx response will result in an exception being thrown. Alternatively it is possible to check more details of the response:

ClientRespone cr = r.get(ClientResponse.class);
if (cr.getStatus() < 300 && 
        cr.getType().isCompatibleWith(MediaType.APPLICATION_XML_TYPE)) {
    Node n = cr.getEntity(DOMSource.class).getNode();
}

Notice that in the above two cases the WebResource instance r is reused.

Caching can be performed on the client side too, so i am wondering if the Jersey client API could reuse Ehcache for a caching solution, embedded (file or in-memory) or networked. Jersey client filters could written and installed to check the cache first.

BBC using Jersey

A recent comment on a blog entry from Jon, a developer at the BBC, says:

Thought you might be interested to hear that here at the BBC we now have a RESTFul JSR311 compliant webservice implemented using Jersey running with Jetty.

It is currently for internal use only but is part of an editorial toolset that Sports Journalists are using.

Nice, great news Jon! Maybe in some modest way Jersey will be contributing to the reporting of the Olympics :-)

About

sandoz

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today