File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes whizlabs question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "whizlabs question." Watch "whizlabs question." New topic

whizlabs question.

mallika shah
Ranch Hand

Joined: May 11, 2006
Posts: 164
hello ,

here is one question:

A client send a message to a queue.The MDB calls the MessageDrivenContext.getCallerPrincipal() upon receiving the message.what will be the return value of this method execution?
1. It will return the principal object associated with the client sending the message
2.It will return the value of security role defied for the method.
3. It will throw a runtime Exception
4. It will return a null value.

Whats the correct ans..please explain
I answered 1.
But whizlabs says its 3.

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

As far as MDB are concerned, there's no client. An MDB does not know who really sent the message first, so all client related methods cannot be used. Please refer to 15.4.3 The MessageDrivenContext interface in the specification. Also, this method never returns null, so you can also discard number 4.

[My Blog]
All roads lead to JavaRanch
mallika shah
Ranch Hand

Joined: May 11, 2006
Posts: 164
Thanks Christophe..

Got your point...

Napu Sun
Ranch Hand

Joined: Apr 18, 2006
Posts: 33
Invoking the getCallerPrincipal and isCallerInRole methods is disallowed in
the message-driven bean methods because the Container does not have a client security context.
The Container must throw and log the java.lang.IllegalStateException if
either of these methods is invoked.

Please refer to Specification 15.5.1
I agree. Here's the link:
subject: whizlabs question.
It's not a secret anymore!