+

Search Tips   |   Advanced Search

Adjusting exception handling for EJB wrapped applications migrating from Version 5 to v8.5

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 v8.5 unless you 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.

  1. Modify the applications that use service specific exceptions. For example, say that the 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 WebSphere Application Server v8.5, you must 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. We must ensure that the 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());
       }