2012年7月8日日曜日

Displaytagポートレットで表のソート、ページング

Displaytagポートレットの作り方。
及び、このポートレットでソート、ページングができる表の作り方を書いておく。

参考情報:
External Paging and Sorting
Displaytag library in your portlet

通常、コノ手の表はJSFベースでナントカFaces使って片付けるんでしょうね。
でも、今回は個人的な方針の都合でSpringベースだから、Displaytagを使う。
  1. Displaytagポートレットを作る
    まず、通常のセットアップとして、Displaytagのライブラリを、アプリケーションのWEB-INF/libに入れる。
    参考情報:Installation Guide

    次に、クラスパスにdisplaytag.propertiesファイルを追加する。
    displaytag.propertiesファイルに、この一文を書き込む。
    factory.requestHelper=org.displaytag.portlet.PortletRequestHelperFactory
    参考情報:JSR-168 Portlet Support

    これで、ポートレットにDisplaytag表を追加して、ソートやページングさせる準備が整う。
    実は、このファイルが無くても、Displaytag表は表示できる。
    が、ソートやページングができない。

  2. ソート、ページングができる表を作る
    ソートやページングができる表を作るには、二つ方法があるらしい。
    Valuelistパターンを使う方法と使わない方法。
    今回はValuelistパターンを使う方法を採用した。

    この方法だとorg.displaytag.pagination.PaginatedListインタフェイスの実装が必要。
    で、探したところ幾つか見つけて、コレはその中の一つ。
    Displaytag library in your portlet

    具体的に、どう使うかって言うと…
    まず、Springのコントローラから渡すモデルMapに、このPaginatedList実装をプットする。
     Map model = new HashMap();
     // 表示するデータのリストを取得する
     List list = this.logpageDao.readLogmessages(filePath,log4jPattern);
     // displaytagでソート、ページングできるリストへ変換
     PaginatedListImpl list2 = new PaginatedListImpl(request);
     list2.setList(list);
     model.put("list", list);
    次に、JSP側で、Displaytag表で表示するデータに、このPaginatedList実装を指定する。
     <portlet:renderURL var="viewListURL" />
     <display:table name="list" sort="external" defaultsort="1" requestURI="${viewListURL}" pagesize="20" id="element" >
      <display:column property="lineNumber" title="LN" sortable="true" sortName="lineNumber" />
      <display:column property="data" title="DT" />
     </display:table>
    
    「pagesize="20"」で1ページに20レコードを指定。

2012年6月28日木曜日

JBoss7のデータソース設定

JBoss7でのデータソース設定方法を説明したページがあったので書いておく。
コレもボチボチと訳してこかな。
[AS71:DataSource configuration]
https://docs.jboss.org/author/display/AS71/DataSource+configuration

ついでにJBoss7.1のドキュメントも
https://docs.jboss.org/author/display/AS71/Documentation

ちなみにコッチの方が1ページになってて見易い
Data Source Configuration in AS 7
https://community.jboss.org/wiki/DataSourceConfigurationInAS7#Installing_a_JDBC_driver_as_a_module


Data Source Configuration in AS 7

Datasources are configured through the datasource subsystem.
Datasourcesは、datasourceサブシステムを通して構成されます。
Declaring a new datasource consists of two separate steps:
新しいdatasourceを宣言することは、2つの別々のステップから成ります:
You would need to provide a JDBC driver and define a datasource that references the driver you installed.
あなたはJDBCドライバーを提供する必要があって、設置したドライバーを参照文に引用するdatasourceを定めるでしょう。

JDBC Driver Installation
JDBCドライバー・インストール

The recommended way to install a JDBC driver into the application server is to simply deploy it as a regular JAR deployment.
アプリケーション・サーバにJDBCドライバーを設置する推薦された方法は、単に普通にJARをデプロイしてそれを配備することです。
The reason for this is that when you run your application server in domain mode, deployments are automatically propagated to all servers to which the deployment applies;
これの理由は、あなたがドメインモードでアプリケーション・サーバを動かすとき、配備機構が配備があてはまるすべてのサーバーに自動的に伝播されるということです;
thus distribution of the driver JAR is one less thing for you to worry about!
このように、ドライバーJARの配布は、あなたが心配する1つのより少ないものです!

Any JDBC 4-compliant driver will automatically be recognized and installed into the system by name and version.
どんなJDBC 4対応ドライバーでも、名前とバージョンによってシステムに自動的に認識されて、設置されます。
A JDBC JAR is identified using the Java service provider mechanism.
JDBC JARは、Javaサービスプロバイダ・メカニズムを使って確認されます。
Such JARs will contain a text a file named META-INF/services/java.sql.Driver, which contains the name of the class(es) of the Drivers which exist in that JAR.
ファイルがMETA-INF/services/java.sql.Driverという名前をつけたテキストを、そのようなJARsは含みます。そして、それはそのJARの中に存在するドライバーの種類の名前を含みます。
If your JDBC driver JAR is not JDBC 4-compliant, it can be made deployable in one of a few ways.
あなたのJDBCドライバーJARがJDBC 4-対応でないならば、それは2、3の方向の1つで展開できるようになることができます。

Modify the JAR
JARを修正する

The most straightforward solution is to simply modify the JAR and add the missing file.
最も直接の解決は単にJARを修正することで、失っているファイルを加えることです。
You can do this from your command shell by:
あなたは、コマンドシェルから以下によってこうすることができます:

1.Change to, or create, an empty temporary directory.
1.空の一時的なディレクトリに移動、あるいは、作成してください。
2.Create a META-INF subdirectory.
2.META-INFサブディレクトリを作成してください。
3.Create a META-INF/services subdirectory.
3.META-INF/servicesサブディレクトリを作成してください。
4.Create a META-INF/services/java.sql.Driver file which contains one line - the fully-qualified class name of the JDBC driver.
4.META-INF/services/java.sql.Driverファイルを作成し、そのファイルにこの1行含めます-JDBCドライバのフルクラス名
5.Use the jar command-line tool to update the JAR like this:
5.jarコマンドラインツールを使い、このようにJARをアップデートします:
jar \-uf jdbc-driver.jar META-INF/services/java.sql.Driver

For a detailed explanation how to deploy JDBC 4 compliant driver jar, please refer to the chapter "Application Deployment".
JDBC 4対応ドライバー・ジャーを展開するために詳細な説明方法については、章「アプリケーションDeployment」を参照してください。

Datasource Definitions
データソース定義

The datasource itself is defined within the subsystem datasources:
datasource自体は、サブシステムdatasourcesの中で定義されます:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
    <datasources>
        <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS">
            <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
            <driver>h2</driver>
            <pool>
                <min-pool-size>10</min-pool-size>
                <max-pool-size>20</max-pool-size>
                <prefill>true</prefill>
            </pool>
            <security>
                <user-name>sa</user-name>
                <password>sa</password>
            </security>
        </datasource>
        <xa-datasource jndi-name="java:jboss/datasources/ExampleXADS" pool-name="ExampleXADS">
           <driver>h2</driver>
           <xa-datasource-property name="URL">jdbc:h2:mem:test</xa-datasource-property>
           <xa-pool>
                <min-pool-size>10</min-pool-size>
                <max-pool-size>20</max-pool-size>
                <prefill>true</prefill>
           </xa-pool>
           <security>
                <user-name>sa</user-name>
                <password>sa</password>
           </security>
        </xa-datasource>
        <drivers>
            <driver name="h2" module="com.h2database.h2">
                <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
            </driver>
        </drivers>
  </datasources>

</subsystem>
(See standalone/configuration/standalone.xml)
(standalone/configuration/standalone.xml参照)

As you can see the datasource references a driver by it's logical name.
datasourceがそばにドライバーを参照文に引用するのをあなたが見ることができるように、それは論理的な名前です。

You can easily query the same information through the CLI:
あなたは、CLIによって同じ情報を簡単に問い合わせることができます:

[standalone@localhost:9999 /] /subsystem=datasources:read-resource(recursive=true)
{
    "outcome" => "success",
    "result" => {
        "data-source" => {"java:/H2DS" => {
            "connection-url" => "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",
            "jndi-name" => "java:/H2DS",
            "driver-name" => "h2",
            "pool-name" => "H2DS",
            "use-java-context" => true,
            "enabled" => true,
            "jta" => true,
            "pool-prefill" => true,
            "pool-use-strict-min" => false,
            "user-name" => "sa",
            "password" => "sa",
            "flush-strategy" => "FailingConnectionOnly",
            "background-validation" => false,
            "use-fast-fail" => false,
            "validate-on-match" => false,
            "use-ccm" => true
        }},
        "xa-data-source" => undefined,
        "jdbc-driver" => {"h2" => {
            "driver-name" => "h2",
            "driver-module-name" => "com.h2database.h2",
            "driver-xa-datasource-class-name" => "org.h2.jdbcx.JdbcDataSource"
        }}
    }
}

[standalone@localhost:9999 /] /subsystem=datasources:installed-drivers-list
{
    "outcome" => "success",
    "result" => [{
        "driver-name" => "h2",
        "deployment-name" => undefined,
        "driver-module-name" => "com.h2database.h2",
        "module-slot" => "main",
        "driver-xa-datasource-class-name" => "org.h2.jdbcx.JdbcDataSource",
        "driver-class-name" => "org.h2.Driver",
        "driver-major-version" => 1,
        "driver-minor-version" => 2,
        "jdbc-compliant" => true
    }]
}
Using the web console or the CLI greatly simplifies the deployment of JDBC drivers and the creation of datasources.
ウェブ・コンソールまたはCLIを使用することは、JDBCドライバーの配備とdatasourcesの創造を大いに単純化します。

The CLI offers a set of commands to create and modify datasources:
CLIは、datasourcesをつくって、修正しなさいという一組の命令を提供します:
[standalone@localhost:9999 /] help
Supported commands:

[...]

data-source - allows to add new, modify and remove existing data sources
xa-data-source - allows add new, modify and remove existing XA data sources

For a more detailed description of a specific command, execute the command with '--help' as the argument.
特定の命令のより仔細な説明のために、引数として『--help』でコマンドを実行してください。

Using security domains
セキュリティ・ドメインの使用

Information can be found at https://community.jboss.org/wiki/JBossAS7SecurityDomainModel
Deployment of -ds.xml files

Starting with JBoss Application Server 7.1.0.Final you have the ability to deploy a -ds.xml file following the schema:
-ds.xmlファイルの配備の情報は、https://community.jboss.org/wiki/JBossAS7SecurityDomainModelで見つかります。

http://docs.jboss.org/ironjacamar/schema/datasources_1_1.xsd

It is mandatory to use a reference to an already deployed / defined entry.
すでに展開された/定義済みのエントリへの参照を使うことは、義務的です。

This feature is primarily intended for development, and thus has a few limitations to be aware of.
この特徴には主に発展を目的として、このように、気づいている2、3の限界があります。
It can not be altered in any of the management interfaces (consle, CLI, etc).
それは、管理インターフェース(コンソール、CLI、その他)の何でも変えられることができません。
Only limited runtime information is available.
限られた実行時情報だけが利用できます。
Also, password vaults and security domains are not deployable, so these can not be bundled with a datasource deployment.
また、パスワード金庫室とセキュリティ・ドメインは展開できないので、これらはdatasource配備とバンドルされることができません。

Component Reference
コンポーネント参照

The datasource subsystem is provided by the IronJacamar project.
datasourceサブシステムは、IronJacamarプロジェクトによって提供されます。
For a detailed description of the available configuration properties, please consult the project documentation.
利用できる構成特性の詳しい説明のために、プロジェクト・ドキュメンテーションを参照してください。

- IronJacamar homepage: http://www.jboss.org/ironjacamar
- Project Documentation: http://www.jboss.org/ironjacamar/docs
- Schema description: http://docs.jboss.org/ironjacamar/userguide/1.0/en-US/html/deployment.html#deployingds_descriptor


2012年6月24日日曜日

Springポートレットでパラメータ付リンクを使ったコントローラ分岐

SpringFrameworkポートレットで、
VIEWモードの中でコントローラ1から、コントローラ2へ画面を移動するのに、
リンクを使って移動する方法を書いておく。
(Spring3.1だからアノテーションでサクっと行くべきなんだろうけど、アノテーションだと、後から見たときに、設定ファイルだけじゃなく、ソースまで追いかけないと、概要が分からなくなるから、 ちょっと使いたくないのよね…)

まず、JSPページこんな風にした場合…

<portlet:renderURL var="vew1">
    <portlet:param name="action" value="view1" />
</portlet:renderURL>

<a href="${vew1}"> 次のページへ</a>

実際ポートレットに出力されるrenderURLは、
パラメータ付URLで、ネーム=action、値=view1になる。
ちなみに「ネーム=actionactionはSpringのデフォルトに合わせた。

で、このジャンプ先をSpring設定ファイルで指定する。
が、この設定ファイル上で一癖あるので要注意。

まず、ポートレットモードハンドラ

<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
 <property name="order" value="2" />
 <property name="portletModeMap">
  <map>
   <entry key="view" value-ref="viewController" />
   <entry key="edit" value-ref="editController" />
   <entry key="help" value-ref="helpController" />
  </map>
 </property>
</bean>

いつもは「property name="order" value="2"」の設定はしない。
各モードへ入ったあと、ドコに飛んでいくか、だけがあれば充分だから。

次に、パラメータハンドラ

<bean id="parameterHandlerMapping" class="org.springframework.web.portlet.handler.ParameterHandlerMapping">
 <property name="order" value="1" />
 <property name="parameterMap">
  <map>
   <entry key="view1" value-ref="view1Controller" />
  </map>
 </property>
 <property name="interceptors">
  <list>
  <ref bean="parameterMappingInterceptor" />
  </list>
 </property>
</bean>

今回、画面から受け取ったパラメータの値で、移動先コントローラを変えたいので、パラメータハンドラを使う。
これで、画面からリンクで受け取ったパラメータがview1の場合はview1Controllerへジャンプする。
で、要注意なのは「property name="order" value="1"」。
これでパラメータハンドラを、ポートレットモードハンドラより優先度を上にしてあげる。
そうしないと、リンクを押しても画面がジャンプしない。

で、それを踏まえつつ、今回の設定を書いておく。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="viewController" class="plutoportlet.ViewController">
        <property name="viewName" value="view" />
    </bean>

    <bean id="editController"
        class="org.springframework.web.portlet.mvc.ParameterizableViewController">
        <property name="viewName" value="edit" />
    </bean>

    <bean id="helpController"
        class="org.springframework.web.portlet.mvc.ParameterizableViewController">
        <property name="viewName" value="help" />
    </bean>

    <bean id="portletModeHandlerMapping"
        class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
        <property name="order" value="2" />
        <property name="portletModeMap">
            <map>
                <entry key="view" value-ref="viewController" />
                <entry key="edit" value-ref="editController" />
                <entry key="help" value-ref="helpController" />
            </map>
        </property>
    </bean>


    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.InternalResourceView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean id="view1Controller" class="plutoportlet.View1Controller">
        <property name="viewName" value="view1" />
    </bean>

    <bean id="parameterMappingInterceptor"
        class="org.springframework.web.portlet.handler.ParameterMappingInterceptor" />

    <bean id="parameterHandlerMapping"
        class="org.springframework.web.portlet.handler.ParameterHandlerMapping">
        <property name="order" value="1" />
        <property name="parameterMap">
            <map>
                <entry key="view1" value-ref="view1Controller" />
            </map>
        </property>
        <property name="interceptors">
            <list>
                <ref bean="parameterMappingInterceptor" />
            </list>
        </property>
    </bean>


</beans>









2012年6月21日木曜日

OpenShiftのLinuxで使えるコマンド

ココに、OpenShiftにSSHログインした後で使用可能なコマンドリストがあったので書いておく。
Remotely Accessing your App with SSH
https://openshift.redhat.com/community/developers/remote-access
ほとんどがLinuxを使ったことがあれば誰でも知ってるコマンドだけどね。

Common Commands

help
Displays a list of common commands to use

ctl_app
control your application

ctl_app start
ctl_app stop
ctl_app restart
ctl_app status

ctl_all
Similar to ctl_app but controlls application and deps like mysql in one command

ctl_all start
ctl_all stop
ctl_all restart
ctl_all status

export
Prints out all available environment variables and their current values which you may use in your application

rm
Removes a file or directory

Use this with care

Remove a file:

rm file

Remove a directory and all files and directories under it

rm -rf

tail_all
Displays the last entries in your log files as they are written to

You can hit ctrl-c to exit this command

ls
List files and directories

ps
List running applications

kill
Kill running applications using the process id found by calling ps

Be careful when using this command as it should only be used to kill runaway processes, otherwise it is preferable to stop them using the appropriate command such as ctl_app stop

mysql
Opens an interactive MySQL shell

mongo
Opens an interactive MongoDB shell

quota
Lists your application's current disk usage

2012年6月20日水曜日

Pluto2.0の日本語文字化け対策

ApachePluto2.0をデフォルトのまま使うと、こんな文字化けが発生する。
  1. JSPやポートレットの日本語が文字化けする。
  2. 画面からPostした日本語が文字化けする。
で、その対策を書いておく。

対策としては、普通のWEBアプリ同様エンコードをUTF-8に統一すればOK。
今回、その対象となるのが、Plutoのフロントエンドとなるplutoアプリ。
この、plutoアプリのweb.xmlを修正する。
つまり、pluto-2.0.3/webapps/pluto/WEB-INF/web.xmlを修正する。

修正したのが下記XML。
修正内容としては、変更や削除は何もなく、サーブレットパラメータとエンコーディングフィルタの追加のみ。
  1. 青文字が、JSPやポートレットの文字化け対策。
    plutoPortalDriverサーブレットのcharsetパラメータにUTF-8を指定する。
    参考情報
    Pluto - Frequently Asked Questions
    http://portals.apache.org/pluto/faq.html
    How can I change the default encoding of the Pluto Portal
  2. 赤文字が、Postした日本語の文字化け対策。
    Tomcatが持ってるエンコーディングフィルタを使って、ブラウザと送受信するデータをUTF-8と指定する。
    昔はサンプルだったのに、いつのまにやら本体に入ってたのね。
エンコーディングフィルタはともかく、サーブレットパラメータはデフォルトをUTF-8にしてくれればいいのにね。

[web.xml]

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

  <display-name>Apache Pluto Portal Driver</display-name>

    <filter>
        <filter-name>EncodeFilter</filter-name>
        <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>EncodeFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/pluto-portal-driver-services-config.xml</param-value>
  </context-param>

  <filter>
    <filter-name>plutoPortalDriver</filter-name>
    <filter-class>org.apache.pluto.driver.PortalDriverFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>plutoPortalDriver</filter-name>
    <url-pattern>/about.jsp</url-pattern>
  </filter-mapping>

  <filter-mapping>
    <filter-name>plutoPortalDriver</filter-name>
    <url-pattern>/about.jsp/*</url-pattern>
  </filter-mapping>

  <listener>
    <listener-class>org.apache.pluto.driver.PortalStartupListener</listener-class>
  </listener>

  <servlet>
    <servlet-name>plutoPortalDriver</servlet-name>
    <display-name>Pluto Portal Driver</display-name>
    <description>Pluto Portal Driver Controller</description>
    <servlet-class>org.apache.pluto.driver.PortalDriverServlet</servlet-class>
    <init-param>
      <param-name>charset</param-name>
      <param-value>UTF-8</param-value>
   </init-param>
  </servlet>

  <servlet>
    <servlet-name>plutoPortalDriverLogout</servlet-name>
    <display-name>Pluto Portal Driver</display-name>
    <description>Pluto Portal Driver Logout</description>
    <servlet-class>org.apache.pluto.driver.PortalDriverLogoutServlet</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>portletApplicationPublisher</servlet-name>
    <display-name>Portlet Application Publisher</display-name>
    <description>Portlet Application Publisher Service</description>
    <servlet-class>org.apache.pluto.driver.PublishServlet</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>tckDriver</servlet-name>
    <display-name>Pluto TCK Driver</display-name>
    <description>Pluto TCK Driver Controller</description>
    <servlet-class>org.apache.pluto.driver.TCKDriverServlet</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>AboutPortlet</servlet-name>
    <servlet-class>org.apache.pluto.container.driver.PortletServlet</servlet-class>
    <init-param>
      <param-name>portlet-name</param-name>
      <param-value>AboutPortlet</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>AdminPortlet</servlet-name>
    <servlet-class>org.apache.pluto.container.driver.PortletServlet</servlet-class>
    <init-param>
      <param-name>portlet-name</param-name>
      <param-value>AdminPortlet</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>PlutoPageAdmin</servlet-name>
    <servlet-class>org.apache.pluto.container.driver.PortletServlet</servlet-class>
    <init-param>
      <param-name>portlet-name</param-name>
      <param-value>PlutoPageAdmin</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>plutoPortalDriver</servlet-name>
    <url-pattern>/portal/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>plutoPortalDriverLogout</servlet-name>
    <url-pattern>/Logout</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>portletApplicationPublisher</servlet-name>
    <url-pattern>/admin/Publish</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>tckDriver</servlet-name>
    <url-pattern>/tck/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>AboutPortlet</servlet-name>
    <url-pattern>/PlutoInvoker/AboutPortlet</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>AdminPortlet</servlet-name>
    <url-pattern>/PlutoInvoker/AdminPortlet</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>PlutoPageAdmin</servlet-name>
    <url-pattern>/PlutoInvoker/PlutoPageAdmin</url-pattern>
  </servlet-mapping>

  <taglib>
    <taglib-uri>http://portals.apache.org/pluto</taglib-uri>
    <taglib-location>/WEB-INF/tld/pluto.tld</taglib-location>
  </taglib>

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>portal</web-resource-name>
      <url-pattern>/portal</url-pattern>
      <url-pattern>/portal/*</url-pattern>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
      <http-method>PUT</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>pluto</role-name>
    </auth-constraint>
  </security-constraint>

  <login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
      <form-login-page>/login.jsp</form-login-page>
      <form-error-page>/login.jsp?error=1</form-error-page>
    </form-login-config>
  </login-config>

  <security-role>
    <role-name>pluto</role-name>
  </security-role>

</web-app>


2012年6月19日火曜日

OpenShiftDIYのTomcat7用server.xml

OpenShiftにDIYアプリケーションを作成し、その中にTomcat7を作ってみた。
その際に設定のキモだったのがTomcatのserver.xmlだったので、その中身を書いておく。

Liferayや他のアプリケーションサーバでもTomcat7なら、このserver.xmlでいけるかもしれない。
でもLiferayはデプロイ設定を変えないとNGだろうな…、OpenShiftはホームディレクトリに書き込み権限が無いからね。
っと思い、試しにOpenShiftDIYにLiferayをセットアップし、走らせた結果…
起動中に「Killed」が出てきてダウンした。
たぶんメモリ不足か何か使用可能リソース制限に触れたのだと思う。
ならばJetspeed2でどうよ、っと思いJetspeed2を試した結果…
Jetspeed2も起動中に「Killed」でダウン。
主要ポートレットコンテナ2つが使用不可なのが残念。
Pluto2.0は動作可能だから、とりあえずはPluto2.0でいいや。

ココの料金ページによると、無料で使えるFreeは、Gear SizesはSmallがデフォルト。
このSmallだとメモリ容量は512 MB RAMだそうな。Mediumだと1 GB RAMだそうな。
Pricing

ココのコミュニティフォーラム記事によると、デフォルトはスモールサイズらしい。
ミディアムサイズにしたければopenshift@redhat.comにメールを送れってことだった。
Cannot deploy Liferay because of PermGen

20120927 Liferayのクイックスタートがあるので、Liferayを作れるかもしれない
openshift / jbossas7-liferay-quickstart

で、本題に戻って…
DIYの中にTomcatを作る方法は、ココ。
Free Apache Tomcat Hosting in the Cloud for Java Applications? It's Called OpenShift!
https://openshift.redhat.com/community/blogs/free-apache-tomcat-hosting-in-the-cloud-for-java-applications-its-called-openshift

20120918 どうやらshutdown設定とajp設定にIPアドレスを入れないと動かないようになったみたいなので、設定追加

で、今回は各設定を下記のようにした前提。
URL = tomcat-yourdomain.rhcloud.com
OPENSHIFT_INTERNAL_IP = 127.6.99.1

[server.xml]

<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="15005" shutdown="SHUTDOWN" address="127.6.99.1" >
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               address="127.6.99.1"
               redirectPort="15443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the JSSE configuration, when using APR, the
         connector should be using the OpenSSL style configuration
         described in the APR documentation -->
    <!--
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="15009" protocol="AJP/1.3" redirectPort="8443" address="127.6.99.1" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="127.6.99.1">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="tomcat-yourdomain.rhcloud.com"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

Pluto2.0用ポートレット設定

Apache Pluto2.0用ポートレットに必要な設定を書いておく。

今回のポートレットはplutoPortletと名づけた。

1.まずportlet.xml。

<?xml version="1.0"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<description>plutoPortlet</description>
<portlet-name>plutoPortlet</portlet-name>
<display-name>plutoPortlet</display-name>
<portlet-class>plutoportlet.MyPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>plutoPortlet</title>
<short-title>plutoPortlet</short-title>
<keywords>plutoPortlet</keywords>
</portlet-info>
</portlet>
</portlet-app>

通常のポートレット用設定だが、 portlet-nameはPluto用にweb.xmlを設定する際、必要になるので注意しとく。

2.次にweb.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <servlet>
        <servlet-name>plutoPortlet</servlet-name>
        <servlet-class>org.apache.pluto.container.driver.PortletServlet</servlet-class>
        <init-param>
            <param-name>portlet-name</param-name>
            <param-value>plutoPortlet</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>plutoPortlet</servlet-name>
        <url-pattern>/PlutoInvoker/plutoPortlet</url-pattern>
    </servlet-mapping>
    <jsp-config>
        <taglib>
            <taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
            <taglib-location>/WEB-INF/portlet_2_0.tld</taglib-location>
        </taglib>
    </jsp-config>
</web-app>
  • 青文字にしたスキーマ設定は、これが無いと/PlutoInvoker/plutoPortletをコールする際にエラーになるので必要。
  • 紫文字にしたクラスは、Pluto2.0でのサーブレット。
    このサーブレットにポートレットをコールしてもらう(らしい)。
  • 赤文字にした設定は、plutoPortletをPlutoに自動認識してもらう為に必要(らしい)。
    ポートレットAP1つごとに、この設定を行う。
    つまり、ポートレットAP追加ごとに、サーブレットとサーブレットマッピングを追加する。
ここまで設定したらplutoPortlet.warファイルにして、pluto-2.0.3/webappsフォルダにデプロイする。
あとはPlutoが自動的に認識してくれる。

3.pluto-2.0.3/conf/Catalina/localhostに置く、plutoPortlet.xml

<Context path="/plutoPortlet" docBase="plutoPortlet"crossContext="true"/>

このファイルが無いと、VIEWモードしか表示しない。
HELPモードやEDITモードが表示できない。

まだ、日本語が文字化けするけど、エンコーディングフィルタを入れれば大丈夫だと思う。
ポートレット側にエンコーディングフィルタ入れてもダメだった。
対策としては、フロント側となるplutoアプリのweb.xmlを修正する必要がある。
内容を書くと長くなるので、別投稿にて詳細説明。