WebSphere Application Server - Express for i5/OS, Version 6.1   
             オペレーティング・システム: i5/OS

             目次と検索結果のパーソナライズ化

Web Services Resource Framework ベースの障害

Web Services Resource Framework (WSRF) は推奨される基本的な障害メッセージ・エレメント・タイプを提供しており、ユーザーはここからサービス固有のすべての障害を引き出すことができます。 共通の基本タイプの利点は、デフォルトで、すべての障害が共通の情報を含むことができることです。 この振る舞いは、障害が整然とログに記録されたり、分析される前にソフトウェアの複数の層を通じて転送される複雑なシステムにおいて有益です。

共通の情報には次の項目が含まれます。
次の 2 つの標準的な障害が定義され、各 WSRF の操作で使用されます。
ResourceUnkownFault
この障害は、WS-Resource がメッセージを受信するサービスによって認識されていないことを示すのに使用します。
ResourceUnavailableFault
この障害は、Web サービスはアクティブであるが、リソースへのアクセスを提供できないことを示すのに使用します。
次の XML 断片は、基本障害エレメントの例を示します。
 <wsrf-bf:BaseFault>
    <wsrf-bf:Timestamp>2005-05-31T12:00:00.000Z</wsrf-bf:Timestamp>
    <wsrf-bf:Originator>
      <wsa:Address>
        http://www.example.org/Printer
      </wsa:Address>
      <wsa:ReferenceParameters>
        <pr:pr-id>P1</pr:pr-id>
      </wsa:ReferenceParameters>
    </wsrf-bf:Originator>
    <wsrf-bf:Description>Offline for service maintenance</wsrf-bf:Description>
    <wsrf-bf:FaultCause>OFFLINE</wsrf-bf:FaultCause>
 </wsrf-bf:BaseFault>

BaseFault クラス

WebSphere Application Server は、WSRF 仕様により定義されるすべての基本障害エレメント・タイプの Java コード・マッピングを提供し、各 Java 例外が com.ibm.websphere.wsrf.BaseFault クラスを拡張する、例外階層を形成します。 各障害クラスは同じようなパターンに従います。

例えば、BaseFault クラスは、次の 2 つのコンストラクターを定義します。
package com.ibm.websphere.wsrf;
public class BaseFault extends Exception
{
    public BaseFault()
    {
       ...
    }
    public BaseFault(EndpointReference originator,
                     ErrorCode errorCode,
                     FaultDescription[] descriptions,
                     IOSerializableSOAPElement faultCause,
                     IOSerializableSOAPElement[] extensibilityElements,
                     Attribute[] attributes)
    {
       ...
    }
    ...
}

IOSerializableSOAPElement クラス

BaseFault クラスは java.lang.Exception クラスを拡張するため、java.io.Serializable インターフェースをインプリメントする必要があります。この要件を満たすには、BaseFault インスタンスのすべてのプロパティーがシリアライズ可能である必要があります。javax.xml.soap.SOAPElement クラスはシリアライズ可能ではないため、WebSphere Application Server は IOSerializableSOAPElement クラスを提供します。このクラスを使用して javax.xml.soap.SOAPElement インスタンスをラップし、そのインスタンスのシリアライズ可能な形式を提供します。

以下のように、IOSerializableSOAPElementFactory クラスを使用して IOSerializableSOAPElement インスタンスを作成します。
 // Get an instance of the IOSerializableSOAPElementFactory class
IOSerializableSOAPElementFactory factory = IOSerializableSOAPElementFactory.newInstance();

// Create an IOSerializableSOAPElement from a javax.xml.soap.SOAPElement
IOSerializableSOAPElement serializableSOAPElement = factory.createElement(soapElement);

// You can retrieve the wrapped SOAPElement from the IOSerializableSOAPElement
SOAPElement soapElement = serializableSOAPElement.getSOAPElement();

すべてのアプリケーション固有の BaseFault インスタンスは、このシリアライズ可能な要件も遵守する必要があります。

アプリケーション固有の障害

アプリケーションは、BaseFault エレメントに対する独自の拡張機能を定義することができます。XML タイプの拡張機能を使用して、BaseFaultType エレメントを拡張する、アプリケーション障害についての新規 XML タイプを定義します。 例えば、次の XML の断片では新規の PrinterFaultType エレメントを作成します。
 <xsd:complexType name="PrinterFaultType">
   <xsd:complexContent>
     <xsd:extension base="wsrf-bf:BaseFaultType"/>
   	</xsd:complexContent>
 </xsd:complexType>
次の例は、印刷操作 (2 つの wsdl:fault メッセージを宣言する PrinterFault オブジェクトを作成する操作) を定義する WSDL 定義を持つ Web サービス・アプリケーションが、PrinterFault オブジェクトを作成する方法を示しています。
import com.ibm.websphere.wsrf.BaseFault;
import com.ibm.websphere.wsrf.*;
import javax.xml.soap.SOAPFactory;
...
    public void print(PrintRequest req) throws PrinterFault, ResourceUnknownFault
    {
        // Determine the identity of the target printer instance.
        PrinterState state = PrinterState.getState ();
        if (state.OFFLINE)
        {       
            try
            {      
                // Get an instance of the SOAPFactory
                SOAPFactory soapFactory = SOAPFactory.newInstance();
      
                // Create the fault cause SOAPElement
                SOAPElement faultCause = soapFactory.createElement("FaultCause");
                faultCase.addTextNode("OFFLINE");

                // Get an instance of the IOSerializableSOAPElementFactory
                IOSerializableSOAPElementFactory factory = IOSerializableSOAPElementFactory.newInstance();

                // Create an IOSerializableSOAPElement from the faultCause SOAPElement
                IOSerializableSOAPElement serializableFaultCause = factory.createElement(faultCause);

                FaultDescription[] faultDescription = new FaultDescription[1];
                faultDescription[0] = new FaultDescription("Offline for service maintenance");
                throw new PrinterFault(
                         state.getPrinterEndpointReference(),
                         null,
                         faultDescription,
                         serializableFaultCause,
                         null,
                         null);
            }
            catch (SOAPException e)
            {
               ...
            }
        }
        ...
次のコードは、基本障害階層が Java 例外階層として処理される方法を示しています。
import com.ibm.websphere.wsrf.BaseFault;
import com.ibm.websphere.wsrf.*;
...
try
{
   printer1.print(job1);
}
catch (ResourceUnknownFault exc)
{
   System.out.println("Operation threw the ResourceUnknownFault”);
}
catch (PrinterFault exc)
{
   System.out.println("Operation threw PrinterFault”);
}
catch (BaseFault exc)
{
   System.out.println("Exception is another BaseFault”);
}
catch (Exception exc)
{
   System.out.println("Exception is not a BaseFault”);
}

カスタム・バインダー

新規のアプリケーション・レベルの基本障害を定義する場合 (例えば上記に示すタイプ PrinterFaultType の PrinterFault)、ユーザーはカスタム・バインダーを提供して、Web サービス・ランタイムが Java クラスを適切な XML メッセージにシリアライズし、反対に XML メッセージを Java クラスのインスタンスにデシリアライズする方法を定義する必要があります。

カスタム・バインダーは、com.ibm.wsspi.webservices.binding.CustomBinder インターフェースをインプリメントする必要があります。 Java アーカイブ (JAR) ファイルのバインダーを、JAR ファイルの /META-INF/services ディレクトリーの宣言メタデータ・ファイル、CustomBindingProvider.xml と一緒にパッケージ化します。 このメタデータ・ファイルは、カスタム・バインダー、Java BaseFault インプリメンテーション、および BaseFault タイプ間の関係を定義します。例えば、PrinterFaultTypeBinder というカスタム・バインダーを定義して、XML PrinterFaultType エレメントとその Java インプリメンテーションである PrinterFault 間に、次のようにマップすることができます。
<customdatabinding:provider
   xmlns:customdatabinding="http://www.ibm.com/webservices/customdatabinding/2004/06"
   xmlns:pr="http://example.org/printer.xsd"
   xmlns="http://www.ibm.com/webservices/customdatabinding/2004/06">
 <mapping>
  <xmlQName>pr:PrinterFaultType</xmlQName>
  <javaName>PrinterFault</javaName>
  <qnameScope>complexType</qnameScope>
  <binder>PrinterFaultTypeBinder</binder>
 </mapping>
</customdatabinding:provider>

BaseFaultBinderHelper クラス

WebSphere Application Server は BaseFaultBinderHelper クラスを提供します。このクラスは、すべての特殊な BaseFault クラスが拡張しなければならないルート BaseFault に固有のデータを、シリアライズおよびデシリアライズするためのサポートを提供します。 カスタム・バインダーが BaseFaultBinderHelper クラスを使用する場合、カスタム・バインダーは拡張された BaseFault データをシリアライズおよびデシリアライズするための追加ロジックのみを提供する必要があります。

次のコードは、BaseFaultBinderHelper クラス・サポートを使用するために PrinterFaultType エレメントのカスタム・バインダーをインプリメントする方法を示しています。
import com.ibm.wsspi.wsrf.BaseFaultBinderHelper;
import com.ibm.wsspi.wsrf.BaseFaultBinderHelperFactory;
import com.ibm.wsspi.webservices.binding.CustomBinder;
import com.ibm.wsspi.webservices.binding.CustomBindingContext;
...
 
public PrinterFaultTypeBinder implements CustomBinder
{
   // Get an instance of the BaseFaultBinderHelper
   private BaseFaultBinderHelper baseFaultBinderHelper = BaseFaultBinderHelperFactory.getBaseFaultBinderHelper();
 
   public SOAPElement serialize(Object data, SOAPElement rootNode, CustomBindingContext context) throws SOAPException
   {
     // Serialize the BaseFault specific data
     baseFaultBinderHelper.serialize(rootNode, (BaseFault)data);
 
     // Serialize any PrinterFault specific data
     ...
 
     // Return the serialized PrinterFault
     return rootNode;
   }
 
   public Object deserialize(SOAPElement rootNode, CustomBindingContext context) throws SOAPException
   {
     // Create an instance of a PrinterFault
     PrinterFault printerFault = new PrinterFault();
 
     // Deserialize the BaseFault specific data - any additional data which
     // forms the PrinterFault extension will be returned as a SOAPElement[].
     SOAPElement[] printerFaultElements = baseFaultBinderHelper.deserialize(printerFault, rootNode);
 
     // Deserialize the PrinterFault specific data contained within the printerFaultElements SOAPElement[]
     ...
 
     // Return the deserialized PrinterFault
     return printerFault;
   }
 
  ...
 
}



関連概念
Web Services Resource Framework サポート
関連タスク
Web サービス・リソース・フレームワークを使用したステートフル Web サービスの作成
関連情報
OASIS WSRF primer
概念トピック    

ご利用条件 | フィードバック

最終更新: Jan 21, 2008 7:05:28 PM EST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.express.iseries.doc/info/iseriesexp/ae/cwbs_wsrf_basefault.html