11 Replies Latest reply on Apr 2, 2006 1:02 AM by efratb

    How to access DB/session beans from applet?

    efratb

      Hi,

      I'm using JBOSS 4.0, JDK 1.5 & mysql 5.
      When I'm trying to get the context from my JSP pages I have no problems.
      But when I try to do it from an applet I get the following error:

      javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at com.imagine.em.QOD_GW.charts.BitRateChartApplet.init(BitRateChartApplet.java:64)
      at sun.applet.AppletPanel.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)

      The code I'm using is:

      javax.naming.InitialContext ctx = new InitialContext();
      portMgr = (PortManagerRemote)
       ctx.lookup("imagineManagment/PortManagerBean/remote");


      I tried to add all the jars to my CLASSPATH but it didn't help.
      Anybody has any idea?

      Thanks a lot,
      Efrat


        • 1. Re: How to access DB/session beans from applet?
          jaikiran

          You should have the jndi.properties file in the applet's classpath. The file usually contains:

          java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
          java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces


          Check the %JBOSS_HOME%/server/default/conf directory for the sample jndi.properties file

          • 2. Re: How to access DB/session beans from applet?
            efratb

            And where should I locate this file?
            What do you mean by the applet's classpath? The path from which the applet is being invoked? (Where the html/jsp file is?)

            Thanks a lot,
            Efrat

            • 3. Re: How to access DB/session beans from applet?
              jaikiran

              In the jsp, you might have used the applet tag. If you have specified a ARCHIVE param(something like the following):

              <param name = "ARCHIVE" value = "myApplet.jar" />

              Then, the jndi.properties should be placed directly under the myApplet.jar package.
              If you havent used the ARCHIVE parameter, then the jndi.properties needs to be placed in the directory which contains the applet

              • 4. Re: How to access DB/session beans from applet?
                efratb

                Yes, I'm using the ARCHIVE param.
                So the jar should include the jndi.properties?

                • 5. Re: How to access DB/session beans from applet?
                  jaikiran

                  Yes

                  • 6. Re: How to access DB/session beans from applet?
                    efratb

                    I did it and now I'm getting a different exception:

                    javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
                    at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1317)
                    at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1446)
                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:594)
                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
                    at javax.naming.InitialContext.lookup(Unknown Source)
                    at com.imagine.em.QOD_GW.charts.BitRateChartApplet.init(BitRateChartApplet.java:64)
                    at sun.applet.AppletPanel.run(Unknown Source)
                    at java.lang.Thread.run(Unknown Source)
                    Caused by: java.net.SocketTimeoutException: Receive timed out
                    at java.net.PlainDatagramSocketImpl.peekData(Native Method)
                    at java.net.DatagramSocket.receive(Unknown Source)
                    at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1287)
                    ... 7 more

                    Maybe it has something to do with the jboss & bussiness jars (e.g. jbosssx-client.jar) ??
                    Where should I place them?

                    Thanks,
                    Efrat

                    • 7. Re: How to access DB/session beans from applet?
                      jaikiran

                      Try adding the following entry to the jndi.properties file, in addition to whatever is already there:

                      java.naming.provider.url=jnp://localhost:1099




                      • 8. Re: How to access DB/session beans from applet?
                        jaikiran

                        Your jndi.properties should look like:

                        java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                        java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
                        java.naming.provider.url=jnp://localhost:1099




                        • 9. Re: How to access DB/session beans from applet?
                          efratb

                          I did it, and now I get this exception:


                          java.lang.ClassFormatError: Truncated class file
                          at java.lang.ClassLoader.defineClass1(Native Method)
                          at java.lang.ClassLoader.defineClass(Unknown Source)
                          at java.security.SecureClassLoader.defineClass(Unknown Source)
                          at java.net.URLClassLoader.defineClass(Unknown Source)
                          at java.net.URLClassLoader.access$100(Unknown Source)
                          at java.net.URLClassLoader$1.run(Unknown Source)
                          at java.security.AccessController.doPrivileged(Native Method)
                          at java.net.URLClassLoader.findClass(Unknown Source)
                          at java.lang.ClassLoader.loadClass(Unknown Source)
                          at java.lang.ClassLoader.loadClass(Unknown Source)
                          at java.lang.ClassLoader.loadClassInternal(Unknown Source)
                          at java.lang.Class.forName0(Native Method)
                          at java.lang.Class.forName(Unknown Source)
                          at sun.rmi.server.LoaderHandler.loadProxyInterfaces(Unknown Source)
                          at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
                          at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
                          at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
                          at java.rmi.server.RMIClassLoader.loadProxyClass(Unknown Source)
                          at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
                          at java.io.ObjectInputStream.readProxyDesc(Unknown Source)
                          at java.io.ObjectInputStream.readClassDesc(Unknown Source)
                          at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
                          at java.io.ObjectInputStream.readObject0(Unknown Source)
                          at java.io.ObjectInputStream.readObject(Unknown Source)
                          at java.rmi.MarshalledObject.get(Unknown Source)
                          at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:652)
                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
                          at javax.naming.InitialContext.lookup(Unknown Source)
                          at com.imagine.em.QOD_GW.charts.BitRateChartApplet.init(BitRateChartApplet.java:64)
                          at sun.applet.AppletPanel.run(Unknown Source)
                          at java.lang.Thread.run(Unknown Source)
                          basic: Exception: java.lang.ClassFormatError: Truncated class file
                          java.lang.ClassFormatError: Truncated class file
                          at java.lang.ClassLoader.defineClass1(Native Method)
                          at java.lang.ClassLoader.defineClass(Unknown Source)
                          at java.security.SecureClassLoader.defineClass(Unknown Source)
                          at java.net.URLClassLoader.defineClass(Unknown Source)
                          at java.net.URLClassLoader.access$100(Unknown Source)
                          at java.net.URLClassLoader$1.run(Unknown Source)
                          at java.security.AccessController.doPrivileged(Native Method)
                          at java.net.URLClassLoader.findClass(Unknown Source)
                          at java.lang.ClassLoader.loadClass(Unknown Source)
                          at java.lang.ClassLoader.loadClass(Unknown Source)
                          at java.lang.ClassLoader.loadClassInternal(Unknown Source)
                          at java.lang.Class.forName0(Native Method)
                          at java.lang.Class.forName(Unknown Source)
                          at sun.rmi.server.LoaderHandler.loadProxyInterfaces(Unknown Source)
                          at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
                          at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
                          at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
                          at java.rmi.server.RMIClassLoader.loadProxyClass(Unknown Source)
                          at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
                          at java.io.ObjectInputStream.readProxyDesc(Unknown Source)
                          at java.io.ObjectInputStream.readClassDesc(Unknown Source)
                          at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
                          at java.io.ObjectInputStream.readObject0(Unknown Source)
                          at java.io.ObjectInputStream.readObject(Unknown Source)
                          at java.rmi.MarshalledObject.get(Unknown Source)
                          at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:652)
                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
                          at javax.naming.InitialContext.lookup(Unknown Source)
                          at com.imagine.em.QOD_GW.charts.BitRateChartApplet.init(BitRateChartApplet.java:64)
                          at sun.applet.AppletPanel.run(Unknown Source)
                          at java.lang.Thread.run(Unknown Source)

                          Any idea??
                          Thanks,
                          Efrat

                          • 10. Re: How to access DB/session beans from applet?
                            rludwick

                            Efrat,
                            Did you solve your problem? The same thing is happening to me when I try to do a lookup on ConnectionFactory from an applet.

                            Robert

                            • 11. Re: How to access DB/session beans from applet?
                              efratb

                              Hi,

                              Yes, I solved the problem somehow...
                              I added all the jboss jars to the classpath, and the files of the server side I added to the applet's jar.
                              Good luck...
                              Efrat