Infinispan RESTful interface

 

Using a custom Infinispan cache configuration

Out of the box, Inifinispan uses a default cache configuration. To set a custom configuration, create an Infinispan XML configuration file and set the PATH to it in your web.xml file, under the key infinispan.config.

The infinispan configuration file is dictated by the Init Servlet which contains the name and the path where the configuration is stored:

<servlet>
   <servlet-name>InitServlet</servlet-name>
   <servlet-class>org.infinispan.rest.StartupListener</servlet-class>

   <!-- Specify your cache configuration file -->
   <init-param>
     <param-name>infinispan.config</param-name>
     <param-value>infinispan.xml</param-value>
 </init-param>

. . . . .
 </servlet>

As it is, drop the following infinispan.xml file into WEB-INF/classes of your application:

<infinispan
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="urn:infinispan:config:4.2 http://www.infinispan.org/schemas/infinispan-config-4.2.xsd"
 xmlns="urn:infinispan:config:4.2">

   <namedCache name="cacheX" />

</infinispan>

So now you can reference cacheX from your RESTful clients.

Last minute addition:

I'm adding a pure javascript code (no jQuery) for interacting with REStful services, you can have a try on it if you like:

 

var url = "http://localhost:8080/infinispan/rest/cacheX/bucket1";
var representationOfDesiredState = "Adding this to the cache";

var client = new XMLHttpRequest();

client.open("PUT", url, false);

client.setRequestHeader("Content-Type", "text/plain");

client.send(representationOfDesiredState);

if (client.status == 200)
 alert("The request succeeded!\n\nThe response representation was:\n\n" + client.responseText)
else
 alert("The request did not succeed!\n\nThe response status was: " + client.status + " " + client.statusText + ".");

References: http://community.jboss.org/wiki/InfinispanRESTserver

Follow us on Twitter