+

Search Tips   |   Advanced Search

Adjusting exception handling for EJB wrapped applications migrating from v5 to v9.0

Because of a change in the Java APIs for XML based Remote Procedure Call (JAX-RPC) specification, EJB applications that could be wrapped in WebSphere Application Server Version 5.1 cannot be wrapped in v9.0 unless we modify the code to the exception handling of the base EJB application.

The JAX-RPC Version 1.1 specification states:

a service specific exception declared in a remote method signature must be a checked exception. It must extend java.lang.Exception either directly or indirectly but it must not be a RuntimeException.

It is no longer possible to directly use java.lang.Exception or java.lang.Throwable types. We must modify the applications using service specific exceptions to comply with the specification.


Tasks

  1. Modify the applications that use service specific exceptions. For example, say that our existing EJB uses a service specific exception called UserException. Inside of UserException is a field called ex that is type java.lang.Exception. To successfully wrapper the application with web services in WAS v9.0, change the UserException class. In this example, we could modify UserException to make the type of ex to be java.lang.String instead of java.lang.Exception.
    new UserException class:
    
    package irwwbase;
    
    /**
     * Insert the type's description here.
     * Creation date: (9/25/00 2:25:18 PM)
     * @author: Administrator
     */
    
    
    public class UserException extends java.lang.Exception {
    
           private java.lang.String _infostring = null;
           private java.lang.String ex;
    /**
     * UserException constructor comment.
     */
    
    public UserException() {
           super();
    }
    /**
     * UserException constructor comment.
     */
    public UserException (String infostring)
    {
           _infostring = infostring;
    } // ctor
    /**
     * Insert the method's description here.
     * Creation date: (11/29/2001 9:25:50 AM)
     * @param msg java.lang.String
     * @param ex java.lang.Exception
     */
    public UserException(String msg,String t) {
           super(msg);
           this.setEx(t);
           
           }
           /**
            * @return
            */
           public java.lang.String get_infostring() {
                  return _infostring;
           }
    
           /**
            * @return
            */
           public java.lang.String getEx() {
                  return ex;
           }
    
           /**
            * @param string
            */
           public void set_infostring(java.lang.String string) {
                  _infostring = string;
           }
    
           /**
            * @param Exception
            */
           public void setEx(java.lang.String exception) {
                  ex = exception;
           }
           
           public void printStackTrace(java.io.PrintWriter s) {  
             System.out.println("the exception is :"+ex);       
             }
    
    }
    

  2. Modify all of the exception handling in the enterprise beans that use it. We must ensure that your enterprise beans are coded to accept the new exceptions. In this example, the code might look like this:
    new EJB exception handling:
    
    try {
          if (isDistributed()) itemCMPEntity = itemCMPEntityHome.findByPrimaryKey(ckey);
          else itemCMPEntityLocal = itemCMPEntityLocalHome.findByPrimaryKey(ckey);
      } catch (Exception ex) {
           System.out.println("%%%%% ERROR: getItemInstance - CMPjdbc " + _className);
           ex.printStackTrace();
           throw new UserException("error on itemCMPEntityHome.findByPrimaryKey(ckey)",ex.getMessage());
       }