Hitachi

Cosminexus V11 アプリケーションサーバ Webサービス開発ガイド


35.3.4 Webサービス実装クラスを作成する

スケルトンクラスにWebサービスの処理を追加し,Webサービス実装クラスを作成します。ここでは,受け取った要求メッセージの内容を,日付情報とともに応答メッセージとして返す処理を追加します。

Webサービス実装クラスの作成例を次に示します。

package com.example.sample;
 
import java.util.Calendar;
import javax.jws.WebService;
 
 
@WebService(endpointInterface = "com.example.sample.TestJaxWs", targetNamespace = "http://example.com/sample", serviceName = "TestJaxWsService", portName = "testJaxWs")
public class TestJaxWsImpl {
 
    public String jaxWsTest1(String information, int count)
        throws UserDefinedException
    {
        Calendar today = Calendar.getInstance();
        StringBuffer result = new StringBuffer( 256 );
        result.append( "We've got your #" );
        result.append( new Integer( count ) );
        result.append( " message \"" );
        result.append( information );
        result.append( "\"! It's " );
        result.append( String.format( "%04d.%02d.%02d %02d:%02d:%02d", new Object[]{
            new Integer( today.get( Calendar.YEAR ) ),
            new Integer( today.get( Calendar.MONTH ) + 1 ),
            new Integer( today.get( Calendar.DAY_OF_MONTH ) ),
            new Integer( today.get( Calendar.HOUR_OF_DAY ) ),
            new Integer( today.get( Calendar.MINUTE ) ),
            new Integer( today.get( Calendar.SECOND ) ) } ) );
        result.append( " now. See ya!" );
        
        return result.toString();
    }
 
}

イタリック体になっている個所が,スケルトンに対して追加した実装です。