It is true that the EJB specs mentions clearly the responsabilities of
each player in the EJB architecture. I am talking here from the point of
view of a Bean developer. As a Bean developer, one of my
responsabilities is making sure that (in my words):
The exceptions thrown by my EJB bean is a subset of the exceptions
thrown by
its remote interface.
I assume that as my responsability and that is why I have read the EJB
spec and tried to be careful. However, I have found (even in EJB demos
of some to-be-sold EJB products) that other developers have made already
a mistake about this. I am not saying that they have not been
responsible. EJB is there to help in time to market and there is a lot
of pressure for everybody. I am sure that I will make similar mistakes
in the future and that will be more certain when the EJB spec changes
and I work with EJB 2.0 just as I do with EJB 1.0 without much time to
read the specs in detail and review my "way of doing things". Morever,
the company that did such demo is doing a very good job apart from those
"small" mistakes (indeed, it is just a demo that I am sure they will
correct very soon).
We have written an example in Weblogic to check that weblogic.ejbc does
not check for that EJB compliency about Exceptions. Weblogic is now one
of the most important EJB vendors and is a good example of "they don't
need to add this feature but it would be helpful for all of us". Here is
my example:
In class myPackage.server.PartyMgrBean (my EJBean), one of the business
methods is:
public IParty[] getAllParties() throws Exception // should be
AccessPartyException.
{
_log("getAllParties() called");
throw new Exception
("Deliberately thrown to check that Weblogic does not check
for " +
"EJB compliency in exception handling. The remote interface
throws " +
"AccessPartyException and the bean throws just an
Exception");
} // end getAllParties
and in class myPackage.interfaces.PartyMgr (the remote interface of
PartyMgrBean):
public IParty[] getAllParties ()
throws AccessPartyException, RemoteException;
Note that Exception (thrown in PartyMgrBean.getAllParties) is not in the
union of AccessPartyException + RemoteException.
I have built the program and nothing told me that there was anything
wrong with that. The EJB compiler finished without any particular
message to make me think about it.
When I ran my client, I got the following output in my client window:
==== Begin output
java myPackage.client.Client
myPackage.client.Client: Creating a party manager...
myPackage.client.Client: Obtaining all the parties in the system...
java.rmi.RemoteException: Unexpected error in
myPackage.server.PartyMgrBean.getAllParties(). Transaction rolled back.
java.lang.Exception: Deliberately thrown to check that Weblogic does
not check for EJB compliency in exception handling. The remote interface
throws AccessPartyException and the bean throws just an Exception
at
myPackage.server.PartyMgrBean.getAllParties(PartyMgrBean.java:110)
at
myPackage.server.PartyMgrBeanEOImpl.getAllParties(PartyMgrBeanEOImpl.java:35)
at
myPackage.interfaces.Skel5t14122r5o1q253v3g2o222f1v4q481s.execute(Skel5t14122r5o1q253v3g2o222f1v4q481s.java:66)
at
weblogic.rmi.t3client.internal.RMIProxy.execute(RMIProxy.java:128)
at
weblogic.t3.srvr.ExecutableSrvrMsg.execute(ExecutableSrvrMsg.java:206)
at weblogic.t3.srvr.ExecuteThread.run(Compiled Code)
; nested exception is:
java.lang.Exception: Deliberately thrown to check that Weblogic
does not check for EJB compliency in exception handling. The remote
interface throws AccessPartyException and the bean throws just an
Exception
==== end output
Therefore, even if it is not mandatory in the specs, I think it is
highly recommended for EJB community to have available a set of tools to
check code to make sure that it is EJB complient. It may seem not very
important but I can see exceptions happening once every two years and
trigering that Exception that "of course" is not caught by the client
and hence kills it without further control. Who should be writing this
code?
* I have considered doing it myself in the framework of a larger
environment that I may use to speed up my development. However, I would
not suggest every<<busy>>body doing this. I am not so sure I will be
able to do it neither.
* Each vendor may provide tools to do that. Alternatively, some of
them may be integrated in tools like the EJB compiler (e.g.
weblogic.ejbc).
* For the most important ones, the same ones are available for free
either from
* Sun Microsystems (if they manage to do everything)
* an independent consortium of EJB vendors
* as freeware, something like GNU's Emacs and JDE to give an
example.
QUESTIONS:
* Should it be considered a responsability of an "EJB container
provider"?
* Have you implemented any tool like that?
* Is there any proposal or free software already available?
* Is there any "public" discussion about this?
* Do you know of any vendor that implemented it already?
Cheers,
Javier Deniz
Future State Technology
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".