ナビゲーションをスキップ

WebLogic Server 9.0 Beehive 統合ガイド

  前 次 前/次ボタンと目次ボタンとの区切り線 目次  

Beehive のチュートリアル


 

このチュートリアルでは、Beehive アプリケーションを作成し、WebLogic Server にデプロイする方法について示すとともに、
以下の 3 種類の Beehive 基本コンポーネントを作成する方法について示します。

注意 : チュートリアルを実行するのが 2 回目である場合、アプリケーションのソース ファイルの場所を変更すると同じサーバ ドメインにデプロイできなくなりますので注意してください。この問題を回避するには、(1) 新しいサーバ ドメインを最初から作成するか (つまり、このチュートリアルの最初の手順から始めるか)、あるいは最初の手順をスキップする場合は (2) サーバからアプリケーションをアンデプロイしておきます。アンデプロイするには、undeploy Ant ターゲットを実行します。

 


Beehive に対応したサーバ ドメインの作成

この手順では、Beehive アプリケーションをサポートできる新しいサーバ ドメインを作成します。

  1. [スタート|すべてのプログラム|BEA Products|Tools|Configuration Wizard] を選択して、ドメイン コンフィグレーション ウィザードを起動します。
  2. 2 ページ目 ([Select Domain Source]) と 3 ページ目 ([管理ユーザ名とパスワードのコンフィグレーション]) のみ以下の変更を行い、それ以外は値を変更せずに各ページの [次へ] をクリックします。
  3. 2 ページ目で、[Apache Beehive] チェック ボックスをチェックしてから [次へ] ボタンをクリックします。

    3 ページ目で、[ユーザ パスワード] フィールドと [ユーザ パスワードの確認] フィールドに weblogic と入力します。

    ウィザードの完了時に、<BEA_HOME>\user_projects\domains\base_domainbase_domain というドメインが作成されます。

  4. 以下のスクリプトを実行して、ドメインのサーバ インスタンスを起動します。
  5. <BEA_HOME>\user_projects\domains\base_domain\startWebLogic.cmd

    (Windows の場合)

    <BEA_HOME>/user_projects/domains/base_domain/startWebLogic.sh 

    (UNIX の場合)

  6. 新しいコマンド ウィンドウを開きます。以下のスクリプトを実行して、コマンド ウィンドウで開発環境を設定します。
  7. <BEA_HOME>\user_projects\domains\base_domain\bin\setDomainEnv.cmd

    (Windows の場合)

    <BEA_HOME>/user_projects/domains/base_domain/bin/setDomainEnv.sh

    (UNIX の場合)

 


新しい J2EE アプリケーションの作成

この手順では、基本ディレクトリ構造を作成し、アプリケーションのコンフィグレーション ファイルを作成します。

  1. 次のディレクトリ構造を作成します。
  2. beehive_tutorial
      src
        APP-INF
          lib
          classes
        META-INF
  3. beehive_tutorial\src\build.xml に、次の Ant ビルド ファイルを作成します。「Beehive に対応したサーバ ドメインの作成」で作成した Beehive に対応したサーバ ドメインと一致するように、user プロパティおよび password プロパティの値はともに weblogic となっています。
  4. <?xml version="1.0" encoding="UTF-8" ?>
    <project default="build" basedir=".">
    <property environment="env"/>
    <!-- オーバーライドを提供する -->
    <property file="build.properties"/>
    <property name="src.dir" value="${basedir}"/>
    <property name="dest.dir" value="${basedir}/../build"/>
    <property name="dist.dir" value="${basedir}/../dist"/>
    <property name="app.name" value="beehive_tutorial"/>
    <property name="ear.path" value="${dist.dir}/${app.name}.ear"/>
    <property name="tmp.dir" value="${java.io.tmpdir}"/>
    <property name="weblogic.home" value="${env.WL_HOME}"/>
    <property name="user" value="weblogic"/>
    <property name="password" value="weblogic"/>
    <fail unless="weblogic.home" message="WL_HOME not set in environment"/>
    <property name="beehive.home" value="${weblogic.home}/beehive"/>
    <!-- beehive-imports では beehive-tools.xml で必要になる依存関係パスを定義する -->
    <import file="${beehive.home}/weblogic-beehive/ant/weblogic-beehive-imports.xml"/>
    <!-- build-schemas、build-controls、build-pageflows のマクロを定義する -->
    <import file="${beehive.home}/weblogic-beehive/ant/weblogic-beehive-tools.xml"/>
    <!-- build-webapp のマクロを定義する -->
    <import file="${beehive.home}/weblogic-beehive/ant/weblogic-beehive-buildmodules.xml"/>
    <taskdef name="libclasspath" classname="weblogic.ant.taskdefs.build.LibClasspathTask"/>
    <target name="init.app.libs"> 
    <libclasspath basedir="${src.dir}" tmpdir="${tmp.dir}" property="app.lib.classpath">
    <librarydir dir="${weblogic.home}/common/deployable-libraries/" />
    </libclasspath>
    <echo message="app.lib.claspath is ${app.lib.classpath}" level="info"/>
    </target>
    <target name="init.dirs">
    <mkdir dir="${dest.dir}/APP-INF/classes"/>
    <mkdir dir="${dest.dir}/APP-INF/lib"/>
    <mkdir dir="${dist.dir}"/>
    </target>
    <target name="init" depends="init.app.libs,init.dirs">
    <path id="app.classpath">
    <pathelement location="${src.dir}/APP-INF/classes"/>
    <pathelement location="${dest.dir}/APP-INF/classes"/>
    <pathelement path="${app.lib.classpath}"/>
    <fileset dir="${src.dir}/APP-INF/lib">
    <include name="**/*.jar"/>
    </fileset>
    <fileset dir="${dest.dir}/APP-INF/lib">
    <include name="**/*.jar"/>
    </fileset>
    <fileset dir="${beehive.home}/apache-beehive-incubating-1.0m1/lib/netui">
    <include name="**/*.jar"/>
    <exclude name="**/beehive-netui-compiler.jar"/>
    </fileset>
    </path>
      <wlcompile srcdir="${src.dir}" destdir="${dest.dir}"/>
    </target>
    <target name="build" depends="compile,appc"/>
    <target name="compile" depends="init"/>
    <target name="clean" depends="init.dirs,clean.dest,clean.dist"/>
    <target name="clean.dest">
    <echo message="deleting dest.dir:${dest.dir}"/>
    <delete includeemptydirs="true" >
    <fileset dir="${dest.dir}" excludes=".beabuild.txt" includes="**/*" />
    </delete>
    </target>
    <target name="clean.dist">
    <echo message="deleting dist.dir:${dist.dir}"/>
    <delete includeemptydirs="true" >
    <fileset dir="${dist.dir}" includes="**/*" />
    </delete>
    </target>
    <target name="appc" depends="init" >
    <wlappc source="${dest.dir}" librarydir="${weblogic.home}/common/deployable-libraries/"/>
    </target>
    <target name="pkg.exploded">
    <antcall target="clean.dist"></antcall>
    <wlpackage toDir="${dist.dir}" srcdir="${src.dir}" destdir="${dest.dir}" />
    </target>
    <target name="deploy.exploded" >
    <wldeploy user="${user}" password="${password}" action="deploy" name="${app.name}" source="${dist.dir}"/>
    </target>
    <target name="deploy" >
    <wldeploy user="${user}" password="${password}" action="deploy" name="${app.name}" source="${dest.dir}"/>
    </target>
    <target name="redeploy">
    <wldeploy user="${user}" password="${password}" action="redeploy" name="${app.name}"/>
    </target>
    <!-- このターゲットは、チュートリアルのソース ファイルの場所を移動する場合に便利。
    サーバからアプリケーションをアンデプロイし、ソース ファイルを移動してから、
    アプリケーションを再びサーバにデプロイする -->
    <target name="undeploy">
    <wldeploy user="${user}" password="${password}" action="undeploy" name="${app.name}"/>
    </target>
    </project>
  5. beehive_tutorial\src\META-INF\application.xml に、次のコンフィグレーション ファイルを作成します。
  6. <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
    <display-name>beehive_tutorial</display-name>
    </application>
  7. beehive_tutorial\src\META-INF\weblogic-application.xml に、次のコンフィグレーション ファイルを作成します。このコンフィグレーション ファイルは、アプリケーションが Beehive 機能を使用することを WebLogic Server に通知するものです。これにより、JAR ファイル形式の適切なライブラリがビルド時および実行時に使用可能になります。
  8. <weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
    <library-ref>
    <library-name>weblogic-beehive-1.0</library-name>
    </library-ref>
    </weblogic-application>

 


新しいページ フロー Web アプリケーションの作成

この手順では、ページ フロー Web アプリケーションを作成します。ページ フローによって Beehive アプリケーション用のユーザ インタフェースが生成されます。これにより、ユーザは JSP を通してアプリケーションと対話できるようになります。

  1. 次のフォルダ
  2. <BEA_HOME>\weblogic90\beehive\apache-beehive-incubating-1.0m1\samples\netui-blank 

    beehive_tutorial\src にコピーします (netui-blank はテンプレート Web アプリケーションです)。

  3. netui-blank フォルダの名前を myWebApp に変更します。先に進む前に、次のディレクトリが存在していることを確認してください。
  4. beehive_tutorial
    src
    myWebApp
    resources
    WEB-INF
    Controller.java
    index.jsp
  5. beehive_tutorial\src\META-INF\application.xml を次のように編集します。追加するコードを太字で示します。
  6. <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
    <display-name>beehive_tutorial</display-name>
    <module>
    <web>
    <web-uri>myWebApp</web-uri>
    <context-root>/myWebApp</context-root>
    </web>
    </module>
    </application>
  7. beehive_tutorial\src\myWebApp\index.jsp を次のように編集します。編集するコードを太字で示します。
  8. <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@ taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
    <%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
    <%@ taglib uri="http://beehive.apache.org/netui/tags-template-1.0" prefix="netui-template"%>
    <netui:html>
    <head>
    <title>Beehive Tutorial Test Page</title>
    <netui:base/>
    </head>
    <netui:body>
    <h3>
    Beehive Tutorial Test Page
    </h3>
    <p>
    Welcome to the Beehive Tutorial!
    </p>
    </netui:body>
    </netui:html>
  9. beehive_tutorial\src\myWebApp\WEB-INF\weblogic.xml に、次のコンフィグレーション ファイルを作成します。
  10. <weblogic-web-app
    xmlns="http://www.bea.com/ns/weblogic/90"
    xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.bea.com/ns/weblogic/90
    http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
    <library-ref>
    <library-name>beehive-netui-1.0</library-name>
    </library-ref>
    <library-ref>
    <library-name>struts-1.1</library-name>
    </library-ref>
    <library-ref>
    <library-name>jstl-1.1</library-name>
    </library-ref>
    </weblogic-web-app>
  11. beehive_tutorial\src\build.xml を次のように編集します。追加するコードを太字で示します。
  12. <?xml version="1.0" encoding="UTF-8" ?>
    <project default="build" basedir=".">

      ...
    <wlcompile srcdir="${src.dir}" destdir="${dest.dir}" excludes="myWebApp"/>
    </target>
    . . .
      <target name="compile" depends="init,compile.myWebApp"/>
    .. .
    <target name="redeploy">
    <wldeploy user="${user}" password="${password}" action="redeploy" name="${app.name}"/>
    </target>
      <target name="compile.myWebApp" depends="init" >
    <libclasspath basedir="${src.dir}/myWebApp" tmpdir="${tmp.dir}" property="myWebApp.lib.classpath">
    <librarydir dir="${weblogic.home}/common/deployable-libraries/" />
    </libclasspath>
    <path id="myWebApp.build.classpath">
    <path refid="app.classpath"/>
    <path path="${myWebApp.lib.classpath}"/>
    </path>
        <build-webapp
    webapp.src.dir="${src.dir}/myWebApp"
    webapp.build.dir="${dest.dir}/myWebApp"
    app.build.classpath="myWebApp.build.classpath"/>
    </target>
    </project>

    注意 : myWebApp を <wlcompile> 手順から除外する理由は、次のとおりです。
    Beehive アプリケーションにとって <wlcompile> は、Java ソース ファイルのコンパイルではなく、分割ソースのデプロイメントを容易にするためのものです。ここでは <wlcompile> 要素は、.beabuild ファイルを生成するために存在しています。これにより、アプリケーションの分割ソースのビルド/デプロイメントが可能になります。分割ソースのビルド/デプロイメントは、アプリケーションのビルドおよびデプロイメントを「きれいに」行う方法です。これにより、元のソース ファイルと生成されたビルド結果を厳密に分離できます。もちろん、<wlcompile> は、アプリケーション内のすべての Java ファイルを検索してコンパイルします。ただし、<wlcompile> は、Beehive 固有のクラスを検出すると失敗します。検索から myWebApp ディレクトリを除外することで、<wlcompile>myWebApp 内で Beehive 固有のクラスを検出した場合に発生するコンパイル エラーを回避します。

  13. コマンド ウィンドウで、beehive_tutorial\src\ に移動します。setDomainEnv.cmd または setDomainEnv.sh を実行したのと同じコマンド ウィンドウを使用していることを確認してください。
  14. アプリケーションをコンパイルするには、次の Ant コマンドを実行します。
  15. ant clean build pkg.exploded
  16. アプリケーションをデプロイするには、次の Ant コマンドを実行します。
  17. ant deploy.exploded
  18. アプリケーションをテストするには、ブラウザで次の URL にアクセスします。
  19. http://localhost:7001/myWebApp/begin.do

index.jsp ページが表示されます。

Welcome to the Beehive Tutorial!

 


Java コントロールの追加

Beehive Java コントロールを使用すると、アプリケーションの機能をカプセル化できます。通常は、以下の機能を実行するために Java コントロールが使用されます。

Beehive にはいくつかの「システム コントロール」が付属しています。システム コントロールとは特定の機能を考慮して設計されたものであり、データベース コントロール、JMS コントロール、EJB コントロール、Web サービス コントロールなどがあります。

次の手順では、単純な機能を持つカスタム コントロールを追加します。このカスタム コントロールは「Hello, World!」メッセージを返します。

beehive_tutorial\src\ ディレクトリ内に、controls ディレクトリを作成します。

  1. beehive_tutorial\src\controls ディレクトリ内に、pkg ディレクトリを作成します。
  2. 先に進む前に、次のディレクトリ構造が存在していることを確認してください。

      beehive_tutorial
    src
    controls
    pkg
  3. beehive_tutorial\src\controls\pkg\ フォルダに、HelloWorld.java ファイルを作成します。HelloWorld.java を次のように編集します。
  4. package pkg;
    import org.apache.beehive.controls.api.bean.*;
    @ControlInterface
    public interface HelloWorld
    {
    String hello();
    }
  5. beehive_tutorial\src\controls\pkg\ フォルダに、HelloWorldImpl.java ファイルを作成します。HelloWorldImpl.java を次のように編集します。
  6. package pkg;
    import org.apache.beehive.controls.api.bean.*;
    @ControlImplementation(isTransient=true)
    public class HelloWorldImpl implements HelloWorld
    {
    public String hello()
    {
    return "hello!";
    }
    }
  7. beehive_tutorial\src\myWebApp\Controller.java を次のように編集します。追加および編集するコードを太字で示します。
  8. import javax.servlet.http.HttpSession;
    import org.apache.beehive.netui.pageflow.Forward;
    import org.apache.beehive.netui.pageflow.PageFlowController;
    import org.apache.beehive.netui.pageflow.annotations.Jpf;
    import org.apache.beehive.controls.api.bean.Control;
    import pkg.HelloWorld;
    @Jpf.Controller(
        simpleActions={
            @Jpf.SimpleAction(name="begin_old", path="index.jsp")
        },
        sharedFlowRefs={
            @Jpf.SharedFlowRef(name="shared", type=shared.SharedFlow.class)
        }
    )
    public class Controller
        extends PageFlowController
    {
        @Jpf.SharedFlowField(name="shared")
        private shared.SharedFlow sharedFlow;
        @Control
        private HelloWorld _helloControl;
        @Jpf.Action(
          forwards={
            @Jpf.Forward(name="success", path="index.jsp")
          }
        )
        protected Forward begin() throws Exception
        {
            Forward f = new Forward("success");
            f.addActionOutput("helloMessage", _helloControl.hello());
            return f;
        }
        /**
         * このコントローラ インスタンスが作成されるときに呼び出されるコールバック
         */
        protected void onCreate()
        {
        }
        /**
         * このコントローラ インスタンスが破棄されるときに呼び出されるコールバック

         */
        protected void onDestroy(HttpSession session)
        {
        }
    }
  9. beehive_tutorial/src/myWebApp/index.jsp を次のように編集します。
  10. <netui:html>
    <head>
    <title>Beehive Tutorial Test Page</title>
    <netui:base/>
    </head>
    <netui:body>
    <h3>
    Beehive Tutorial Test Page
    </h3>
    <p>
    Welcome to the Beehive Tutorial!
    </p>
    <p>
    Response from the hello() method on the HelloWorld Control:
    <netui:span style="color:#FF0000" value="${pageInput.helloMessage}"/>
    </p>
    </netui:body>
    </netui:html>
  11. beehive_tutorial/src/build.xml を次のように編集します。追加するコードを太字で示します。
  12. <?xml version="1.0" encoding="UTF-8" ?>
    <project default="build" basedir=".">
    ...
      <wlcompile srcdir="${src.dir}" destdir="${dest.dir}" excludes="myWebApp,controls"/>
    . . .
    <target name="compile" depends="init,compile.helloWorldControl,compile.myWebApp"/>
    . . .
    <target name="compile.helloWorldControl" depends="init">
    <build-controls
    srcdir="${src.dir}"
    destDir="${dest.dir}/APP-INF/classes"
    tempdir="${tmp.dir}/${app.name}/controls/build-controls"
    classpathRef="app.classpath"
    />
    <!-- 重複した myWebApp <apt> 出力をクリーンアップする -->
    <delete>
    <fileset dir="${dest.dir}/APP-INF/classes" excludes="pkg/**/*.class"/>
    </delete>
    </target>
    </project> 
  13. アプリケーションをコンパイルするには、次の Ant コマンドを実行します。setDomainEnv.cmd または setDomainEnv.sh を実行したのと同じコマンド ウィンドウを使用していることを確認してください。
  14. 注意 : 次のビルド プロセスでは、ビルドの警告がいくつか表示されます。これらの警告は無害であり、コンパイルの最終結果に影響しません。

    ant clean build pkg.exploded
  15. アプリケーションをデプロイするには、次の Ant コマンドを実行します。
  16. ant deploy.exploded 
  17. アプリケーションをテストするには、ブラウザで次の URL にアクセスします。
  18. http://localhost:7001/myWebApp/begin.do

    次の JSP ページが表示されます。

    Beehive Tutorial Test Page 
    Welcome to the Beehive Tutorial!
    Response from the hello() method on the HelloWorld Control: hello! 

 


Java Web サービスの追加

Web サービスは、アプリケーションに XML ベースのインタフェースを提供します。この手順では、アプリケーションとの XML ベースの通信方法を作成します。

  1. beehive_tutorial\src\ ディレクトリに、services フォルダを作成します。
  2. beehive_tutorial\src\services\ ディレクトリに、pkg フォルダを作成します。
  3. beehive_tutorial\src\services\pkg\ ディレクトリに、HelloWorldService.java ファイルを作成します。
  4. HelloWorldService.java を次のように編集します。
  5. package pkg; 
    import javax.jws.*;
    import org.apache.beehive.controls.api.bean.Control;
    import pkg.HelloWorld;
    @WebService
    public class HelloWorldService
    {
        @Control
        private HelloWorld _helloControl;
        @WebMethod()
        public String hello()
        {
            String message = _helloControl.hello();
             return message;
        }
    }
  6. beehive_tutorial\src\build.xml を次のように編集します。追加するコードを太字で示します。
  7. <?xml version="1.0" encoding="UTF-8" ?>
    <project default="build" basedir=".">
    ...
    <!-- application.xml ファイルと、Web サービスのコンパイル プロセスによって作成される自動生成
    application.xml ファイルを結合する -->

    <copy todir="${dest.dir}/META-INF">
    <fileset dir="${src.dir}/META-INF"/>
    </copy>
    <wlcompile srcdir="${src.dir}" destdir="${dest.dir}" excludes="myWebApp,controls,services"/>
    ...
    <target name="compile" depends="init,compile.helloWorldControl,compile.helloWorldService,compile.myWebApp"/>
    ...
    <target name="compile.helloWorldService" depends="init" >
      <taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask"/>
      <jwsc
    verbose="true"
    tempdir="${tmp.dir}"
    destdir="${dest.dir}"
    keepgenerated="true"
    srcdir="${basedir}/services">
    <jws file="pkg/HelloWorldService.java" name="HelloWorldService" explode="true"/>
    <classpath>
    <path refid="app.classpath"/>
    </classpath>
    </jwsc>
    </target>
    </project>
  8. アプリケーションをビルドするには、次の Ant コマンドを実行します。setDomainEnv.cmd または setDomainEnv.sh を実行したのと同じコマンド ウィンドウを使用していることを確認してください。
  9. ant clean build pkg.exploded
  10. アプリケーションをデプロイするには、次の Ant コマンドを実行します。
  11. ant deploy.exploded
  12. Web サービスをテストするには、ブラウザで次の URL にアクセスします。
  13. http://localhost:7001/HelloWorldService/HelloWorldService

    Web サービスの WSDL を表示するには、次の URL にアクセスします。

    http://localhost:7001/HelloWorldService/HelloWorldService?WSDL

 

ページの先頭 前 次