Java™ APIs for XML based Remote Procedure Call (JAX-RPC) 仕様の変更のため、WebSphere® Application Server バージョン 5.1 にラップできた Enterprise JavaBeans (EJB) アプリケーションは、基本 EJB アプリケーションの例外処理のコードを変更しない限り、バージョン 9.0 でラップできません。
このタスクについて
JAX-RPC バージョン 1.1 仕様は、以下のように規定しています。
リモート・メソッド・シグニチャーで宣言されるサービス固有の例外は、
チェックあり例外である必要があります。java.lang.Exception を直接的または間接的に拡張する必要がありますが、
RuntimeException であってはなりません。
java.lang.Exception タイプまたは java.lang.Throwable タイプを直接使用することができなくなりました。仕様に準拠させるには、
サービス固有の例外を使用するアプリケーションを変更する必要があります。
手順
- サービス固有の例外を使用するアプリケーションを変更します。 例えば、既存の EJB が
UserException と呼ばれるサービス固有の例外を使用しているとします。UserException 内には、java.lang.Exception タイプの ex と
呼ばれるフィールドがあります。WebSphere Application Server バージョン 9.0 で Web サービスを使用してアプリケーションを正常にラップするには、UserException クラスを変更する必要があります。この例では、UserException を変更して、
ex のタイプを java.lang.Exception ではなく java.lang.String にすることが可能です。
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);
}
}
- 例外処理を使用するエンタープライズ Bean ですべての例外処理を変更します。 エンタープライズ Bean が新規例外を受け入れるようコード化されていることを確認する必要があります。
この例では、コードは以下のようになります。
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());
}