This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes ejbcertificate.com question on ejbActivate() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "ejbcertificate.com question on ejbActivate()" Watch "ejbcertificate.com question on ejbActivate()" New topic
Author

ejbcertificate.com question on ejbActivate()

Poobhathy Kannan
Ranch Hand

Joined: May 26, 2004
Posts: 94
The exhibit excerpt is from a container managed persistence entity bean, which one of the following statements is correct?

...
public void ejbActivate() {
try{
// get the caller principal
Principal callerPrincipal=myEntityCtx.getCallerPrincipal();
// get the distinguished name fromthe principal
log(callerPrincipal.getName());
} catch(Throwable t) {
//Oooops!!
}
}
...

1.There will be an entry in the log with the return value from "callerPrincipal.getName()".

2.There will not be an entry in the log as the code will not execute the line "log(callerPrincipal.getName());".

3 .There will be an entry in the log of "null".

4.This code will not compile as the method getCallerPrincipal() on the javax.ejb.EntityContext returns a boolean result not a reference to an instance of java.security.Principal.


Answer 2 is correct, this is the ejbActivate method of an entity bean. The container invokes the ejbActivate() method on an instance, when an instance needs to be activated to service an invocation on an existing entity object. This occurs because there is no suitable instance in the ready state to service the client's call. The getCallerPrincipal() method returns the java.security.Principal that identifies the invoker of the bean instance's EJB object. When ejbActivate() is invoked in an entity bean there is no client (the bean is not associated with the client at this point), this means that the Container cannot return a Principal. Instead a java.lang.IllegalStateException will be thrown by the Container so the code will go into the catch block.


My View: ejbActivate() is called when a client make a call on business method. so on that time ,it's possible to get client security informations.

so,how this answer is right? Pleas explain....


http://learnertobeginner.blogspot.com/
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Are you're thinking that the ejbActivate method can only be invoked as a direct consequence of a client invoking some business methods? This is not exactly correct.

You need to be clear that ejbActivate can only be invoked by the container. A client can never get to invoke this method since its not being exposed to them at all.

Now what if my calling client is a MDB. Can you still say that you'll have a client security context? A MDB does not have any clients at all. Hence, no client security context. And if it happens to use an entity bean, there'll be no propagation of client context.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Poobhathy Kannan
Ranch Hand

Joined: May 26, 2004
Posts: 94
Thanks Lee, Now it's clear to me
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Originally posted by Poobhathy Kannan:
Thanks Lee, Now it's clear to me


No problem.

Study hard!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ejbcertificate.com question on ejbActivate()