5 Replies Latest reply on Sep 14, 2010 10:59 AM by manik

    REST access to GUI demo cache

    eboily

      Hi
      I am trying to access the GUI demo cache from a REST interface.
      I did deploy the GUI demo on two servers with the following configuration:
      <?xml version="1.0" encoding="UTF-8"?>
      <infinispan
            xsi:schemaLocation="urn:infinispan:config:4.0 http://www.infinispan.org/schemas/infinispan-config-4.0.xsd"
            xmlns="urn:infinispan:config:4.0">
       
         <global>
            <transport clusterName="demoCluster"/>
         </global>
         <default>
            <clustering mode="replication">
               <l1 enabled="true" lifespan="60000"/>
               <hash numOwners="2" rehashRpcTimeout="120000"/>
               <sync/>
               <stateRetrieval fetchInMemoryState="true" />
            </clustering>
         </default>
      </infinispan>
      {code}
      So far so good, the two servers share the cached data and everything works as expected.
      I then installed tomcat and deployed infinispan-server-rest.war in it. Of course I copied the ${infinispan}/gui-demo-cache-config.xml as ${tomcat}/webapps/infinispan-server-rest/WEB-INF/classes/infinispan.xml and I have the following lines in my ${tomcat}/webapps/infinispan-server-rest/web.xml:
      <init-param>
              <param-name>infinispan.configuration</param-name>
              <param-value>infinispan.xml</param-value>
      </init-param>
      When I access localhost:8080/infinispan-server-rest/, I do get the "Welcome to the Infinispan RESTful Server".
      Using the GUI, I put the (key,value)=(1,100) in the cache.
      Now, I expect that when I use my browser and go to localhost:8080/infinispan-server-rest/rest/___defaultCache/1, I would get
      100
      as the answer. But I get
      HTTP Status 404 - The requested resource () is not available.
      I am assuming that the compiled GUI demo uses the DefaultCacheManager and the cache name is ___defaultCache, and this is the one accessed by the REST server. However, when I use the python script sample_python_REST_client.py to play with the REST server, I got the right results (the script stores a key-value pair and gets it back). It seems that the REST server is not connected with the GUI demo cache but its own cache.
      Any idea what I did get wrong? Or am I totally in the far left field?
      Thanks for your help!
      - Edouard

      Hi

       

      I am trying to access the GUI demo cache from a REST interface.

       

      I did deploy the GUI demo on two servers with the following configuration:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <infinispan

            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

            xsi:schemaLocation="urn:infinispan:config:4.0 http://www.infinispan.org/schemas/infinispan-config-4.0.xsd"

            xmlns="urn:infinispan:config:4.0">

       

         <global>

            <transport clusterName="demoCluster"/>

         </global>

       

         <default>

            <clustering mode="replication">

               <l1 enabled="true" lifespan="60000"/>

               <hash numOwners="2" rehashRpcTimeout="120000"/>

               <sync/>

               <stateRetrieval fetchInMemoryState="true" />

            </clustering>

         </default>

      </infinispan>

       

       

       

       

      So far so good, the two servers share the cached data and everything works as expected.

      I then installed tomcat and deployed infinispan-server-rest.war in it. Of course I copied the ${infinispan}/gui-demo-cache-config.xml as ${tomcat}/webapps/infinispan-server-rest/WEB-INF/classes/infinispan.xml and I have the following lines in my ${tomcat}/webapps/infinispan-server-rest/web.xml:

      <init-param>

              <param-name>infinispan.configuration</param-name>

              <param-value>infinispan.xml</param-value>

      </init-param>

       

      When I access localhost:8080/infinispan-server-rest/, I do get the "Welcome to the Infinispan RESTful Server".

       

      Using the GUI, I put the (key,value)=(1,100) in the cache.

      Now, I expect that when I use my browser and go to localhost:8080/infinispan-server-rest/rest/___defaultCache/1, I would get

      100

      as the answer. But I get

      HTTP Status 404 - The requested resource () is not available.

       

      I am assuming that the compiled GUI demo uses the DefaultCacheManager and the cache name is ___defaultCache, and this is the one accessed by the REST server. However, when I use the python script sample_python_REST_client.py to play with the REST server, I got the right results (the script stores a key-value pair and gets it back). It seems that the REST server is not connected with the GUI demo cache but its own cache.

       

      Any idea what I did get wrong? Or am I totally in the far left field?

       

      Thanks for your help!

       

      - Edouard

        • 1. Re: REST access to GUI demo cache
          galder.zamarreno

          THe GUI demo starts its own cache as per the gui demo config file. The REST module would, using the same configuration, create its own cache as well. Now, if clustering is set up correctly, whatever you put in the GUI demo should be retrievable from the REST server, assuming distribution or replication modes where used.

           

          In your case, the default cache is configured with clustering and replication, so you it should work. I believe the default transport that used is UDP, so check your environment depending on whether the GUI and REST server are running on same machine or different one. You can verify whether UDP works using instructions in http://www.jgroups.org/manual/html/ch02.html#d0e426

          • 2. Re: REST access to GUI demo cache
            sellhorn

            I'm getting a very similar problem.

             

            I have a program that has infinispan.xml (which it's own cluster name), and then on the REST server under WEB-INF I put the same file. I can't see the REST server connecting at all, I don't even think it's reading my infinispan.xml file (I have DEBUG turned on, and don't see it saying it is).

             

            Going to try with just no configuration file using default cluster/default cache now :-(

            • 3. Re: REST access to GUI demo cache
              sellhorn

              Still not fully there, but this could be a problem. In infinispan final, web.xml has the property name

               

               

                    <init-param>
                       <param-name>infinispan.config</param-name>
                       <param-value>/infinispan.xml</param-value>
                       <param-name>infinispan.configuration</param-name>
                       <param-value>/infinispan.xml</param-value>
                    </init-param>

                    <init-param>

                       <param-name>infinispan.configuration</param-name>

                       <param-value>infinispan.xml</param-value>

                    </init-param>

               

               

              But on the trunk, the scala code uses another property;

              http://anonsvn.jboss.org/repos/infinispan/trunk/server/rest/src/main/scala/org/infinispan/rest/StartupListener.scala

               

              class StartupListener extends HttpServlet {
                 override def init(cfg: ServletConfig) {
                    super.init(cfg)
                    val cfgFile = cfg getInitParameter "infinispan.config"
                    if (cfgFile == null)
                       ManagerInstance.instance = new DefaultCacheManager
                    else {
                       ManagerInstance.instance = new DefaultCacheManager(cfgFile)
                    }

               

              Still don't have things fully working, but this is certainly a related issue ...

              • 4. Re: REST access to GUI demo cache
                sellhorn

                OK, using infinispan.config makes it work ! :-)

                 

                I filed a JIRA issue on this; https://jira.jboss.org/browse/ISPN-645

                 

                I'm putting object values and it works great, on the reads having other issues ... but that's another story :-)

                • 5. Re: REST access to GUI demo cache
                  manik

                  Thanks for reporting; I've fixed this.  You'll see the fix in the next 4.2.0 release.