Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how web container talk with EJB container?

 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how web container talk with EJB container? using RMI_IIOP? sorry for the silly question.
 
Srinivas Velamuri
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Potentially Web container can be hosted by a JVM and EJB Container can be hosted by a different JVM. Java objects of two different JVMs communicate using RMI protocol. I think prior to EJB 1.1 spec., these containers are permitted to talk in plain RMI, but after EJB 1.1, RMI-IIOP is the standard protocol between them.
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks. If web container and EJB container are in same JVM. How do they talk with each other?any example.
 
Srinivas Velamuri
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean Components of Web container and those of EJB Container use RMI-IIOP protocol for communication purpose. I don't think Web Container and EJB Container will talk to each other. Correct me if I am wrong.
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes , I meant the components in the container too. Just need to get basic idea about how they communicate with each other.Maybe I need to check some book about it.
 
Bert Ertman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question depends on the EJB api used. In EJB 1.1 all communication from whatever to an EJB is remote. All calls have stubs/ties in between. So RMI-IIOP will be used. Of course there are commercial application servers available that have 'workarounds' for that, they either use their own faster protocols, like Weblogic does (T3 or Tengah to Tengah protocol) or provide you with 'dirty tricks' to do local lookups to enhance performance. (like Websphere: com.ibm.CORBA.iiop.noLocalCopies=true) As you know...remote calls are very expensive. In EJB 2.0 there is also a possibility to do local lookups of EJBs. Ofcourse you have to be sure that both components are within the same VM otherwise it is not possible. If some vendor implements a Webcontainer and an EJB container that run on top of the same VM, it will be possible to do local lookups from e.g. a servlet in the web container to an EJB in the EJB container.
Good luck!
Bert
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,Bert Ertman. You explanation is very clear. In case someone want to use JSP/Servelet to commmuncate with the EBJ,does he/she have to use RMI/IIOP? Sorry if my question is too basic.
[ March 27, 2002: Message edited by: Win Yu ]
 
Bert Ertman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm..not sure if I understand your question... Normally (in EJB 1.1) if you want to use an EJB from a servlet/jsp you have to do a JNDI lookup of the bean, which returns you a stub. The fact that there is a stub means that you use RMI-IIOP, or some proprietary protocol from some vendor as I explained in my earlier post.
In EJB 2.0, the bean developer might decide to develop an ADDITIONAL two interfaces, called localhome and local interface. These are 'normal' interfaces, not java.rmi.Remote! Using these interfaces, another component is able to talk to the locally available bean. but only if both components are within the same VM.
Make sure you get this right...these local interfaces are ALSO implemented by the EJB OBJECT (!) and NOT the Bean class itself. Otherwise it would break the service based architecture of EJB and ofcourse the EJB spec. ("One should NEVER have the bean implementation class implement it's home or remote interface".)
As you might have figured out, with EJB 2.0 it's possible to build EJBs that have either two or even four interfaces. (both remote and locally accessible)
EJB 2.0 is not part of the exam, but ofcourse always nice to talk about
kind regards,
Bert
 
Jim Baker
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is related.
How the transaction and session management
passed over between web container and ejb
container? Does J2EE spec covers that?
Need connectors between them?
Any inputs are welcome.
Jim
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim: I copied something from blueprint, hope this can help you to understand a little bit.
8.5 Transactions in Applets and Application Clients
The J2EE platform does not require transaction support in applets and application clients, though like distributed transactions, a J2EE product might choose to provide this capability for added value. So, whether applets and application clients can directly access a UserTransaction object depends on the apabilities provided by the container. To ensure portability, applets and application clients should delegate
transactional work to enterprise beans.
8.6 Transactions in Web Components
A servlet or JSP page can use JNDI to lookup a UserTransaction object, then use the UserTransaction interface to demarcation transactions. This is useful in a two-tier
application where a Web component needs to access enterprise information systems under the scope of a JTA transaction. Code Example 8.1 illustrates the use of the JTA interface to demarcate trans-actions within a Web component:
Context ic = new InitialContext();
UserTransaction ut = (UserTransaction) ic.lookup("java:comp/UserTransaction");
ut.begin();
[ March 28, 2002: Message edited by: Win Yu ]
 
Jim Baker
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Win.
That means the web container itself does not
handle transaction at all. What if I'm using
container managed demarcation in ejb tier?
Jim
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think EJB tier can start a new TX or just follow the TX(maybe no TX) from web tier. correct me if I am wrong.
 
Alberto Dell'Era
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim:
What if I'm using
container managed demarcation in ejb tier?
Jim

Are you asking what happens if you don't start
the transaction in the web tier ?
Assuming that is what you're asking for, here
is a quick explanation.
If, say, the "transaction attribute" of all your methods is set to "Required", which is the better approach IMHO, the transaction will start at the beginning of the EJB tier method you are calling fro the web tier, and will finish (commit or rollback) at the end of the same method. All "submethods", i.e. methods called from the method above, will join (i.e. will be part of) the transaction.
If the "transaction attribute" is set to other values the behaviour is different, of course. All is explained quite clearly here :
http://java.sun.com/blueprints/guidelines/designing_enterprise_applications/transaction_management/enterprise_beans/index.html
Ciao
Alberto
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,Alberto. Your explanation is perfect.
 
Jim Baker
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alberto:
If I started a TX in web tier (in a servlet),
how this TX propagated into ejb tier? When a
commit/rollback is done in the backend DB,
assuming the ejb container and DB are connected,
how the TX is hand over back to the web tier so
the servlet can do something.
JB
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Baker:
Alberto:
If I started a TX in web tier (in a servlet),
how this TX propagated into ejb tier? When a
commit/rollback is done in the backend DB,
assuming the ejb container and DB are connected,
how the TX is hand over back to the web tier so
the servlet can do something.
JB

In this case, sevlet or jsp(web container) is the one who start that TX.It can use javax.transaction.UserTransaction object to know if TX commit or abort from EJB container. I hope I am right about this.
 
Jim Baker
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there an API to get the UserTransaction object
from ejb container?
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you can use JNDI to look up TX service and then get object.Just guess.
[ April 04, 2002: Message edited by: Win Yu ]
 
Jim Baker
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can U post a sample code for this? JNDI looking
up transaction?
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
----------------------------------------------
Code Example 8.1 illustrates the use of the JTA interface to demarcate transactions within a Web component:

Context ic = new InitialContext();
UserTransaction ut =
(UserTransaction) ic.lookup("java:comp/UserTransaction");
ut.begin();
// perform transactional work here
ut.commit();
Code Example 8.1 Web Component Using JTA Transactions
---------------------------------------------
I copied above from blueprint.Hope this can help.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For this to work the UserTransaction would need to be added as a reference to your web applications deployment descriptor because the actual JNDI name for the Application Server's implementation of javax.transaction.UserTransaction is dependent on the Application Server. I think (don't quote me) that it is simply javax.transaction.UserTransaction for WebLogic.
 
sarah Marsh
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the following question has not been answered, anybody please:
If I started a TX in web tier (in a servlet), how this TX propagated into ejb tier?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic