• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Doubts regarding javabeat questions

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic