| Interstage Application Server SOAPサービス ユーザーズガイド |
目次
索引
![]()
|
| 第5章 RPC方式のアプリケーションの実装 | > 5.4 スタブ方式によるRPCクライアントアプリケーション |
セション管理を行う場合は、ユーザスタブクラスをcom.fujitsu.interstage.soapx.client.Stubクラスにキャストし、以下のメソッドを使用してセション情報を保持することで、セションを利用できます。
●パッケージ名:com.fujitsu.interstage.soapx.client
|
クラス名 |
メソッド |
説明 |
|---|---|---|
|
Stub |
public void |
HTTPセション継続を行うかどうかを設定します。 |

スタブオブジェクトを、com.fujitsu.interstage.soapx.client.Stubクラスにキャストし、setMaintainSessionメソッドをパラメタに"true"を指定して呼び出すことで、スタブオブジェクトはセション管理の情報を保持するように設定されます。
セション管理の情報を保持するように設定されたスタブオブジェクトを使用してRPCサーバアプリケーションを呼び出すことで、セションを継続できます。
com.fujitsu.interstage.soapx.client.Stub.setMaintainSessionメソッドを、パラメタに"false"を指定して呼び出した場合、このcom.fujitsu.interstage.soapx.client.Stubクラスのインスタンスはセション管理の情報を破棄し、セションは継続されなくなります。

●RPCサーバアプリケーション
//
//RPCサーバアプリケーション
//
import java.rmi.RemoteException;
/*
* <code>CountRequestServer</code>
* Deploy this with 'Session' scope
*/
public class CountRequestServer implements CountIf
{
private long n= 0;
/*
* return the number of requested times in the session.
* @return number of the requested times in the session.
*/
public long count() throws RemoteException
{
this.n++;
return this.n;
}
} |
●RPCクライアントアプリケーション
//
//RPCクライアントアプリケーション
//
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.Detail;
import com.fujitsu.interstage.soapx.client.Stub;
import java.util.Iterator;
public class CountRequestClient
{
static final int stopTimes=10;
static void run( String targetURL )
{
try {
QName serviceQName = new QName(
"urn: sample-count-request ", "CountRequestService" );
ServiceFactory factory = ServiceFactory.newInstance();
CountRequestServiceLocator locator = (CountRequestServiceLocator)
factory.createService(serviceQName);
CountRequest target = locator.getCountRequestPort();
// セション情報の保持
((Stub)target).setMaintainSession(true);
System.out.println( "started." );
for( int times = 1; times <= stopTimes; times++ ){
boolean succeeded;
try{
long rettimes = target.count();
if( times != rettimes ){
succeeded = false;
}
succeeded = true;
} catch(SOAPException se) {
System.out.println("SOAPException throwed.");
System.out.println(se);
succeeded = false;
}
if( !succeeded ){
System.out.println("Call failed ! called " + times +
" times. (last one may be trying only)");
break;
}
}
System.out.println("ended.");
} catch( javax.xml.rpc.ServiceException e ) {
e.printStackTrace();
if( e.getLinkedCause() != null ) {
e.getLinkedCause().printStackTrace();
}
} catch( javax.xml.rpc.soap.SOAPFaultException e ) {
e.printStackTrace();
System.out.println(" Code = " + e.getFaultCode());
System.out.println(" String = " + e.getFaultString());
System.out.println(" Actor = " + e.getFaultActor());
if( e.getDetail() != null ) {
Detail detail = e.getDetail();
Iterator it = detail.getDetailEntries();
if( it != null ) {
while(it.hasNext()) {
SOAPElement elm = (SOAPElement)it.next();
System.out.println(" Detail = " + elm);
}
}
}
} catch( javax.xml.rpc.JAXRPCException e ) {
e.printStackTrace();
if( e.getLinkedCause() != null ) {
e.getLinkedCause().printStackTrace();
}
} catch( java.rmi.RemoteException e ) {
e.printStackTrace();
if( e.detail != null ) {
e.detail.printStackTrace();
}
} catch( Throwable e ) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception{
if(args.length<1){
System.out.println("Usage: java CountRequestClient <RPC router's URL>");
System.exit(1);
}
String targetURL = args[0];
run( targetURL );
}
} |

目次
索引
![]()
|