6 Replies Latest reply on May 3, 2005 3:44 AM by darranl

    Applet and EJB

    austinkenny

      I have trouble getting applets and EJBs to work?. Regarding the tutorial
      http://www.huihoo.com/jboss/online_manual/3.0/ch13s21.html

      Thanks to Mr. Sacha Labourey I have managed to solve some of the issues... here are the issues I have encountered to help others.
      Finally I finish with the issue which is stopping my progress so far.

      Firstly to help others trying to implement this Tutorial?.
      I am using jboss 4.0.1
      Eclipse to build my code
      Running the applet via Firefox or internet explorer

      AppletClient.war this contains the code for the applet and the html page.

      [EjbModule] Deploying TestApplet


      The applet was failing when the below line is executed?.

      TestAppletHome home = (TestAppletHome)PortableRemoteObject.narrow( new InitialContext(jndiProps).lookup( "TestApplet" ),TestAppletHome.class) ;

      Error message:
      javax.naming.NoIntialContextExecption: Cannot instantiate class:org.jnp.interfaces.NamingContextFactory[Root execption is java.lang.ClassNotFoundExeception: org.jnp.interface.nameing ContextFactory]

      All other jars associated to the tutorial have been copied to deploy directory along with jbossall-client.jar

      Again Thanks to Mr. Sacha Labourey. the answer to this issue was

      adding the jnp-client.jar to the AppletClient.war WAR downloaded by the applet.

      Second issue:

      I was denied access to socket connection because of a security issue.

      I have temporarily adjusted the java.policy file in the Java\jre1.5.0_02\lib\security directory on my machine which has the client deployed on it?.giving permission to open socket connection to the server machine (please note the jboss server is a deployed on a separate machine).

      permission java.net.SocketPermission "127.0.0.1:1098-", "accept, connect, listen, resolve";

      This solved the security issue (TEMPORY) as this will mean every client machine will have to change there java.policy file to run the applet?. users can't be asked to do this.

      This is the issue where I am now stuck:
      I know that the machine that has JBOSS running and the TestApplet EJB deployed is listening to the 1098 port because I executed the command netstat:

      Performing the netstat ?a command returns:

      tcp6 0 0 *:1098 *:* LISTEN

      yet the return from the applet is as follows:

      javax.naming.CommunicationExecption [Root execption is java.rmi.ConnectionExecption: Connection refused to host 127.0.0.1; nested execption is: java.net.ConnectionExecption: Connection refused: connect]

      Can any one help?

      Regards

      Austin Kenny
      kennyau@cs.tcd.ie
      Trinity College Dublin
      Knowledge Data Engineering Group





        • 1. Re: Applet and EJB
          milowe

          A few ideas that might you in the right direction:
          1. JNP
          I am not sure how you set the naming props in your applet. Try this for now:

          Properties env = new Properties();
          env.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
          env.setProperty("java.naming.provider.url", "YourServerIP:1099");
          Context ctx = new InitialContext(env);

          If you get this to work you can then change to get the IP of the server from the applet instead of hardwiring it.
          2. Port 1099
          The deafult port for the naming service is 1099. You need to allowed to connect to that port from the applet.(unless you have changed the port).
          3. Signing the applet
          Another way to get the applet to make those network connection outside the sandbox is to sign it. That way you dont have to bother about the policy file.

          If you want to deploy this solution over the Internet you probably want to change the naming service to use the HttpNamingContextFactory to run it over HTTP and get through all those fws.

          • 2. Re: Applet and EJB
            austinkenny

            Hi

            Just so you know this is how I am naming props:

            Properties jndiProps = new Properties() ;
            Context context = new InitialContext(jndiProps);

            jndiProps.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" ) ;

            jndiProps.setProperty("java.naming.provider.url", myip:1099) ;

            jndiProps.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jboss.naming" ) ;

            jndiProps.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" ) ;

            // The below statment is where the error is returned

            TestAppletHome home = (TestAppletHome)PortableRemoteObject.narrow( new InitialContext(jndiProps).lookup( "TestApplet" ),
            TestAppletHome.class) ;


            error: javax.naming.CommunicationExecption [Root execption is java.rmi.ConnectionExecption: Connection refused to host 127.0.0.1; nested execption is: java.net.ConnectionExecption: Connection refused: connect]


            I have in the java.policy file:

            permission java.net.SocketPermission "127.0.0.1:1098-", "accept, connect, listen, resolve";
            permission java.net.SocketPermission "127.0.0.1:1099-", "accept, connect, listen, resolve";

            and i still get this error.

            if I make this change below as you suggested: HttpNamingContextFactory.
            Am I using the correct class from the jar jbossall-client.jar?

            jndiProps.setProperty("java.naming.factory.initial", "org.jboss.naming.HttpNamingContextFactory" ) ;

            where else should changes be applied?

            Thanks for all the help...
            Austin

            • 3. Re: Applet and EJB
              austinkenny

              By the way myip is the ip of the other machine which is hosting JBOSS

              • 4. Re: Applet and EJB
                milowe

                Lets focus on one thing at the time. You need to make other changes in your configuration in order to use RMI over HTTP (just using HttpNamingContextFactory wont do it).

                First of all, I assume that the ip of your JBoss box is not 127.0.0.1 since you say yoi run it on another box.
                Still it seems that you are trying to connect to localhost when doing the JNDI lookup. Do you use ip or hostname in "myip"? Check your host files and check that you dont use a hostname that resolves to localhost(127.0.0.1).

                • 5. Re: Applet and EJB
                  cfagiani

                  I'm having a similar issue. When I invoke the create method on my bean, I get an error (see below). I have signed my applet and I'm looking up the context using the following code:

                  Properties jndiProps = new Properties() ;
                  String myServer = this.getCodeBase().getHost ();
                  jndiProps.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" ) ;
                  jndiProps.setProperty("java.naming.provider.url", "127.0.0.1:1099" ) ;
                  jndiProps.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" ) ;
                  participantHome = (DrawingParticipantSessionHome)PortableRemoteObject.narrow( new InitialContext(jndiProps).lookup( "ejb/chickenscratch/drawing/bus/ejb/DrawingParticipantSession" ),
                  DrawingParticipantSessionHome.class) ;

                  The server is hosted on my local machine (so 127.0.0.1 should be the correct IP). I've also validated that the JNDI name I'm passing is correct.

                  Can anyone offer any suggestions?


                  java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)

                  at java.security.AccessControlContext.checkPermission(Unknown Source)

                  at java.security.AccessController.checkPermission(Unknown Source)

                  at java.lang.SecurityManager.checkPermission(Unknown Source)

                  at java.lang.SecurityManager.checkMemberAccess(Unknown Source)

                  at java.lang.Class.checkMemberAccess(Unknown Source)

                  at java.lang.Class.getDeclaredMethods(Unknown Source)

                  at org.jboss.invocation.MarshalledInvocation$DeclaredMethodsAction.run(MarshalledInvocation.java:571)

                  at java.security.AccessController.doPrivileged(Native Method)

                  at org.jboss.invocation.MarshalledInvocation.getFullInterfaceHashes(MarshalledInvocation.java:157)

                  at org.jboss.invocation.MarshalledInvocation.calculateHash(MarshalledInvocation.java:303)

                  at org.jboss.invocation.MarshalledInvocation.writeExternal(MarshalledInvocation.java:473)

                  at java.io.ObjectOutputStream.writeExternalData(Unknown Source)

                  at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)

                  at java.io.ObjectOutputStream.writeObject0(Unknown Source)

                  at java.io.ObjectOutputStream.writeObject(Unknown Source)

                  at sun.rmi.server.UnicastRef.marshalValue(Unknown Source)

                  at sun.rmi.server.UnicastRef.invoke(Unknown Source)

                  at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)

                  at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:118)

                  at org.jboss.invocation.InvokerInterceptor.invokeInvoker(InvokerInterceptor.java:163)

                  at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:103)

                  at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)

                  at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:169)

                  at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:91)

                  at $Proxy0.create(Unknown Source)

                  at chickenscratch.app.applet.DrawingApplet.init(Unknown Source)

                  at sun.applet.AppletPanel.run(Unknown Source)

                  at java.lang.Thread.run(Unknown Source)

                  • 6. Re: Applet and EJB
                    darranl

                    Last time I did something similar to this was in a rush so didn't get a chance to look into the problem too deeply.

                    I think my solution in the end was to sign all jars used by the Applet, so that included the JBoss jars.