8 Replies Latest reply on Oct 25, 2005 8:23 AM by hgarrett2

    EJB3 Tutorial Problem with Servlet

    hgarrett2

      I followed step by step JBoss EJB3.0 TrailBlazers and Demo Applications and now I have the authors-beans.eb3 running on my Standalone JBoss_4.0.3

      I need to access the AuthorsBean from a Servlet on a Standalone Tomcat 5.0.X Web Server that is running on the same Host. How do I do it? How do I configure the Context? Is JNDI the preferible method to access the EJBeans3 ?

      Can anyone paste here a Servlet version of AuthorServlet for use in a Standalone Tomcat ?

      P.S.Why does authors-beans.ejb3 cannot be deployed as authors-beans.jar ?
      Is there a jboss xml config file where I can change it ?

        • 1. Re: EJB3 Tutorial Problem with Servlet
          java.jago

          Hi,

          Sorry I cannot answer your question - however please help me.

          I also want to repeat the JBoss Trailblazer Demos. But I have some problems...can you tell me what version of JBoss AS you have - how you installed and configuered it, which Trailblazers you successfully finished...etc.

          What do you use JBossIDE ? Which version ?

          Cheers,
          jago

          • 2. Re: EJB3 Tutorial Problem with Servlet
            hgarrett2

            I do not use "JBoss IDE" because I like Eclipse 3.1 as it is, not an adapted version wich is the one JBoss download page offers. I also hate 'myeclipse' / 'Nitrox' or 'Exadel' because they tend to monopolize this wonderfull and Powerfull - FREE - OpenSource IDE.

            My Eclipse 3.1 also uses Tomcat plugin for .war export of the web-modules. So, to install it I just copied the folders named org.jboss.ide.eclipse.* to the /plugins (just Linux here) folder in /usr/local/eclipse.

            The Trailblazer of EJB3.0 has some minor things (check:http://www.jboss.com/index.html?module=bb&op=viewtopic&t=69256)
            but overall is fine and working. (Even the configuration)

            I just pointed that EJB3.0 Trailblazers describe a WebAplication for an Embbebed Tomcat, and that is not good by the same reasons I pointed earlier. Tomcat is Fine and working greater in its own place. And since EJB3 is new there aren't many tutorials about working in Servlets with EJB3. So I really need to discuss it here.

            • 3. Re: EJB3 Tutorial Problem with Servlet
              bill.burke

              the trailblazer is out of date as you already might have guessed. Michael Yuan is in the process of updating it.

              • 4. Re: EJB3 Tutorial Problem with Servlet
                neelixx

                I'm not sure, but if you launch Tomcat in another process than JBoss, won't you create another JVM?

                If it does, the only way to access the AuthorBean on JBoss from a standalone Tomcat, is to use the remote interface, and JNDI.

                If that's the case, configure your context to go to the JNDI port that your JBoss server is listening to. You can find this during the startup of your server. I think it's 1099?????

                Your EJB3 jar files need to be configured with the .ejb3 extension rather than the .jar to be recognized by the EJB3 deployer. The deployer reads your annotations and builds the necessary interfaces.

                • 5. Re: EJB3 Tutorial Problem with Servlet
                  hgarrett2

                  Many thanks to your reply Neelix.
                  Yes, it is true I'll use a second JVM by using a standalone Tomcat.
                  I configured the in server.xml to get the new and the correct reference.
                  I also made a copy of the jndi.properties from the .ejb3 to the .war.
                  Everything seems fine but the error is always the same:

                  Error: javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: java.security.AccessControlException: access denied

                  I checked catalina.policy file and confirmed grant option of "java.naming.*" is "read";

                  What is happening here? Does this error says something precisely ?
                  thanks again in advance.

                  • 6. Re: EJB3 Tutorial Problem with Servlet
                    hgarrett2

                    The Forum Editor catched all my tags!
                    Just to correct the third phrase.
                    ( I configured the "context" in server.xml to get the new "resourceParams" and the correct "Ejb" reference. )

                    • 7. Re: EJB3 Tutorial Problem with Servlet
                      neelixx

                      Taken directly from:

                      http://www.amitysolutions.com.au/documents/JBossTomcatJNDI-technote.pdf

                      Jon Barnett states, "Tomcat provides its own JNDI service but it cannot be used to directly locate JBoss components as there are no locations of JBoss stored in the Tomcat JNDI service. You need to get your web application to perform the lookup using the JBoss JNDI service as the location of the home objects for your EJBs are stored in that directory."

                      Again, taken from the same technote:

                      try
                       {
                       Properties jndiProps = new Properties();
                       jndiProps.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                       jndiProps.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interface");
                       jndiProps.setProperty(Context.PROVIDER_URL, "jnp://jboss-server:1099")
                       Object reference = (new InitialContext(jndiProps)).lookup
                      ("ejb/amity/remote/EJBean");
                       EJBeanHome home = (EJBeanHome)PortableRemoteObject.narrow(reference,
                      EJBeanHome.class);
                       EJBean bean = home.create();
                      ...
                      }
                       catch(Exception e)
                      {
                       e.printStackTrace();
                      }
                      


                      I hope this is of some help.

                      Cheers

                      • 8. Re: EJB3 Tutorial Problem with Servlet
                        hgarrett2

                        For those who want Tomcat Standalone connected to JBoss EJB3. Here's the answer:

                        Many thanks again for the reply Neelixx, I knew I had to use the JBoss JNDI service and I had the technote you mentioned already printed. But it was not the Servlet code the cause of the AccessControlException, it was Tomcat policy. I think it's better to write here the answer in case of others need to jump quickly over this nightmare.

                        First of all: The error « Class org.jboss.ejb3.JBossProxy not found » can be solved by including the "jboss-ejb3.jar" and "jboss-aspect-library-jdk50.jar" in the WEB-INF/lib folder since in my case the .classpath strangely sometimes is ignored.(probably cause -» symlinks)

                        The problem of JNDI "java.security.AccessControlException: access denied" in Tomcat can be solved this way:

                        Edit your "catalina.policy" file and write this at the bottom:

                        // Access to JNDI/JNP
                        grant codeBase "file:${catalina.home}/-" {
                        permission java.net.SocketPermission "localhost:1024-", "connect,accept,listen,resolve";
                        permission java.util.PropertyPermission "*","read";
                        };

                        grant codeBase "file:${catalina.home}/Projects-main-Folder/-" {
                        permission java.security.AllPermission;
                        };

                        grant {
                        permission java.lang.RuntimePermission "accessDeclaredMembers";
                        permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
                        permission java.lang.RuntimePermission "defineCGLIBClassInJavaPackage";
                        };

                        Stop Tomcat and Start it with this command:
                        cd $CATALINA_HOME
                        ./startup.sh -security

                        It is up and running. Now everything is working.