File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Doubts regarding javabeat questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Doubts regarding javabeat questions" Watch "Doubts regarding javabeat questions" New topic
Author

Doubts regarding javabeat questions

krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
Hi,
Following are the question.
Please tell me if I am wrong.
1) Consider the following logging interceptor that is applied to a business
method 'start()' of an enterprise bean by name 'Session',
public class Logging
{
@AroundInvoke
public Object log(InvocationContext invocation) throws Exception
{
String methodName = invocation.getMethod().getName();
System.out.println("Start of the method->" + methodName);
try
{
return invocation.proceed( );
}
finally
{
System.out.println("End of the method->" + methodName);
}
}
}
What will be the behavior when the statement 'invocation.proceed()' is
commented?
a. It is mandatory for any interceptor to invoke the method
'InvocationContext.proceed()', else during deployment of the bean, the EJB
container will throw an Error telling that 'Invalid interceptor class'.
b. The business method 'Session.start()' won't be invoked at all.
c. The behavior of the EJB container in the absence of the statement
'invocation.proceed()' will vary across implementations.
d. None of the above.

My reasoning: The baove code won't be compiled. so, d is the answere.

22) Which of the following statements are correct regarding Interceptors?
a. Interceptors can be applied only to Stateful session beans, they cannot be applied to
stateless session beans as well as to message-driven beans.
b. Calling a interceptor method defined on an enterprise bean is not allowed.
My reasoning: Can we call interceptor method from client or any other bean?
can we call @AroundInvoke method explicitly?


Thanks&Regards, Krishna.
SCJP1.4, SCWCD1.4, SCBCD 5.0
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Originally posted by krishna bulusu:
My reasoning: The baove code won't be compiled. so, d is the answere.


Why? I also think d) is the answer but for me everything works fine.

Originally posted by krishna bulusu:
My reasoning: Can we call interceptor method from client or any other bean?
can we call @AroundInvoke method explicitly?


How would you call it?
If the interceptor method is defined in a separate class, I cannot think of a way of getting a reference to the interceptor class. If it is defined in the bean class itself, then how would a client call it if it cannot be a business method of the bean (section 12.3 of the ejb core spec.)?

Now, there's the remote possibility of calling it from a business method of the bean like in:



But for this to work you need to define your own class that implements InvocationContext inerface (in my example MyInvocationContextStub class). Something like:


This is too complicated in my opinion and I am definitely not certain that it would work.
[ September 09, 2008: Message edited by: Sergio Tridente ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
Yes, your true.

The first question is perfectly valid. But the Java beat answer is b.
Regarding the second question what is your answer?
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Hi krishna,

Regarding the first question, I have just tried it and it works fine: the interceptor's around invoke method runs and invokes the business method.

Regarding the second one. It depends on the question. If we are asked if a client can call directly the around invoke method, then the answer is no. However, as I stated in my previous post, we can call the around invoke method explicitly from inside a business method. I tried the piece of code I posted earlier and it worked fine. That said, I don't think that was what the people that created the question were thinking about. Then, the answer would be no.
 
jQuery in Action, 2nd edition
 
subject: Doubts regarding javabeat questions