SeamFramework.orgCommunity Documentation

第40章 Seam on IBM's Websphere AS

40.1. Websphere AS environment and deployment information
40.1.1. Installation versions
40.2. jee5/booking サンプル
40.2.1. 構成ファイルの変更
40.2.2. jee5/booking サンプルのビルド
40.2.3. Websphere へのアプリケーションのデプロイ
40.3. jpa booking サンプル
40.3.1. jpa サンプルのビルド
40.3.2. jpa サンプルのデプロイ
40.3.3. What's different for Websphere AS V7
40.4. Deploying an application created using seam-gen on Websphere V7
40.4.1. seam-gen セットアップの実行
40.4.2. Websphere へのデプロイに必要な変更点

Websphere AS V7 is IBM's application server offering. This release is fully Java EE 5 certified.

First we will go over some basic information about the Websphere AS environment that we used for these examples. We will go over the details of those steps with the JEE5 booking example. We will also deploy the JPA example application.

Websphere AS is a commercial product and so we will not discuss the details of its installation other than to say follow the directions provided by your particular installation type and license. This section will detail the exact server versions used, installation tips, and some custom properties that are needed for all of the examples.

All of the examples and information in this chapter are based on the version V7 of Websphere AS at the time of this writing.

After installing Websphere AS, create server profile with Profile Management Tool, if you didn't create profile in installation process.

jee5/booking サンプルは、(JBoss AS 上で動作する) ホテル予約サンプルに基づいています。そのままで GlassFish 上で動作するように設計されていますが、以下の手順で Websphere 上でも動作させることができます。このサンプルは $SEAM_DIST/examples/jee5/booking にあります。

雛形のサンプルに対して必要となる構成ファイルの変更点は以下の通りです。

resources/WEB-INF/components.xml

We need to change the way that we look up EJBs for WAS. We need to remove the /local from the end of the jndi-pattern attribute. It should look like this:



<core:init jndi-pattern="java:comp/env/jboss-seam-jee5/#{ejbName}" debug="true"/>
                  
resources/META-INF/ejb-jar.xml

We need to replace the /local string from ejb-ref-name. See at the following final code:



   <enterprise-beans>
      <!-- EJB reference required when one Seam EJB component references another Seam EJB component using @In -->
      <!-- Not required if you inject using @EJB, but then you lose state management and client-side interceptors (e.g., security) -->
      <session>
         <ejb-name>RegisterAction</ejb-name>
         <ejb-local-ref>
            <ejb-ref-name>jboss-seam-jee5/AuthenticatorAction</ejb-ref-name>
            <ejb-ref-type>Session</ejb-ref-type>
            <local>org.jboss.seam.example.booking.Authenticator</local>
         </ejb-local-ref>
      </session>
   </enterprise-beans>
resources/WEB-INF/web.xml

We have to make some changes to the EJB references in the web.xml. These changes are what will allow WAS to bind automatically the EJB3 references in the web module to the the actual EJB3 beans in the EAR module. Replace all of the /local strings in ejb-local-refs when the values below.



  <!-- JEE5 EJB3 names -->
  <ejb-local-ref>
    <ejb-ref-name>jboss-seam-jee5/AuthenticatorAction</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local>org.jboss.seam.example.booking.Authenticator</local>
  </ejb-local-ref>        

  <ejb-local-ref>
    <ejb-ref-name>jboss-seam-jee5/BookingListAction</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local>org.jboss.seam.example.booking.BookingList</local>
  </ejb-local-ref>

  <ejb-local-ref>
    <ejb-ref-name>jboss-seam-jee5/RegisterAction</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local>org.jboss.seam.example.booking.Register</local>
  </ejb-local-ref>

  <ejb-local-ref>
    <ejb-ref-name>jboss-seam-jee5/ChangePasswordAction</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local>org.jboss.seam.example.booking.ChangePassword</local>
  </ejb-local-ref>

  <ejb-local-ref>
    <ejb-ref-name>jboss-seam-jee5/HotelBookingAction</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local>org.jboss.seam.example.booking.HotelBooking</local>
  </ejb-local-ref>

  <ejb-local-ref>
    <ejb-ref-name>jboss-seam-jee5/HotelSearchingAction</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local>org.jboss.seam.example.booking.HotelSearching</local>
  </ejb-local-ref>

  <ejb-local-ref>
    <ejb-ref-name>jboss-seam-jee5/EjbSynchronizations</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local>org.jboss.seam.transaction.LocalEjbSynchronizations</local>
  </ejb-local-ref>

Note also that EjbSynchronizations is a built-in Seam EJB and not part of the Hotel Booking example. This means that if your application's components.xml specifies transaction:ejb-transaction, then you must include:



  <ejb-local-ref>
    <ejb-ref-name
>myapp/EjbSynchronizations</ejb-ref-name>
    <ejb-ref-type
>Session</ejb-ref-type>
    <local-home
></local-home>
    <local
>org.jboss.seam.transaction.LocalEjbSynchronizations</local>
  </ejb-local-ref>

web.xml の中で上記の設定を行わなければ、以下のエラーが発生します。

Name comp/env/myapp/EjbSynchronizations not found in context java:
resources/META-INF/persistence.xml

For this example we will be using the default datasource that comes with WAS. To do this change the jta-data-source element:



<jta-data-source
>DefaultDatasource</jta-data-source>

Hibernate プロパティを設定する必要があります。まず最初に GlassFish プロパティをコメントアウトします。次に以下のプロパティを追加修正する必要があります。



<!--<property name="hibernate.transaction.flush_before_completion" value="true"/>-->
<property name="hibernate.cache.provider_class" 
          value="org.hibernate.cache.HashtableCacheProvider"/>
<property name="hibernate.dialect" value="GlassfishDerbyDialect"/>
<property name="hibernate.transaction.manager_lookup_class" 
          value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
                  

src/GlassfishDerbyDialect.java

You will need to get the GlassfishDerbyDialect.java and copy it into the /src directory. The java class exists in the JPA example source directory and can be copied using the command below assuming you are in jee5/booking directory:

cp ../../jpa/src/GlassfishDerbyDialect.java
   ./src

This class will be put into the jboss-seam-jee5.jar file.

resources/import.sql

Derby DB とダイアレクトのいずれも ID カラムの生成をサポートしないので、JPA サンプルからこのファイルをコピーしなければなりません。ファイルは、ID カラムの違い以外は同一です。 以下のコマンドを使用してコピーしてください

cp ../../jpa/resources-websphere7/import.sql ./resources

必要なものはすべて所定の位置に揃いました。残されたことはデプロイすることです - あとわずか数ステップの手順です。

デプロイには、WebSphere の管理コンソールを使用します。従来どおり従われなければならない手順とヒントがあります。

The steps below are for the WAS version stated above. The ports are default values, if you changed them substitute your values.

  1. Log in to the administration console

    https://localhost:9043/admin

    or

    http://localhost:9060/admin

  2. Access the Websphere enterprise applications menu option under the Applications --> Application Type left side menu.

  3. At the top of the Enterprise Applications table select Install. Below are installation wizard pages and what needs to done on each:

  4. アプリケーションのインストールが完了しましたが、実行の前にいくつかの調整をする必要があります。

  5. アプリケーションを開始するために Enterprise Applications (エンタープライズアプリケーション) テーブルに戻って、リストの中からサンプルのアプリケーションを選択してください。テーブルの先頭で Start ボタンを選択してください。

  6. You can now access the application at http://localhost:9080/seam-jee5-booking/index.html .

Thankfully getting the jpa example to work is much easier than the jee5 example. This is the Hotel Booking example implemented in Seam POJOs and using Hibernate JPA with JPA transactions. It does not use EJB3.

サンプルには、Websphere も含めた多くのコンテナ用の構成とビルドスクリプトが既に用意されています。

最初に行うことは、サンプルのビルトとデプロイです。そのあとに必要な設定変更を行います。

これは jee5 サンプルの 項40.2.3. 「Websphere へのアプリケーションのデプロイ」 と類似していますが、多くの手順は必要ありません。

  • Enterprise Applications (エンタープライズアプリケーション) テーブルから Install (インストール) ボタンを選択してください。

    • アプリケーションのインストール準備

      • Browse to the examples/jpa/dist-websphere7/jboss-seam-jpa.war file using the file upload widget.

      • Select the Fast Path button.

      • Next ボタンを選択してください。

    • Next ボタンを選択して、3 ページ先まで進んでください。そこまで変更は必要ありません。

    • Map context roots for Web modules

      • Context root テキストボックスに jboss-seam-jpaを入力してください。

      • Next ボタンを選択してください。

    • Summary (要約) ページ

      • お望みなら設定を確認して、Finish (完了) ボタンを選択してアプリケーションのインストールを完了してください。インストールが完了して Save (保存) リンクを選択すると Enterprise Applications (エンタープライズアプリケーション)テーブルに戻ります。

  • As with the jee5 example there are some class loader changes needed before we start the application. Follow the instructions at installation adjustments for jee5 example but exchange jboss-seam-jpa_war for Seam Booking.

  • 最後にアプリケーションを開始するには、Enterprise Applications (エンタープライズアプリケーション) テーブルでアプリケーションを選択して Start (開始) ボタンをクリックしてください。

  • http://localhost:9080/jboss-seam-jpa/index.html からアプリケーションにアクセスできます。

The differences between the JPA examples that deploys to JBoss 4.2 and Websphere AS V7 are mostly expected; library and configuration file changes.

seam-gen は、開発者が素早くアプリケーションを準備して動作させるのにとても役に立つツールで、独自の機能を追加するための雛形を用意します。seam-gen はそのままで JBoss AS で動作するように構成されたアプリケーションを生成します。以下の手順では、Websphere 上で動作させるために必要なステップを示します。項40.2. 「jee5/booking サンプル 」 で述べたように、EJB3 アプリケーションを動作させるには変更が必要です。このセクションでは、その正確な手順を示します。

第一ステップは、雛形となるプロジェクトを生成できるように seam-gen をセットアップすることです。以下に実行したように、設定すべき項目がいくつかあります。特に、データソースと Hibernate の設定値は、プロジェクトを生成する環境に合わせて設定します。

./seam setup
Buildfile: build.xml

init:

setup:
     [echo] Welcome to seam-gen :-)
    [input] Enter your Java project workspace (the directory that contains your 
Seam projects) [C:/Projects] [C:/Projects]
/home/jbalunas/workspace
    [input] Enter your JBoss home directory [C:/Program Files/jboss-4.2.3.GA] 
[C:/Program Files/jboss-4.2.3.GA]
/home/jbalunas/jboss/jboss-4.2.3.GA
    [input] Enter the project name [myproject] [myproject]
websphere_example
     [echo] Accepted project name as: websphere_example
    [input] Do you want to use ICEFaces instead of RichFaces [n] (y, [n], )

    [input] skipping input as property icefaces.home.new has already been set.
    [input] Select a RichFaces skin [blueSky] ([blueSky], classic, ruby, wine, 
deepMarine, emeraldTown, sakura, DEFAULT)

    [input] Is this project deployed as an EAR (with EJB components) or a WAR 
(with no EJB support) [ear]  ([ear], war, )

    [input] Enter the Java package name for your session beans [org.jboss.seam.
tutorial.websphere.action] [org.jboss.seam.tutorial.websphere.action]
org.jboss.seam.tutorial.websphere.action 
    [input] Enter the Java package name for your entity beans [org.jboss.seam.
tutorial.websphere.model] [org.jboss.seam.tutorial.websphere.model]
org.jboss.seam.tutorial.websphere.model  
    [input] Enter the Java package name for your test cases [org.jboss.seam.
tutorial.websphere.action.test] [org.jboss.seam.tutorial.websphere.action.test]
org.jboss.seam.tutorial.websphere.test
    [input] What kind of database are you using? [hsql]  ([hsql], mysql, oracle,
 postgres, mssql, db2, sybase, enterprisedb, h2)

    [input] Enter the Hibernate dialect for your database [org.hibernate.
dialect.HSQLDialect] [org.hibernate.dialect.HSQLDialect]

    [input] Enter the filesystem path to the JDBC driver jar [/tmp/seam/lib/hsqldb.jar] 
[/tmp/seam/lib/hsqldb.jar]

    [input] Enter JDBC driver class for your database [org.hsqldb.jdbcDriver] 
[org.hsqldb.jdbcDriver]

    [input] Enter the JDBC URL for your database [jdbc:hsqldb:.] 
[jdbc:hsqldb:.]

    [input] Enter database username [sa] [sa]

    [input] Enter database password [] []

    [input] Enter the database schema name (it is OK to leave this blank) [] []

    [input] Enter the database catalog name (it is OK to leave this blank) [] []

    [input] Are you working with tables that already exist in the database? [n]
  (y, [n], )

    [input] Do you want to drop and recreate the database tables and data in 
import.sql each time you deploy? [n]  (y, [n], )

[propertyfile] Creating new property file: 
/rhdev/projects/jboss-seam/svn-seam_2_0/jboss-seam-2_0/seam-gen/build.properties
     [echo] Installing JDBC driver jar to JBoss server
     [copy] Copying 1 file to /home/jbalunas/jboss/jboss-4.2.3.GA/server/default/lib
     [echo] Type 'seam create-project' to create the new project

BUILD SUCCESSFUL
Total time: 3 minutes 5 seconds

プロジェクトを作成するためには、$ ./seam new-project と入力してください。そして cd /home/jbalunas/workspace/websphere_example と入力して新しく作成されたディレクトリへ移動してください。

生成されたプロジェクトに変更を行う必要があります。

resources/META-INF/persistence-dev.xml
  • jta-data-sourceDefaultDatasource に修正してください。組み込みの Websphere DB を使用します。

  • 以下のプロパティを追加修正してください。項40.2. 「jee5/booking サンプル 」 に詳細が説明されています。

    
    
    <property name="hibernate.dialect" value="GlassfishDerbyDialect"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.format_sql" value="true"/>
    <property name="hibernate.cache.provider_class" 
              value="org.hibernate.cache.HashtableCacheProvider"/>
    <property name="hibernate.transaction.manager_lookup_class" 
              value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
  • EntityManagerFactory を定義する JBoss AS 固有のメソッドを取り除いてください。

    
    <property 
     name="jboss.entity.manager.factory.jndi.name" 
     value="java:/websphere_exampleEntityManagerFactory">
  • prod プロファイルを使用して Websphere にデプロイしたければ、persistence-prod.xml も同様に修正する必要があります。

src/GlassfishDerbyDialect.java

As with other examples we need to include this java class for DB support. It can be copied from the jpa example into the websphere_example/src directory.

cp $SEAM/examples/jpa/src/GlassfishDerbyDialect.java
   ./src

resources/META-INF/jboss-app.xml

JBoss AS にはデプロイしないのでこのファイルを削除できます (JBoss AS では jboss-app.xml を使用して、クラスローディングの分離を有効にします)

resources/*-ds.xml

JBoss AS にはデプロイしないのでこのファイルを削除できます (これらのファイルは、JBoss AS ではデータソースを定義していますが、Websphere ではデフォルトのデータソースを使用しています)

resources/WEB-INF/components.xml
  • コンテナ管理トランザクション統合を有効にします - <transaction:ejb-transaction /> コンポーネントと、その名前空間宣言 xmlns:transaction="http://jboss.com/products/seam/transaction" を追記してください

  • jndi-patternjava:comp/env/websphere_example/#{ejbName} に修正します

  • このサンプルでは、managed-persistence-context は必要ではないので、そのエントリは削除します。

    
    
    <persistence:managed-persistence-context name="entityManager"
                 auto-create="true"
                 persistence-unit-jndi-name="java:/websphere_exampleEntityManagerFactory"/> 
resources/WEB-INF/web.xml

As with the jee5/booking example we need to add EJB references to the web.xml. These references require replacing /local string in ejb-ref-name to flag them for Websphere to perform the proper binding.


  
  <ejb-local-ref>
    <ejb-ref-name>websphere_example/AuthenticatorAction</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local>org.jboss.seam.tutorial.websphere.action.Authenticator</local>
  </ejb-local-ref>        
   
  <ejb-local-ref>
    <ejb-ref-name>websphere_example/EjbSynchronizations</ejb-ref-name>  
    <ejb-ref-type>Session</ejb-ref-type>
    <local>org.jboss.seam.transaction.LocalEjbSynchronizations</local>
  </ejb-local-ref>

このアプリケーションは、jee5/booking サンプルと同様の変更が必要となります。