WebLogic Server 9.0 Beehive 統合ガイド
![]() |
![]() |
![]() |
![]() |
このチュートリアルでは、Beehive アプリケーションを作成し、WebLogic Server にデプロイする方法について示すとともに、
以下の 3 種類の Beehive 基本コンポーネントを作成する方法について示します。
注意 : チュートリアルを実行するのが 2 回目である場合、アプリケーションのソース ファイルの場所を変更すると同じサーバ ドメインにデプロイできなくなりますので注意してください。この問題を回避するには、(1) 新しいサーバ ドメインを最初から作成するか (つまり、このチュートリアルの最初の手順から始めるか)、あるいは最初の手順をスキップする場合は (2) サーバからアプリケーションをアンデプロイしておきます。アンデプロイするには、undeploy
Ant ターゲットを実行します。
この手順では、Beehive アプリケーションをサポートできる新しいサーバ ドメインを作成します。
2 ページ目で、[Apache Beehive] チェック ボックスをチェックしてから [次へ] ボタンをクリックします。
3 ページ目で、[ユーザ パスワード] フィールドと [ユーザ パスワードの確認] フィールドに weblogic
と入力します。
ウィザードの完了時に、<BEA_HOME>
\user_projects\domains\base_domain
に base_domain というドメインが作成されます。
<BEA_HOME>\user_projects\domains\base_domain\startWebLogic.cmd
<BEA_HOME>\user_projects\domains\base_domain\bin\setDomainEnv.cmd
この手順では、基本ディレクトリ構造を作成し、アプリケーションのコンフィグレーション ファイルを作成します。
beehive_tutorial
src
APP-INF
lib
classes
META-INF
beehive_tutorial\src\build.xml
に、次の Ant ビルド ファイルを作成します。「Beehive に対応したサーバ ドメインの作成」で作成した Beehive に対応したサーバ ドメインと一致するように、user プロパティおよび password プロパティの値はともに weblogic となっています。
<?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>
<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>
beehive_tutorial\src\META-INF\weblogic-application.xml
に、次のコンフィグレーション ファイルを作成します。このコンフィグレーション ファイルは、アプリケーションが Beehive 機能を使用することを WebLogic Server に通知するものです。これにより、JAR ファイル形式の適切なライブラリがビルド時および実行時に使用可能になります。
<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 アプリケーションを作成します。ページ フローによって Beehive アプリケーション用のユーザ インタフェースが生成されます。これにより、ユーザは JSP を通してアプリケーションと対話できるようになります。
<BEA_HOME>
\weblogic90\beehive\apache-beehive-incubating-1.0m1\samples\netui-blank
beehive_tutorial
src
myWebApp
resources
WEB-INF
Controller.java
index.jsp
<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>
</application>
<web>
<web-uri>myWebApp</web-uri>
<context-root>/myWebApp</context-root>
</web>
</module>
<%@ 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>
<p>
Beehive Tutorial Test Page
</h3>Welcome to the Beehive Tutorial!
</p>
</netui:body>
</netui:html>
<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>
<?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 固有のクラスを検出した場合に発生するコンパイル エラーを回避します。
beehive_tutorial\src\
に移動します。setDomainEnv.cmd
または setDomainEnv.sh
を実行したのと同じコマンド ウィンドウを使用していることを確認してください。
ant clean build pkg.exploded
ant deploy.exploded
Welcome to the Beehive Tutorial!
Beehive Java コントロールを使用すると、アプリケーションの機能をカプセル化できます。通常は、以下の機能を実行するために Java コントロールが使用されます。
Beehive にはいくつかの「システム コントロール」が付属しています。システム コントロールとは特定の機能を考慮して設計されたものであり、データベース コントロール、JMS コントロール、EJB コントロール、Web サービス コントロールなどがあります。
次の手順では、単純な機能を持つカスタム コントロールを追加します。このカスタム コントロールは「Hello, World!」メッセージを返します。
beehive_tutorial\src\
ディレクトリ内に、controls
ディレクトリを作成します。
package pkg;
import org.apache.beehive.controls.api.bean.*;
@ControlInterface
public interface HelloWorld
{
String hello();
}
beehive_tutorial\src\controls\pkg\
フォルダに、HelloWorldImpl.java
ファイルを作成します。HelloWorldImpl.java
を次のように編集します。
package pkg;
import org.apache.beehive.controls.api.bean.*;
@ControlImplementation(isTransient=true)
public class HelloWorldImpl implements HelloWorld
{
public String hello()
{
return "hello!";
}
}
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)
{
}
}
<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>
</netui:body>
Response from the hello() method on the HelloWorld Control:
<netui:span style="color:#FF0000" value="${pageInput.helloMessage}"/>
</p>
</netui:html>
<?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>
setDomainEnv.cmd
または setDomainEnv.sh
を実行したのと同じコマンド ウィンドウを使用していることを確認してください。注意 : 次のビルド プロセスでは、ビルドの警告がいくつか表示されます。これらの警告は無害であり、コンパイルの最終結果に影響しません。
ant clean build pkg.exploded
ant deploy.exploded
http://localhost:7001/myWebApp/begin.do
Beehive Tutorial Test Page
Welcome to the Beehive Tutorial!
Response from the hello() method on the HelloWorld Control: hello!
Web サービスは、アプリケーションに XML ベースのインタフェースを提供します。この手順では、アプリケーションとの XML ベースの通信方法を作成します。
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;
}
}
<?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>
setDomainEnv.cmd
または setDomainEnv.sh
を実行したのと同じコマンド ウィンドウを使用していることを確認してください。
ant clean build pkg.exploded
ant deploy.exploded
http://localhost:7001/HelloWorldService/HelloWorldService
Web サービスの WSDL を表示するには、次の URL にアクセスします。
http://localhost:7001/HelloWorldService/HelloWorldService?WSDL
![]() |
![]() |
![]() |