+

Search Tips   |   Advanced Search

 

Adjusting exception handling for EJB wrappered applications migrating from version 5 to version 6

 

Because of a change in the Java APIs for XML based Remote Procedure Call (JAX-RPC) specification, EJB applications that could be wrappered in WAS version 5.1 cannot be wrappered in version 6 unless you modify the code to the exception handling of the base EJB application.

 

Overview

Essentially, 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.

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

 

Procedure

  1. Modify your applications that use service specific exceptions. For example, say that your 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 your application with Web services in WAS version 6, change the UserException class . In this example, you 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. You 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());   }