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

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

●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.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.namespace.QName;
import java.util.Map;
public class CountRequestClient
{
static final String targetOPName = "count";
static final String targetURN = "urn:sample-countRequest";
static final int stopTimes=10;
static final QName datatype =
new QName("http://www.w3.org/2001/XMLSchema", "long");
static void run( String targetURL )
{
try {
Service service = ServiceFactory.newInstance().createService(
new QName( "urn:sample-countRequest", "count" ));
javax.xml.rpc.Call call = service.createCall();
call.setTargetEndpointAddress(targetURL);
call.setOperationName( new QName( targetURN, targetOPName ));
call.setReturnType(datatype);
// セション情報の保持
((com.fujitsu.interstage.soapx.client.Call)call).setMaintainSession(true);
Object[] param = new Object[] {};
System.out.println( "started." );
for( int times = 1; times <= stopTimes; times++ ){
boolean succeeded;
Long resp = (Long)call.invoke( param );
succeeded = proccessResponse( resp, times);
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();
}
}
static boolean proccessResponse( Long resp, int calltimes ){
// check the response
if( resp == null ){
System.out.println( "-------- the call failed --------" );
return false;
} else {
if( resp.longValue() == calltimes ){
System.out.println( " requested " + resp + " times." );
return true;
} else {
System.out.println( "ERROR:Server called counter value("+resp+") " +
"differs from really called times(" +calltimes+")!");
return false;
}
}
}
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 );
}
} |

目次
索引
![]()
|