unable to call getKeys using JNDI
---------------------------------

         Key: JBCACHE-84
         URL: http://jira.jboss.com/jira/browse/JBCACHE-84
     Project: JBoss Cache
        Type: Bug
    Versions: 1.2    
    Reporter: Bela Ban
 Assigned to: Bela Ban 
    Priority: Minor
     Fix For: 1.2.1


I an unable to call getKeys on a TreeCache.  I get the Cache by doing a JNDI 
lookup.  Once I get it I can do a put and get with no problem. When I call 
getKeys I get an NotSerializableException on java.util.HashMap$KeySet.
Here is my JUnit test and results..


  | package com.cexp.common.enterprise;
  | 
  | import java.util.Set;
  | import java.util.Collection;
  | import java.util.Iterator;
  | 
  | import junit.framework.TestCase;
  | 
  | import org.apache.commons.logging.Log;
  | import org.apache.commons.logging.LogFactory;
  | import org.jboss.cache.TreeCacheMBean;
  | import javax.naming.NameNotFoundException;
  | import javax.naming.InitialContext;
  | import javax.naming.NameParser;
  | import javax.naming.NamingException;
  | import javax.naming.Context;
  | import javax.naming.Name;
  | 
  | 
  | /**  Simple tests for the ContextFramework.
  |  * @author kkalmbac
  |  *
  |  */
  | public class TestCache extends TestCase {
  |   /** the logger. */
  |   private static Log log = LogFactory.getLog(TestCache.class);
  |   private InitialContext context;
  |   private TreeCacheMBean theCache;
  |   public static Object lookup(Context context, Name name)
  |                                             throws NamingException
  |   {
  |     // Try the lookup twice because, if the naming server has gone down, 
  |     // the jndi connection in the context is stale and doesn't seem to 
  |     // get recreated until after the first lookup attempt.  The second 
  |     // lookup attempt will then succeed.  
  | 
  |     int lookupCount = 0;
  |     int lookupAttempts = 2;
  | 
  |     while (lookupCount++ < lookupAttempts)
  |     {
  |       try
  |       {
  |         if(log.isDebugEnabled()){
  |             log.debug("lookup() name=" + name);
  |         }
  |         return context.lookup(name);
  |       }
  |       catch (NamingException e)
  |       {
  |         if(log.isDebugEnabled()){
  |             log.debug("lookup() NamingException", e);
  |         }
  |         if (lookupCount == lookupAttempts)
  |           throw e;
  |       }
  |     }
  | 
  |     return null;
  |   }  
  |   public static Object lookup(Context context, String name)
  |                                             throws NamingException
  |   {
  |     NameParser parser = context.getNameParser(context.getNameInNamespace());
  |     return lookup(context, parser.parse(name));
  |   }
  |   
  |   protected InitialContext getContext() {
  |     if (context == null) {
  |       try {
  |         context = new InitialContext();
  |       } catch (Exception e) {
  |         log.error("could not get initial context", e);
  |       }
  |     }
  | 
  |     return context;
  |   }
  |   
  |   private TreeCacheMBean getCache() {
  |         if (log.isDebugEnabled())
  |         {
  |             log.debug("getCache()");
  |         }
  | 
  |         if (theCache == null)
  |         {
  |             try
  |             {
  |                 theCache = (TreeCacheMBean)lookup(getContext(), 
"MyTreeCache");
  |                 if (log.isDebugEnabled())
  |                 {
  |                     log.debug("cache found " + theCache);
  |                 }
  |             }
  |             catch (NameNotFoundException e)
  |             {
  |             }
  |             catch (Exception e)
  |             {
  |             }
  |         }
  | 
  |         return theCache;
  |   }  
  |   /** Constructor.
  |    * @param s the test name
  |    */
  |   public TestCache(String s) {
  |     super(s);
  |     
  |     System.setProperty(
  |       "java.naming.factory.initial",
  |       "org.jnp.interfaces.NamingContextFactory");
  |     System.setProperty(
  |       "java.naming.factory.url.pkgs",
  |       "org.jboss.naming:org.jnp.interfaces");
  |     System.setProperty(
  |       "jnp.socketFactory",
  |       "org.jnp.interfaces.TimedSocketFactory");
  |     System.setProperty("java.naming.provider.url", "jnp://localhost:1099");
  |     System.setProperty("jnp.timeout", "0");
  |     System.setProperty("jnp.sotimeout", "0");
  | 
  |   
  |   }
  |   
  |   /** Simple tests for the UserContext. */
  |   public void testGetKeys() {
  |     TreeCacheMBean cache = getCache();
  |     try {
  |       cache.put("/","Test","value");
  |       Object o = cache.get("/", "Test");
  |       System.out.println("We got " + o);
  |       Set s = cache.getKeys("/");
  |     } catch (Exception e) {
  |       e.printStackTrace();
  |     }
  |   }
  | }
  | 

Here is the results..

  | We got value
  | java.lang.reflect.UndeclaredThrowableException
  |     at $Proxy0.getKeys(Unknown Source)
  |     at com.cexp.common.enterprise.TestCache.testGetKeys(TestCache.java:135)
  |     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  |     at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  |     at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  |     at java.lang.reflect.Method.invoke(Method.java:324)
  |     at junit.framework.TestCase.runTest(TestCase.java:154)
  |     at junit.framework.TestCase.runBare(TestCase.java:127)
  |     at junit.framework.TestResult$1.protect(TestResult.java:106)
  |     at junit.framework.TestResult.runProtected(TestResult.java:124)
  |     at junit.framework.TestResult.run(TestResult.java:109)
  |     at junit.framework.TestCase.run(TestCase.java:118)
  |     at junit.framework.TestSuite.runTest(TestSuite.java:208)
  |     at junit.framework.TestSuite.run(TestSuite.java:203)
  |     at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
  |     at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
  |     at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
  | Caused by: java.io.NotSerializableException: java.util.HashMap$KeySet
  |     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
  |     at 
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
  |     at 
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
  |     at 
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
  |     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
  |     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
  |     at 
org.jboss.remoting.RemoteMethodInvocationResult.<init>(RemoteMethodInvocationResult.java:47)
  |     at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:284)
  |     at 
org.jboss.remoting.transport.socket.SocketServerInvoker$Client.run(SocketServerInvoker.java:208)
  | 

Any help at all would be appreciated.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://jira.jboss.com/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
JBoss-Development mailing list
JBoss-Development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to