About Question enthuware.oce-ejbd.v6.2.551 : Subclasses of exceptions in throws clause of @AroundInvoke method

Moderator: admin

Post Reply
dstmailinator
Posts: 1
Joined: Tue Oct 15, 2013 1:19 am
Contact:

About Question enthuware.oce-ejbd.v6.2.551 : Subclasses of exceptions in throws clause of @AroundInvoke method

Post by dstmailinator »

Description of one of the wrong answers is:
The signature of @AroundInvoke method must have "throws Exception" part. This is required.
However in question enthuware.oce-ejbd.v6.2.519 there's such a code snippet:

Code: Select all

@AroundInvoke
public Object myAround(InvocationContext ic) throws NoAccountException
EJB 3.1 specification says:
Business method interceptor methods may throw runtime exceptions or application exceptions that are allowed in the throws clause of the business method.
However Java EE 6 API gives the following signature for an interceptor method:

Code: Select all

@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception { ... }
I tested on Weblogic, that subclasses of Exception in throws clause of an interceptor method are not valid. There's an error during deployment.
weblogic.ejb.container.compliance.ComplianceException: AroundInvoke method myInterceptor in class oce.ejbd.MySLSInterceptor must have the signature: 'Object <METHOD(InvocationContext)> throws Exception'
That's why I think that either Java EE 6 API is inaccurate (should allow Exception subclasses) or you shouldn't use signature with "throws NoAccountException" and say that "throws Exception" is required in another place, if it's not clear what is really compatible with specification.

Online
admin
Site Admin
Posts: 8943
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.551 : Subclasses of exceptions in throws clause of @AroundInvoke method

Post by admin »

Very sorry for late reply. Required some research.

As you've quoted from EJB 3.1 specification and also given in Interceptor specification, it specifies the signature of AroundInvoke method as having "throws Exception". This makes sense because the interceptor method is permitted to throw any exception that is declared in the business method. So that is possible only if the interceptor method signature has "throws Exception".

The other question needs to be corrected.

HTH,
Paul.

-Paul.
If you like our products and services, please help us by posting your review here.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.551 : Subclasses

Post by himaiMinh »

The getBalance returns a double while myAround returns an Object.
It should have a ClassCastException during runtime.

Online
admin
Site Admin
Posts: 8943
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.551 : Subclasses

Post by admin »

No, it is ok as per Interceptor specification, Page 5: Around-invoke methods have the following signature: Object <METHOD>(InvocationContext) throws Exception
If you like our products and services, please help us by posting your review here.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.551 : Subclasses

Post by himaiMinh »

Thanks.
But in one of the questions,

Code: Select all


@AroundInvoke
 Object myAround(InvocationContext context) throws Exception{
      return new Integer(100);
 }

 public String getCode(String input){

   return "CountryCode "+ input;
 }
The explanation says it will have ClassCastException during runtime.

But in this case:

Code: Select all

@AroundInvoke
 Object myAround(InvocationContext context) throws Exception{
      return context.proceed();
 }

public double getBalance(){

   return 2.0;
 }
These return type are different, one is object, another is a double, but it works.

Online
admin
Site Admin
Posts: 8943
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.551 : Subclasses

Post by admin »

Yes, I updated that also.
As you may have noticed, sometimes the container do not follow the specification exactly.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests