// import文宣言
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.soap.SOAPFaultException;
import javax.xml.rpc.encoding.TypeMappingRegistry;
import javax.xml.rpc.encoding.TypeMapping;
import javax.xml.soap.Detail;
import javax.xml.soap.DetailEntry;
import javax.xml.namespace.QName;
import java.util.Iterator;
import javax.xml.soap.SOAPElement;
:
try {
:
Service service = null;
service = ServiceFactory.newInstance().createService(new QName("",""));
TypeMappingRegistry tmr = service.getTypeMappingRegistry();
TypeMapping tm = tmr.createTypeMapping();
// ユーザ定義例外 QName作成
QName _qname =
new QName( "urn:Fujitsu-Soap-Service-Data", "ODdemo-calculator-ZEROPARAM" );
// ユーザ定義例外 ZEROPARAMのマッピング登録
tm.register(ODdemo.calculatorPackage.ZEROPARAMSOAPGWType.class, _qname,
new com.fujitsu.interstage.soapx.encoding.ser.BeanSerializerFactory(
ODdemo.calculatorPackage.ZEROPARAMSOAPGWType.class, _qname),
new com.fujitsu.interstage.soapx.encoding.ser.BeanDeserializerFactory(
ODdemo.calculatorPackage.ZEROPARAMSOAPGWType.class, _qname ) );
// マッピング情報をマッピングレジストリへ登録
tmr.register( "http://schemas.xmlsoap.org/soap/encoding/", tm );
:
// メソッド呼び出し
..... = call.invoke(...);
:
} catch( javax.xml.rpc.ServiceException e ) {
:
} catch( SOAPFaultException e ) {
// Fault情報の取得
QName _faultCode = e.getFaultCode();
String _faultString = e.getFaultString();
String _faultActor = e.getFaultActor();
Detail _detail = e.getDetail();
if( _detail != null ){
// Fault詳細項目の取得
String _ex_id = null;
int _ex_major = 0;
int _ex_minor = 0;
int _ex_status = org.omg.CORBA.CompletionStatus._COMPLETED_MAYBE;
String _ex_message = null;
//CORBA例外用Faults詳細項目 QName作成
String NS_URI_CORBAException = "com.fujitsu.interstage.soap.gateway.CORBAException";
QName Q_CORBAEXCEPTION_ID = new QName( NS_URI_CORBAException, "id" );
QName Q_CORBAEXCEPTION_MAJOR =
new QName( NS_URI_CORBAException, "major" );
QName Q_CORBAEXCEPTION_MINOR =
new QName( NS_URI_CORBAException, "minor" );
QName Q_CORBAEXCEPTION_STATUS =
new QName( NS_URI_CORBAException, "status" );
QName Q_CORBAEXCEPTION_MESSAGE =
new QName( NS_URI_CORBAException, "message" );
Iterator _it = _detail.getChildElements();
if( _it != null ) {
while(_it.hasNext()) {
SOAPElement _elm = (SOAPElement)_it.next();
String _elmName = _elm.getElementName().getLocalName();
if( _elmName.equals("id")) {
_ex_id = _elm.getValue();
}
else if( _elmName.equals("major")){
_ex_major = new Integer(_elm.getValue()).intValue();
}
else if( _elmName.equals("minor")) {
_ex_minor = new Integer(_elm.getValue() ).intValue();
}
else if( _elmName.equals("status")) {
_ex_status = new Integer(_elm.getValue() ).intValue();
}
else if( _elmName.equals("message")) {
_ex_message = _elm.getValue();
}
} // while
// CORBA例外の作成
if( _ex_id != null ) {
java.lang.Object _ex_obj = null;
try {
java.lang.Class _ex_class = java.lang.Class.forName( _ex_id );
_ex_obj = _ex_class.newInstance();
} catch( java.lang.ClassNotFoundException nie ) {
: //_ex_idで示すクラスが見つからなかった場合の例外処理を記述
} catch( java.lang.InstantiationException nie ) {
: //_exクラスのインスタンスを作成できなかった場合の例外処理を記述
} catch( java.lang.IllegalAccessException nie ) {
: //_exクラスまたは_exクラスのコンストラクタにアクセス
: //できなかった場合の例外処理を記述
}
// SystemException
if( _ex_obj instanceof org.omg.CORBA.SystemException ) {
((org.omg.CORBA.SystemException)_ex_obj).minor = _ex_minor;
((org.omg.CORBA.SystemException)_ex_obj).completed =
org.omg.CORBA.CompletionStatus.from_int( _ex_status );
// 作成したCORBAシステム例外をthrowする
throw (org.omg.CORBA.SystemException)_ex_obj;
}
}
}
}
} |