You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Arnaud Level <le...@ist.fujitsu.com> on 2001/03/13 10:11:06 UTC

ejb-ref/EjbRef/EjbFactory implementation

Hi everyone,
I'm working on the implementation of the EjbFactory class (Tomcat 4.0).
According to what I've understand, this class is used when the lookup
method is called from a Servlet (or jsp).
e.g: Context ctx = new InitialContext();
      ctx.lookup("java:comp\MyEjb");
If the ejb-ref tag has been defined in the web.xml file, Tomcat is able
to find the EjbFactory (through the EjbRef saved for MyEjb). Then what
can this Factory do ?
It delegates the job to the Ejb server in its getObjectInstance method:
    - by creating a new InitialContext (with the factory class of my Ejb
server as env parameter).
   - by calling the lookup method of the newly created context and
returning the resulting value.
If this is correct, what the point to define the home,remote and
ejb-link (in the web.xml file) value since they are not passed to the
Ejb server which will use the one defined in its own web.xml file. So
the question is what are those value (defined in the web.xml file of
read by Tomcat) used for ?
Am I misundertanding something ?
Any help is appreciated.
Thank you.
Arnaud Level.

This is a basic way to implement it but it shows the idea:
e.g: EjbFactory.java
  public Object getObjectInstance(Object obj, Name name, Context
nameCtx,
                                    Hashtable environment)
        throws NamingException {

        if (obj instanceof EjbRef) {
            Reference ref = (Reference) obj;
            Hashtable table = new Hashtable(2);
            table.put(Context.INITIAL_CONTEXT_FACTORY,
"com...MyEjbServerCtxFactory");
           javax.naming.InitialContext initCtx = new
javax.naming.InitialContext(table);
           return initCtx.lookup("MyEjb"); //
        }
        return null;

    }



Re: ejb-ref/EjbRef/EjbFactory implementation

Posted by Remy Maucherat <re...@apache.org>.
> I am very interested in this implementation.  I have been trying to use
the
> tomcat context to get a reference to an EJB in another machine (running
> Jboss).
> In my investigation, the <ejb-link> is the most important field in
> <ejb-ref> when there are multiple machines because it defines the full URL
> to the EJB
> (schema://machine.url:port/published.ejb.name).
> The NamingManager should be able to use the schema to find the
> URLContextFactory.  And the 'machine.url:port' for the connection.
>
> The <home> <remote> and other tags are useful, when the EJB containter is
> sharing the same JVM as jakarta (and thus the same name space).

I think the factory is supposed to check the type of the returned bean.

Remy


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, email: tomcat-dev-help@jakarta.apache.org


Re: ejb-ref/EjbRef/EjbFactory implementation

Posted by tt...@ticnet.com.
I am very interested in this implementation.  I have been trying to use the
tomcat context to get a reference to an EJB in another machine (running
Jboss).  
In my investigation, the <ejb-link> is the most important field in
<ejb-ref> when there are multiple machines because it defines the full URL
to the EJB 
(schema://machine.url:port/published.ejb.name).  
The NamingManager should be able to use the schema to find the
URLContextFactory.  And the 'machine.url:port' for the connection.

The <home> <remote> and other tags are useful, when the EJB containter is
sharing the same JVM as jakarta (and thus the same name space).

Please send me more details of your implementation.
Thanks, Tim

Arnaud Level writes:

> Hi everyone,
> I'm working on the implementation of the EjbFactory class (Tomcat 4.0).
> According to what I've understand, this class is used when the lookup
> method is called from a Servlet (or jsp).
> e.g: Context ctx = new InitialContext();
>       ctx.lookup("java:comp\MyEjb");
> If the ejb-ref tag has been defined in the web.xml file, Tomcat is able
> to find the EjbFactory (through the EjbRef saved for MyEjb). Then what
> can this Factory do ?
> It delegates the job to the Ejb server in its getObjectInstance method:
>     - by creating a new InitialContext (with the factory class of my Ejb
> server as env parameter).
>    - by calling the lookup method of the newly created context and
> returning the resulting value.
> If this is correct, what the point to define the home,remote and
> ejb-link (in the web.xml file) value since they are not passed to the
> Ejb server which will use the one defined in its own web.xml file. So
> the question is what are those value (defined in the web.xml file of
> read by Tomcat) used for ?
> Am I misundertanding something ?
> Any help is appreciated.
> Thank you.
> Arnaud Level.
> 
> This is a basic way to implement it but it shows the idea:
> e.g: EjbFactory.java
>   public Object getObjectInstance(Object obj, Name name, Context
> nameCtx,
>                                     Hashtable environment)
>         throws NamingException {
> 
>         if (obj instanceof EjbRef) {
>             Reference ref = (Reference) obj;
>             Hashtable table = new Hashtable(2);
>             table.put(Context.INITIAL_CONTEXT_FACTORY,
> "com...MyEjbServerCtxFactory");
>            javax.naming.InitialContext initCtx = new
> javax.naming.InitialContext(table);
>            return initCtx.lookup("MyEjb"); //
>         }
>         return null;
> 
>     }
> 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, email: tomcat-dev-help@jakarta.apache.org