11 Replies Latest reply on Dec 23, 2002 11:41 PM by Allen Johnson

    Does anybody calls EJB from standalone Tomcat?

    Alex Cholokov Newbie

      Hello, all

      Does anybody calls EJB from standalone Tomcat?
      May you point me to correct configuration example?

      Al.

        • 1. Re: Does anybody calls EJB from standalone Tomcat?
          prabhakar chaganti Apprentice

          By standalone tomcat, are you referring to a tomcat installation separate from the jboss bundled with tc?

          -prabhakar

          • 2. Re: Does anybody calls EJB from standalone Tomcat?
            Alex Cholokov Newbie

            Exactly. I want Tomcat and Jboss running in two JVMs, enven on two different computers. And i had some probs when try to setup this. So may be somebody have success whith such task.

            • 3. Re: Does anybody calls EJB from standalone Tomcat?
              Michael Schoning Newbie

              I can call and EJB running in JBoss from another JVM using the code below. I don't see any reason why it wouldn't work from inside tomcat aswell.

              I also added jboss-all.jar to my class path.


              public class CountryRegions {
              private InitialContext initialContext = null;

              private com.eds.plm.eit.eaproxy.ejb.GetRegionsEjbHome getHome() throws NamingException {
              return (com.eds.plm.eit.eaproxy.ejb.GetRegionsEjbHome) getContext().lookup(GetRegionsEjbHome.JNDI_NAME); // Must be your JNDI name
              }

              private InitialContext getContext() throws NamingException {

              if(initialContext == null){
              Hashtable props = new Hashtable();
              props.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
              props.put(InitialContext.PROVIDER_URL, "jnp://pcoa525.edsplm.com:1099");
              initialContext = new InitialContext(props);
              }
              return initialContext;
              }

              public void testBean() {

              try {
              com.eds.plm.eit.eaproxy.ejb.GetRegionsEjb myBean = getHome().create();
              RegionBean[] beans = myBean.getRegions("US");
              }
              catch (RemoteException e) {
              e.printStackTrace();
              }
              catch (CreateException e) {
              e.printStackTrace();
              }
              catch (NamingException e) {
              e.printStackTrace();
              }
              catch (Exception e) {
              e.printStackTrace();
              }

              }

              public static void main(String[] args) {
              CountryRegions test = new CountryRegions();
              test.testBean();

              }
              }

              Michael

              • 4. Re: Does anybody calls EJB from standalone Tomcat?
                Andrzej Taramina Newbie

                It's not very useful having to hardcode the JNDI Initial Context properties in your code. I've tried putting a jndi.properties file in many places in my external (separate JVM) Tomcat, but to no avail.

                Has anyone figured out a way to get the new InitialContext() method to find the JBoss jndi.properties file somewhere on the classpath inside a Tomcat servlet? Is this one of those nasty classloader issues?

                I'm using Tomcat 4.1.12 and JBoss 3.0.4.

                • 5. Re: Does anybody calls EJB from standalone Tomcat?
                  Alex Cholokov Newbie

                  Hello,
                  Somewhere in maillists i fount a solution that is work for me too. See below

                  tomcat-user
                  <-- Chronological --> Find <-- Thread -->

                  Tomcat 4.1.7 + remote Jboss (SUCCEFUL)

                  --------------------------------------------------------------------------------

                  From: Mauricio Nunez
                  Subject: Tomcat 4.1.7 + remote Jboss (SUCCEFUL)
                  Date: Tue, 13 Aug 2002 09:28:27 -0700

                  --------------------------------------------------------------------------------

                  Hi,

                  I'm trying to get Jboss + Tomcat working remotely.
                  At my test server, I install Tomcat 4.1.7 and Jboss 3.0.1 standalone.

                  To get my code working, i put my jdni.properties file at
                  WEB-INF/classes, copy all the client jars to WEB-INF/lib, and my test
                  ejb jar.

                  Then,I added and ejb-ref entry at my web.xml, defining an "ejb/Storage"
                  name.

                  >From my code, I used the tomcat' InitialContext, getting an valid
                  reference to my deployed EJB.

                  ctx.lookup("java:comp/env/ejb/Storage")

                  My question is:

                  Are all these steps necessary , or exists a shorter approach ?

                  Any comments are welcome.

                  Thanks

                  ---------------------------------------------------------------------

                  my jndi.properties in WEB-INF/classes

                  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

                  my web.xml:

                  <ejb-ref>
                  Prueba de coneccion con ejb
                  <ejb-ref-name>ejb/Storage</ejb-ref-name>
                  <ejb-ref-type>Session</ejb-ref-type>
                  com.chile.ejb.test.StorageHome
                  com.chile.ejb.test.Storage
                  <ejb-link>jnp://localhost:1099/Storage</ejb-link>
                  </ejb-ref>


                  my code:

                  javax.naming.InitialContext ctx=new javax.naming.InitialContext();

                  StorageHome home = (StorageHome) javax.rmi.PortableRemoteObject.narrow(
                  ctx.lookup("java:comp/env/ejb/Storage") , StorageHome.class);






                  --
                  To unsubscribe, e-mail: <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
                  For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>



                  --------------------------------------------------------------------------------

                  Tomcat 4.1.7 + remote Jboss (SUCCEFUL), Mauricio Nunez


                  <-- Chronological --> <-- Thread -->

                  Reply via email to

                  • 6. Re: Does anybody calls EJB from standalone Tomcat?
                    Andrzej Taramina Newbie

                    I'm using the latest stable releases: Tomcat version (4.1.12)...and JBoss(3.0.4).

                    Putting the jndi.properties file in the jmx-console WEB-INF/Classes does NOT work. My servlet code picks up the Tomcat JNDI instead of the JBoss one.

                    Any ideas?

                    • 7. Re: Does anybody calls EJB from standalone Tomcat?
                      Andrzej Taramina Newbie

                      Doesn't work for me. I put my jndi.properties file in the jmx-console WEB-INF/classes directory....but when I create my InitialContext ctx = new InitialContext() it picks up the Tomcat JNDI tree instead of the JBoss one.

                      Anyone have any clues?

                      Thanks!

                      • 8. Re: Does anybody calls EJB from standalone Tomcat?
                        Darrel Riekhof Newbie

                        I thought the files to edit in chaldon's post were all to do with the Tomcat web container, not JBoss EJB container. Anyone confirm or deny this?

                        What does he mean by 'copy all the client jars to WEB-INF/lib'? Copy the needed ejb classes to the web app's lib dir?

                        Do you have to put <ejb-ref> tags in your web app's web.xml file for each remote EJB it uses?

                        • 9. Re: Does anybody calls EJB from standalone Tomcat?
                          Darrel Riekhof Newbie

                          I got it working, ignore my post above.

                          Anyone know the minimal set of JBoss client jars that need to go in your webapp's lib dir? I just threw them all in there...

                          • 10. Re: Does anybody calls EJB from standalone Tomcat?
                            seanxu Newbie

                            It is bogus!!!
                            It only works when &lt;ejb-ref&gt; is defined in web.xml. I even tried to discard jndi.properties from WEB-INF/classes directory and it still works. But if I take out &lt;ejb-ref&gt; from web.xml then it fails in JNDI lookup.
                            Tomcat container does not pick up the jndi.properties from WEB-INF/classes.

                            Has anyone tested differently?

                            thanks,

                            • 11. Re: Does anybody calls EJB from standalone Tomcat?
                              Allen Johnson Newbie

                              > It is bogus!!!
                              > It only works when <ejb-ref> is defined in
                              > web.xml. I even tried to discard jndi.properties from
                              > WEB-INF/classes directory and it still works. But if
                              > I take out <ejb-ref> from web.xml then it fails
                              > in JNDI lookup.
                              > Tomcat container does not pick up the jndi.properties
                              > from WEB-INF/classes.
                              >
                              > Has anyone tested differently?
                              >
                              > thanks,

                              It is required to have an <ejb-ref> for every remote ejb you reference in your web-app. Same for local ejb's if you are running embedded tomcat.

                              Its the same concept as referencing an ejb within another ejb. You need to declare an ejb-ref so that jboss can map the actual jndi name to the java:comp/env/ejb/... jndi name specific for that ejb. With a web-app, you need to have the same kinda reference.