ここでは、サンプルアプリケーションをアプリケーションサービス機能のサービスとして統合するまでの流れとソースコードについて説明します。サンプルアプリケーション全体のソースコードについては添付のソースコードを参照してください。また、本アプリケーションでは、発生した例外は呼び出し元で取得しています。アプリケーション作成の際は、各処理に応じて適した例外処理を行うようにしてください。
Interstage Studio Java EEの起動
Interstage Studio Java EEを起動します。
プロジェクトの作成
アプリケーションサービス機能のサービスとして公開するプロジェクトを開きます。
統合するアプリケーションを”ExampleApp”としています。
インテグレーションパックのライブラリの追加
インテグレーションパックのライブラリ(jarファイル)を ”ExampleApp”プロジェクトに追加します。
fujitsu-bss-integration-pack\apis\platform\lib fujitsu-bss-extsvc-platform.jar fujitsu-bss-integration-pack\apis\provisioning\lib fujitsu-bss-extsvc-provisioning.jar
WebContent\WEB-INF\lib fujitsu-bss-extsvc-provisioning.jar fujitsu-bss-extsvc-platform.jar
プロビジョニングサービスの実装
プロビジョニングサービスを実装するクラスを追加します。
プロビジョニングサービスAPI「com.fujitsu.bss.intf.ProvisioningService#createInstance」の実装例です。
package example.server; import java.util.List; import javax.jws.WebService; import com.fujitsu.bss.provisioning.data.BaseResult; import com.fujitsu.bss.provisioning.data.InstanceInfo; import com.fujitsu.bss.provisioning.data.InstanceRequest; import com.fujitsu.bss.provisioning.data.InstanceResult; import com.fujitsu.bss.provisioning.data.ServiceParameter; import com.fujitsu.bss.provisioning.data.User; import com.fujitsu.bss.provisioning.data.UserResult; import com.fujitsu.bss.provisioning.intf.ProvisioningService; @WebService(serviceName = "ProvisioningService", targetNamespace = "http://bss.fujitsu.com/xsd/v1.1", portName = "StubServicePort", endpointInterface = "com.fujitsu.bss.provisioning.intf.ProvisioningService") public class ProvisioningServiceImpl implements ProvisioningService { private static final int RETURN_CODE_OK = 0; public InstanceResult createInstance(InstanceRequest request) { InstanceInfo instance = new InstanceInfo(); instance.setInstanceId(request.getSubscriptionId()); instance.setAccessInfo(null); InstanceResult result = new InstanceResult(); result.setInstance(instance); result.setRc(RETURN_CODE_OK); result.setDesc("Ok"); return result; } }
ログイン・ログアウトの実装
詳細は、付録C ログイン・ログアウトの実装 を参照してください。
Integrationhelperファイルのコピー
Integrationhelper.warおよびIntegrationhelperSRC.zipを解凍し、ファイルを “ExampleApp”プロジェクトに追加します。“resource”フォルダをプロジェクトのビルドパスに追加します。
Integrationhelper.war\WEB-INF\classes commons-logging.properties simplelog.properties tokenhandler.properties IntegrationhelperSRC\com\fujitsu\bes\integrationhelper BssClient.java ConnectionInfo.java Constants.java LogoutListener.java PortFactory.java TokenhandlerServlet.java Integrationhelper.war\WEB-INF\lib commons-httpclient-3.1.jar commons-logging-1.1.1.jar
resource commons-logging.properties simplelog.properties tokenhandler.properties src\com\fujitsu\bes\integrationhelper BssClient.java ConnectionInfo.java Constants.java LogoutListener.java PortFactory.java TokenhandlerServlet.java WebContent\WEB-INF\lib commons-httpclient-3.1.jar commons-logging-1.1.1.jar
Tokenhandler.propertiesの編集
Tokenhandler.proertiesのプロパティを環境に合わせて修正します。
#specify the service wsdl url TOKENHANDLER_BSS_HOST=http://192.168.11.22:8080/SessionService/v1.1/BASIC?wsdl #if basic auth should be used specify the user id TOKENHANDLER_BSS_USER=1000 #if basic auth should be used specify the password TOKENHANDLER_BSS_PWD=admin123 # this path will be used as a target after the token resolution TOKENHANDLER_FORWARD=/AutoLogin
カスタムログインモジュールの実装
カスタムログインモジュールを実装します。
この実装例では、クライアントからのGET要求とPOST要求を"menu.jsp"に転送しています。
package example.servlets; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class AutoLoginServlet extends HttpServlet { public AutoLoginServlet() { super(); } protected void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher rd = request.getRequestDispatcher("menu.jsp"); rd.forward(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { process(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { process(request, response); } }
イベントサービスのクライアントの実装
イベントサービスのクライアントを実装するクラスを追加します。
イベントサービスAPI 「com.fujitsu.bss.intf.EventService#recordEventForSubscription」の実装例です。
package example.client; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.BindingProvider; import javax.xml.ws.Service; import com.fujitsu.bss.intf.EventService; import com.fujitsu.bss.types.exceptions.DuplicateEventException; import com.fujitsu.bss.types.exceptions.ObjectNotFoundException; import com.fujitsu.bss.types.exceptions.OrganizationAuthoritiesException; import com.fujitsu.bss.types.exceptions.ValidationException; import com.fujitsu.bss.vo.VOGatheredEvent; public class EventClient { public void recordEvent(long subscriptionKey, String eventId, String actor, long multiplier) throws MalformedURLException, ObjectNotFoundException, DuplicateEventException, OrganizationAuthoritiesException, ValidationException, IOException { EventService eventService = PortFactory.getPort(ConnectionInfo.create(), EventService.class); VOGatheredEvent event = new VOGatheredEvent(); event.setActor(actor); event.setEventId(eventId); event.setMultiplier(multiplier); event.setOccurrenceTime(System.currentTimeMillis()); eventService.recordEventForSubscription(subscriptionKey, event); } }
IntegrationhelperのPortFactoryクラスのカスタマイズ
PortFactoryクラスはtokenhandler.propertiesに設定されたSessionServiceのWSDLに接続しています。
これをEventServiceのWSDLに接続できるようにカスタマイズします。PortFactory.javaの38行目を以下のように修正します。
URL wsdlLocation = new URL(info.getWsdlUrl());
String wsdlUrl = info.getWsdlUrl(); wsdlUrl = wsdlUrl.replace("SessionService", serviceName); URL wsdlLocation = new URL(wsdlUrl);
イベント生成およびログアウト処理の実装
イベント生成およびログアウト処理をアプリケーションに実装します。
この実装例では、イベントの生成およびログアウト処理を行うためにServletを使用します。イベント、ログアウトをHttpParameterの”button”で取得し、Servletに6.で作成したイベントサービスを呼び出す処理、Integrationhelperクラスのログアウトを呼び出す処理を実行しています。
package example.servlets; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.fujitsu.bes.integrationhelper.BssClient; import example.client.EventClient; public class ExampleServlet extends HttpServlet { public ExampleServlet() { super(); } protected void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); String cmd = request.getParameter("button"); if (cmd != null) { // ログアウト if (cmd.equals("logout")) { String logoutPath = BssClient.logoutUser(session); response.sendRedirect(logoutPath); session.invalidate(); return; } // イベント if (cmd.equals("event1") || cmd.equals("event2")) { String eventId = null; if (cmd.equals("event1")) { eventId = "TEST_EVENT1"; } else if (cmd.equals("event2")) { eventId = "TEST_EVENT2"; } try { String subKey = (String) session.getAttribute("subKey"); String userId = (String) session.getAttribute("userid"); long subscriptionKey = Long.parseLong(subKey); String actor = userId; long multiplier = 1; EventClient eventClient = new EventClient(); eventClient.recordEvent(subscriptionKey, eventId, actor, multiplier); } catch (Exception e) { e.printStackTrace(); } } } RequestDispatcher rd = request.getRequestDispatcher("menu.jsp"); rd.forward(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { process(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { process(request, response); } }
定義ファイルへの追加
以下の定義をデプロイメント記述子(web.xml)に追加します。
トークンハンドラ
ログアウトリスナー
カスタムログインモジュール
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>ExampleApp</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>login.jsp</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>ExampleServlet</display-name> <servlet-name>ExampleServlet</servlet-name> <servlet-class>example.servlets.ExampleServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>ExampleServlet</servlet-name> <url-pattern>/ExampleServlet</url-pattern> </servlet-mapping> <!--トークンハンドラ --> <servlet> <display-name>TokenhandlerServlet</display-name> <servlet-name>TokenhandlerServlet</servlet-name> <servlet-class>com.fujitsu.bes.integrationhelper.TokenhandlerServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TokenhandlerServlet</servlet-name> <url-pattern>/resolveToken</url-pattern> </servlet-mapping> <!-- ログアウトリスナー --> <listener> <listener-class>com.fujitsu.bes.integrationhelper.LogoutListener</listener-class> </listener> <!-- カスタムログインモジュール --> <servlet> <description></description> <display-name>AutoLoginServlet</display-name> <servlet-name>AutoLoginServlet</servlet-name> <servlet-class>example.servlets.AutoLoginServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>AutoLoginServlet</servlet-name> <url-pattern>/AutoLogin</url-pattern> </servlet-mapping> </web-app>
アプリケーションのビルド
プロジェクトのビルドを実行し、warファイルを作成します。
アプリケーションの配備
Interstage Java EE管理コンソールを開きます。
[アプリケーション] > [Webアプリケーション] を選択します。
[配備…]をクリックします。
テクニカルサービスの登録
テクノロジープロバイダーとしてアプリケーションサービス機能の管理画面へログインします。
[テクニカルサービス] > [テクニカルサービスの登録]を選択します。
以下の情報を入力し、[保存]ボタンをクリックします。サービスおよびプロビジョニングのURLは、サンプルアプリケーションを動作させている環境に合わせて修正してください。
テクニカルサービス名 :Example バージョン :1.0 アクセス種別 :プラットフォームアクセス サービスURL :http://192.168.11.22:8080/ExampleApp プロビジョニングURL :http://192.168.11.22:8080/ExampleApp/Services/ProvisioningService?wsdl
[テクニカルサービス] > [テクニカルサービスのエクスポート]を選択します。
テクニカルサービス名“Example”をチェックし、[エクスポート]ボタンをクリックします。
3.でエクスポートしたテクニカルサービスXMLファイルを編集し、イベントを追加します。
<?xml version="1.0" encoding="UTF-8"?>
<TechnicalServices xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../fujitsu-adm-um-serviceprovisioning/javares/TechnicalServices.xsd">
<TechnicalService accessType="PLATFORM" baseUrl="http://192.168.11.22:8080/exampleApp"
build="" descriptionUrl="" id="Example"
loginPath="/resolveToken" provisioningType="SYNCHRONOUS"
provisioningUrl="http:// 192.168.11.22:8080/exampleApp/services/ProvisioningService?wsdl"
provisioningVersion="" version="1.0">
<AccessInfo locale="ja"/>
<LocalizedDescription locale="ja"/>
<LocalizedLicense locale="ja"/>
<Event id="TEST_EVENT1">
<LocalizedDescription locale="ja">
Event1
</LocalizedDescription>
</Event>
<Event id="TEST_EVENT2">
<LocalizedDescription locale="ja">
Event2
</LocalizedDescription>
</Event>
</TechnicalService>
</TechnicalServices>
[テクニカルサービス] > [テクニカルサービスのエクスポート]を選択します。
4.で作成したテクニカルサービスXMLを参照し、[インポート]ボタンをクリックします。
このあと、サプライヤーが「サービス仕様の作成」、「価格モデルの設定」、「サービスの公開」を行います。
操作方法については、“アプリケーションサービス機能 運用ガイド 管理者編 第5章サプライヤー”の操作を参照してください。