Hello, EJB-DEVELOPERS!

Sorry if you see this msg for the second time, I'm not sure
if it got to the list the first time, so reposting.. Plz excuse
for possible inconvenience.

Yesterday there was a letter on JSP-INTEREST, basically asking
"How to use EJB-s with JSP-s/Servlets. I'm not an expert in this area,
but I have written a reply to this letter. The more I read my own
reply the more doubts I have. Finally I decided to subscribe to
EJB-INTEREST and send my "essay" here to ask people more knowledgeable
in the EJB containers then I am to comment on my expectedly numerous
mistakes.

BTW, I've also got some questions there at the bottom of the letter.
I would feel _very obliged_ to hear answers to them too:
no kidding you would through fog off my eyes that has been long covering
them! Plz, HELP!

Okay, here goes the letter
==========================================================================
Hello Gerry!

Not an expert, just my two-penny! I'm a beginner with EJB too!

Gerry Scheetz <[EMAIL PROTECTED]> wrote:

GS> Some topics I have run across while surfing and my thoughts.
GS> ** Enterprise Java Beans - no in-house knowledge, so we would be learning
GS> from the ground up.  Do we need a server?
Yup!

Here I'm going to write some rubbish, plz, experts, correct me!

Generally all the EJB containers may run in one of two ways:

1) EJB container run in the same jvm as the servlet container (then they
   communicate locally.)
   (requires tight integration between
    EJB and web containers)
   I guess that here it is enough to create initial
   context with a zero-arg constructor:

   new InitialContext();

   and this is J2EE compliant.

   These are the things you need to do to make
   the ejb appear in your InitialContext:

   Declare that you webapp uses the ejb,
   this is like "declaring a variable" in a programming
   language in your web.xml either:

   - use a <ejb-ref> element
     this implies using the whole heavy
     and time-consuming marshalling machinery
   - use a <ejb-local-ref> element
     this implies skipping the whole
     marshalling machinery and working directly

   Then you should "assign a value" to the "variable",
   bind a EJB home interface to the webapp's JNDI context.
   You do it either
   1a) - directly: you put a <ejb-link> element inside the <ejb-ref>,
         or <ejb-local-ref> element
         (I do not think this is a common scenario)
   1b) - indirectly: you use some EJB+Web container specific way
         (often via a web interface and/or via additional deployment
         descriptors)

2) EJB container and web container run in different JVMs. They use tcp
   to communicate.
   (This allows web and EJB containers that were not pre-tuned for
    each other still cooperate, but then it is 2.2 not 2.1)

   The 2) section has two subsections:

   2.1) EJB container and Web container are integrated closely enough.
   All is J2EE compliant. This is much like 1) variant, only you
   can not use <ejb-local-ref>, only <ejb-ref>

   2.2) you have to create the InitialContext with
        plenty of parameters (fill a HashMap and pass it to the
        constructor).

   This is not J2EE.
   You create an InitialContext that
   is almost completely independent of what the web container has
   provided you with and it does have to initiate a new TCP
   connection. (This may be as slow as creating a new database
   connection, i guess)

GS> Are they tough to code?
Haven't tried it, but guess it should be a piece of cake :-)

GS> How to get info from there to JavaBean for use in JSP?
Here I'm a moron. Please, others, do correct me!
Still you may
** have a normal JavaBean interact with a Enterprise
   Java Bean internally. Internally you create the
   InitialContext, do the look-ups and all the stuff

   You may use the Value object pattern in this case and
   probably save some time and network bandwidth. Although
   with 1a) variant the Value object pattern is not necessary.

** somewhere in the controller servlet (or in a jsp directly)
   you create the initial context, do the lookup, get an instance
   of remote (EJB 1.1 terminology) interface and bind it somewhere.
   I guess the best is as a request attribute. Then it behaves
   as a normal JavaBean and you may use it. I guess that especially
   with 1a) variant this is a feasible solution

GS> I am open for suggestions.  Actually what I would really like is a location
GS> online where I can research this a bit more.
Upps, let others help you with this :-)

- Anton
[EMAIL PROTECTED]
[EMAIL PROTECTED]

P.S.

Questions that I would like to hear answers too are:

- I just do not know if variant 2.1) actually happens in real life.
  I just do not know if WAS and Weblogic are 1) or 2.1).
  Plz, tell me!
  (I'm sure that 1) exists, JBoss+Tomcat4.0.1 give an example
  and that 2.2) exists, Resin may work in this fashion with
  great many EJB containers)

- I know that if we download JBoss+Tomcat4.0.1 from jboss.org
  it may all work and may be work in the 1) way.
  I guess that Tomcat may well work as 2.2), I guess that
  any web container will work 2.2)
  The question is: are there any other ways to make Tomcat
  run 1) then using the JBoss+Tomcat install?
  Does Tomcat run in the 2.1) mode?
  If not for both questions, then how can Tomcat be a reference
  implementation while Servlet 2.3 requires JNDI app context
  described in J2EE version 1.3
  and it requires support for <ejb-ref> and <ejb-local-ref>?

- Can Resin be made run 1) or 2.1)? I guess the currently it
  can not.

--------------------end-of-letter------------------------------


- Anton

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to