• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Exceptions

 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the remote client does not extend Remote, will the client get RemoteException? or rather in what cases the client will get remote exception.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think whether client get RemoteException is not determined by client implement Remote or not,is determined by if the business method is remote and did it implement Remote interface(please reference master ejb3 eppendix E,too long to refer here)
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anu Tilwalli,

In EJB2, the remote interface of a Session Bean implements java.rmi.Remote and all the methods must throw the java.rmi.RemoteException.
So, a remote client of an EJB2 Session Bean will possibly get a java.rmi.RemoteException.

In EJB3, a remote business interface must not implement java.rmi.Remote.
And the throws clauses should not include the java.rmi.RemoteException.
So, a remote client of an EJB3 Session Bean will never get java.rmi.RemoteException.

Hope it helps,

Beno�t
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But in some of the books it says that the container wraps the exception into RemoteException for remote clients.
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the specs

1. For MDB, Other beans it throws javax.ejb.EJBException
2. For webservice client it throws javax.rmi.RemoteException
3. For EJB 2.1 Client
throws RemoteException if its remote client
throws EJBException if its local client
4. Throws EJB 3.0 Client
If the remote extends java.rmi.REMOTE remote exception in thrown.
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If bean method runs in the transaction started by the container[Required or Require New]

If any application exception is raised

Containers Action
1. Should rethrow the app exception
2. If instance calls setRollBack, then rollback or do rollback depending up @ApplicationAnnotation type & rethrow the exception.

Client View
1. Receive application exception
1. If the client executes in a transaction, the client transaction is not marked for roll back

Would the transaction is still not marked for rollback if the client initiated the transaction. I mean if the client had initiated, the transaction would have been propogated to the bean method[In case of Required].

The exception chart in the spec is a bit confusing.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what i understand this is the rule

[ April 03, 2008: Message edited by: Derick Potgieter ]
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I thought. But if you the see the spec, it says that this would happen only if the remote interface implements Remote. But when I tried this, I always got EJBException.

Any thoughts on it?
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I thought. But if you the see the spec, it says that this would happen only if the remote interface implements Remote. But when I tried this, I always got EJBException.

Any thoughts on it?
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i read from Manning book EJB 3 in Action
page 88 about the Remote business interface.

A remote business interface may extend java.rmi.Remote as we�ve done here,
although this is optional. Typically the container will perform byte-code enhancements during deployment to extend java.rmi.Remote if your bean interface does not extend it. Remote business interface methods are not required to throw java.rmi.RemoteException unless the business interface extends the java.rmi.Remote interface.



Is that mean if I explicit extends the Remote business interface with java.rmi.RemoteExcepton , client will get RemoteException instead of EJBException ?
[ July 04, 2008: Message edited by: Witt Lilavivat ]
 
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
Accordingly to O'reilly's book (page 397):


System exceptions include java.lang.RuntimeException and its subclasses. EJBException is a subclass of RuntimeException, so it is considered a system exception. System exceptions also include java.rmi.RemoteException and its subclasses. The RuntimeException and RemoteException subclasses differ in that they can be turned into application exceptions using the @javax.ejb.ApplicationException annotation.



Later in the same chapter (page 399):


In session beans, when a system exception occurs and the instance is discarded, a RuntimeException is always thrown whether the client is a remote or local invocation. If the client started the transaction, which was then propagated to the EJB, a system exception (thrown by the enterprise bean method) will be caught by the container and rethrown as a javax.ejb.EJBTransactionRolledbackException. EJBTransactionRolledbackException is a subtype of RuntimeException and gives a more explicit indication to the client that a rollback occurred. If the client did not propagate a transaction to the EJB, the system exception will be caught and rethrown as an EJBException.



I think this explains well why Anu was always getting an EJBException: the RemoteException is caught and rethwon as a EJBException (or an EJBTransactionRolledbackException if the transactions originated from the client).
 
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
After reading the relevant chapter in the spces, I am taking back what I wrote: there is something wrong with O'Reilly's book regarding RemoteException.

I did some tests on JBoss 4.2.2GA and this is what I got:

Case 1: no transaction on client, EJB initiated transaction
- When the business method throws a java.lang.Exception, the client receives a java.lang.Exception
- When the business method throws a java.lang.RuntimeException, the client receives a javax.ejb.EJBException
- When the business method throws a java.lang.ArithmeticException (subclass of RuntimeException), the client receives a javax.ejb.EJBException
- When the business method throws a java.rmi.RemoteException, the client receives a java.rmi.RemoteException
- When the business method throws a java.rmi.ServerException (subclass of RemoteException), the client receives a java.rmi.ServerException

Case 2: client initiated transaction propagated to the EJB
- When the business method throws a java.lang.Exception, the client receives a java.lang.Exception
- When the business method throws a java.lang.RuntimeException, the client receives a javax.ejb.EJBTransactionRolledbackException
- When the business method throws a java.lang.ArithmeticException, the client receives a javax.ejb.EJBTransactionRolledbackException
- When the business method throws a java.rmi.RemoteException, the client receives a javax.ejb.EJBTransactionRolledbackException
- When the business method throws a java.rmi.ServerException, the client receives a javax.ejb.EJBTransactionRolledbackException

Case 3: client initiated transaction that does not propagate to the client (TransactionAttributeType.NOT_SUPPORTED)
- When the business method throws a java.lang.Exception, the client receives a java.lang.Exception
- When the business method throws a java.lang.RuntimeException, the client receives a java.lang.RuntimeException
- When the business method throws a java.lang.ArithmeticException, the client receives a java.lang.ArithmeticException
- When the business method throws a java.rmi.RemoteException, the client receives a java.rmi.RemoteException
- When the business method throws a java.rmi.ServerException, the client receives a java.rmi.ServerException

This does not follow what the ejb-core specs say. I guess it is a problem with JBoss. I will install Glassfish anf try it again. I will post back the results.
[ July 06, 2008: Message edited by: Sergio Tridente ]
 
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
I tried the same three cases in Glassfish. Here are the results:

Case 1: no transaction on client, EJB initiated transaction
- When the business method throws a java.lang.Exception, the client receives a java.lang.Exception
- When the business method throws a java.lang.RuntimeException, the client receives a java.rmi.ServerException
- When the business method throws a java.lang.ArithmeticException (subclass of RuntimeException), the client receives a java.rmi.ServerException
- When the business method throws a java.rmi.RemoteException, the client receives a java.rmi.ServerException
- When the business method throws a java.rmi.ServerException (subclass of RemoteException), the client receives a java.rmi.ServerException

Case 2: client initiated transaction propagated to the EJB
- When the business method throws a java.lang.Exception, the client receives a java.lang.Exception
- When the business method throws a java.lang.RuntimeException, the client receives a javax.transaction.TransactionRolledbackException
- When the business method throws a java.lang.ArithmeticException, the client receives a javax.transaction.TransactionRolledbackException
- When the business method throws a java.rmi.RemoteException, the client receives a javax.transaction.TransactionRolledbackException
- When the business method throws a java.rmi.ServerException, the client receives a javax.transaction.TransactionRolledbackException

Case 3: client initiated transaction that does not propagate to the client (TransactionAttributeType.NOT_SUPPORTED)
- When the business method throws a java.lang.Exception, the client receives a java.lang.Exception
- When the business method throws a java.lang.RuntimeException, the client receives a java.rmi.ServerException
- When the business method throws a java.lang.ArithmeticException, the client receives a java.rmi.ServerException
- When the business method throws a java.rmi.RemoteException, the client receives a java.rmi.ServerException
- When the business method throws a java.rmi.ServerException, the client receives a java.rmi.ServerException

This definitely works more like what's written in the specifications. It looks like a Jboss problem to me.
[ July 06, 2008: Message edited by: Sergio Tridente ]
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get remote Exception for the remote client only when the bean method throws Remote Exception.

But in spec & in many mocks, it says that if its a remote client it should throw remote exception.

Which is correct?
 
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
The specs, of course. As I said, it works fine on Glassfish: it throws ServerException, which is a subclass of RemoteException, when the Bean's interface extends Remote. But it throws EJBException when it does not extend Remote, even if it is annotated with @Remote.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic