0 Replies Latest reply on Feb 7, 2006 1:29 PM by rami

    Help! Cannot get a reference to the MBean server from a WAR

    rami

      I?m trying to create and use my own cache in a clustered environment running under jboss web server. I am currently using JBossCache version 1.2.4 deployed as an mbean in JBoss 4.0.2, running under Java 1.5.

      I created a my-service.xml in the deploy folder to configure the mbean. My config file is as follows:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <!-- ============================================================================== -->
      <!-- -->
      <!-- Customized TreeAopCache Service Configuration for API session Info Replication -->
      <!-- -->
      <!-- =============================================================================== -->
      
      <server>
      
       <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/>
      
       <!-- ==================================================================== -->
       <!-- Defines TreeCacheAop as API cache -->
       <!-- ==================================================================== -->
      
       <mbean code="org.jboss.cache.TreeCache"
       name="jboss.cache:service=MyCache">
      
       <depends>jboss:service=Naming</depends>
       <depends>jboss:service=TransactionManager</depends>
      
      
       <!--
       Configure the TransactionManager
       -->
       <attribute name="TransactionManagerLookupClass">org.jboss.cache.JBossTransactionManagerLookup</attribute>
      
       <!--
       Isolation level : SERIALIZABLE
       REPEATABLE_READ (default)
       READ_COMMITTED
       READ_UNCOMMITTED
       NONE
       -->
       <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
      
       <!--
       Valid modes are LOCAL, REPL_ASYNC and REPL_SYNC
       -->
       <attribute name="CacheMode">REPL_SYNC</attribute>
      
       <!--
       Just used for async repl: use a replication queue
       -->
       <attribute name="UseReplQueue">false</attribute>
      
       <!--
       Replication interval for replication queue (in ms)
       -->
       <attribute name="ReplQueueInterval">0</attribute>
      
       <!--
       Max number of elements which trigger replication
       -->
       <attribute name="ReplQueueMaxElements">0</attribute>
      
       <!-- Name of cluster. Needs to be the same for all clusters, in order
       to find each other
       -->
       <attribute name="ClusterName">TreeCache-Cluster</attribute>
      
       <!-- JGroups protocol stack properties. Can also be a URL,
       e.g. file:/home/bela/default.xml
       <attribute name="ClusterProperties"></attribute>
       -->
      
       <attribute name="ClusterConfig">
       <!-- Use this for TCPIP -->
       <config>
       <TCP bind_addr="IP_ADDRESS_1" start_port="7820" loopback="true"/>
       <TCPPING initial_hosts="IP_ADDRESS_1[7820],IP_ADDRESS_2[7820]" port_range="3" timeout="3500"
       num_initial_members="1" up_thread="true" down_thread="true"/>
       <MERGE2 min_interval="5000" max_interval="10000"/>
       <FD shun="true" timeout="2500" max_tries="5" up_thread="true" down_thread="true"/>
       <VERIFY_SUSPECT timeout="1500" down_thread="false" up_thread="false"/>
       <pbcast.NAKACK down_thread="true" up_thread="true" gc_lag="100"
       retransmit_timeout="3000"/>
       <pbcast.STABLE desired_avg_gossip="20000" down_thread="false" up_thread="false"/>
       <pbcast.GMS join_timeout="5000" join_retry_timeout="2000" shun="false"
       print_local_addr="true" down_thread="true" up_thread="true"/>
       <pbcast.STATE_TRANSFER up_thread="true" down_thread="true"/>
       </config>
       </attribute>
      
      
       <!--
       Whether or not to fetch state on joining a cluster
       -->
       <attribute name="FetchStateOnStartup">true</attribute>
      
       <!--
       The max amount of time (in milliseconds) we wait until the
       initial state (ie. the contents of the cache) are retrieved from
       existing members in a clustered environment
       -->
       <attribute name="InitialStateRetrievalTimeout">5000</attribute>
      
       <!--
       Number of milliseconds to wait until all responses for a
       synchronous call have been received.
       -->
       <attribute name="SyncReplTimeout">10000</attribute>
      
       <!-- Max number of milliseconds to wait for a lock acquisition -->
       <attribute name="LockAcquisitionTimeout">15000</attribute>
      
       <!-- Name of the eviction policy class. -->
       <attribute name="EvictionPolicyClass"></attribute>
      
       </mbean>
      
      </server>
      


      I created a test.jsp to access the cache. The code is as follows:

      <%@page import="javax.management.MBeanServer"%>
      <%@page import="org.jboss.mx.util.MBeanProxyExt"%>
      <%@page import="org.jboss.mx.util.MBeanServerLocator"%>
      <%@page import="org.jboss.cache.TreeCacheMBean"%>
      
      <%
      MBeanServer server=MBeanServerLocator.locateJBoss();
      TreeCacheMBean cache;
      cache=(TreeCacheMBean)MBeanProxyExt.create(TreeCacheMBean.class, "jboss.cache:service=MyCache", server);
      
      cache.put("cache.test","1","4");
      String output1 = (String) cache.get("cache.test","1");
      System.out.println("cache.test = " + output1);
      
      cache.put("cache.test","1","904");
      String output2 = (String) cache.get("cache.test","1");
      System.out.println("cache.test= " + output2);
      
      %>
      


      The test.jsp is working if it's deployed under ROOT.war, so by going to MY_DOMAIN/test.jsp I was able to get a reference to MBean server, access the MBean and use put and get methods, but whenever I use a different WAR (Let's say test.WAR) to run the test.jsp by going to MY_DOMAIN/test/test.jsp I keep getting the following error:

      2006-02-07 10:51:14,956 62108412 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/test].[jsp]] (http-0.0.0.0-80-3:) Servlet.service() for servlet jsp threw exception
      java.util.NoSuchElementException
       at java.util.AbstractList$Itr.next(AbstractList.java:426)
       at org.jboss.mx.util.MBeanServerLocator.locate(MBeanServerLocator.java:67)
       at org.jboss.mx.util.MBeanServerLocator.locate(MBeanServerLocator.java:80)
       at org.apache.jsp.test_jsp._jspService(org.apache.jsp.test_jsp:58)
       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
       at org.jboss.web.tomcat.tc5.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:81)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:526)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:534)
      


      For some reason the code fails to get a reference to the MBean server if it trys to access the cache from any other WARs deployed under the same deploy folder under the same jboss configuration.

      Here is the files hierarchy I have right now under the deploy folder:


      my-service.xml
      +jbossweb-tomcat55.sar -> ROOT.WAR -> test.jsp
      +test.WAR -> test.jsp


      Any suggestions on how to get around this problem are appreciated!!