This discussion is archived
5 Replies Latest reply: May 8, 2012 6:44 AM by gimbal2 RSS

How lookup EJB from another application on Glassfish 3.1

916153 Newbie
Currently Being Moderated
Hello,

I have EJB application exposing remote interface SystemIf (which is implemented by local, stateless session bean System). I can easy lookup this interface from client application
using call like: *(SystemIf)context.lookup( "business.SystemIf" );* - it works ok.
I want also to refer this interface from Web Service application deployed on the same GlassFish server. I was trying many approaches but every time I receive exceptions like:

SEVERE: javax.naming.NamingException: Lookup failed for 'java:global/EjbApplication/SystemIf' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: *SystemIf not found*]

I tried following lookup calls:

Properties props = new Properties();
props.setProperty("java.naming.factory.initial" , "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state" , "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
context = new InitialContext( props );
system = (SystemIf)context.lookup( "java:global/MegajanServerApp/System" );
system = (SystemIf)context.lookup( "java:global/MegajanServerApp/SystemIf" );
system = (SystemIf)context.lookup( "java:global/MegajanServerApp/business/SystemIf" );
system = (SystemIf)context.lookup( "business.SystemIf" );
               
I added "*gf-client.jar*" file to build path of my WebService aplication in Eclipse. Please help me resolve this problem.
Thanks in advance.
  • 1. Re: How lookup EJB from another application on Glassfish 3.1
    gimbal2 Guru
    Currently Being Moderated
    I don't think you should be setting up any JNDI stuff when you try to lookup something on the same application server; the JNDI environment is already configured BY the server.

    You should ditch all the configuration properties and just try to lookup the bean through its business (remote) interface.
    context = new InitialContext();
    // lookup bean
    You may even be able to just inject the remote interface if it is really running on the same server.

    http://docs.oracle.com/javaee/6/tutorial/doc/gipjf.html
  • 2. Re: How lookup EJB from another application on Glassfish 3.1
    916153 Newbie
    Currently Being Moderated
    Yes I knew it. I did such attempt before I started to use JNDI lookups with preconfigured InitialContext.
    When I used InitialContext without parameters the same exception occurs. I am not sure but I the web service application is running on web container,
    but EJB application is runing on other container. I am little puzzled.
    Maybe JNDI query has wrong syntax or I need to configure some special settings on server via Glassfish admin console.
    I still cannot lookup EJB from another aplication from Web Service although they are on the same Glassfish application server :(
    How to do that?
  • 3. Re: How lookup EJB from another application on Glassfish 3.1
    gimbal2 Guru
    Currently Being Moderated
    Eh now you're contradicting yourself. What is it? They're running on different containers or they are running on the same container? Note: "glassfish server" = container.

    Since JEE6 JNDI naming is standardized, no need to wonder about what name you should be using. If you don't have a good book on EJB 3.1 laying around (you should, I recommend "Enterprise Javabeans 3.1" by O'Reilly publishing) then your backup is the Glassfish management interface. It should be able to tell you under which names EJBs are deployed. There is never a need for guesswork.

    EDIT:

    alternatively, read the EJB 3.1 specifications. They're actually quite clear:

    http://download.oracle.com/otndocs/jcp/ejb-3.1-fr-eval-oth-JSpec/

    And on top of that I also wrote an article that includes listing some of the most common global JNDI names you will need:

    http://entjavastuff.blogspot.com/2012/01/jboss-7-creating-prototype-webapp.html

    (search for "Bootstrapping the database" and scroll a little down)
  • 4. Re: How lookup EJB from another application on Glassfish 3.1
    916153 Newbie
    Currently Being Moderated
    Thanks for all the materials. I will check them.
    Actually I have read some informations from link You sent in previous reply. I came accross interesting solution which may solve my problem.
    There is said using @WebService and @WebMethod annotations I could make my EJB class accesible for web clients. Then I don't need to
    create separate Web Service application calling EJB's from my first application. I will try this. I think this is exactly what I needed.
    Remote business interface implemented by my EJB class exposes set of methods returning data in JSON format which can based by JavaScript based clients.
  • 5. Re: How lookup EJB from another application on Glassfish 3.1
    gimbal2 Guru
    Currently Being Moderated
    Slawomir wrote:
    There is said using @WebService and @WebMethod annotations I could make my EJB class accesible for web clients. Then I don't need to
    Well what that does is turn your EJB into a JAX-WS webservice (in other words: a SOAP service). That makes it easier to open it up to the outside world, sure. Its even portable, you could access the webservice from something else than Java.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points