« プリンタ故障 | トップページ | NetBeans でパッケージ作成:REST(2) »

2015年2月19日 (木)

サーバの REST 化に挑戦 〜 まずは OS X で WildFly 8.2.1 を起動する

当院の OpenDolphin はバージョン 1.3.0 ベースで,JBoss Application Server との通信に Java RMI (Remote Method Invocation) を使っている。最新の本家バージョンと増田先生バージョンは REST (Representational State Transfer) という仕組みを使うように変更されている。どうやら REST は http プロトコルを使うので,iPad からアクセスしたりできて,クライアントの自由度が上がるようだ。当院では RMI で特に困ってはいなかったのであるが,興味があったので REST 化に挑戦してみた。REST 化に際して,増田先生の 2.3m を参考にさせて頂いた。できたソースは Bitbucket さんで公開している。
まずは開発環境整備のため,mac で WildFly 8.2.1 を NetBeans から起動できるように設定するところから始めた。

Postgres の準備

postgres は Server.app を購入して,プログラミングの時だけ手動で起動するように設定した

WildFly 8.2.1 の準備

JBoss AS は現在は WildFly という名前になっている。
  • WIldFly の GitHub から branch 8.x を選択して "Download Zip" して解凍する。作業時点ではこれで 8.2.1.Final がダウンロードされた。
  • nekop 様のブログを参考にビルド開始。
    $ mvn -T4 clean install -DskipTests
     :
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 04:42 min (Wall Clock)
    [INFO] Finished at: 2015-01-30T20:08:10+09:00
    [INFO] Final Memory: 474M/2888M
    [INFO] ------------------------------------------------------------------------
    
    build/target/wildfly-8.2.1.Final-SNAPSHOT ができる。これを /Applications に持っていく。
  • /Applications/wildfly-8.2.1.FinalーSNAPSHOT/bin に移動して 起動してみる。
    $ ./standalone.sh -b 0.0.0.0
    =========================================================================
      JBoss Bootstrap Environment
      JBOSS_HOME: /Applications/wildfly-8.2.1.Final-SNAPSHOT
      JAVA: /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java
      JAVA_OPTS:  -server -XX:+UseCompressedOops  -server -XX:+UseCompressedOops -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true
    =========================================================================
      :
    15:30:03,780 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.2.1.Final-SNAPSHOT "Tweek" started in 9972ms - Started 450 of 503 services (92 services are lazy, passive or on-demand)
    
  • 管理ユーザ登録
    ./add-user.sh する。
    $ ./add-user.sh
    What type of user do you wish to add?
     a) Management User (mgmt-users.properties)
     b) Application User (application-users.properties)
    (a):
    Enter the details of the new user to add.
    Using realm 'ManagementRealm' as discovered from the existing property files.
    Username : user
    Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
     - The password should not be one of the following restricted values {root, admin, administrator}
     - The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
     - The password should be different from the username
    Password : xxxx
    Re-enter Password : xxxx
    What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]:
    About to add user 'user' for realm 'ManagementRealm'
    Is this correct yes/no? yes
    Added user 'user' to file '/Applications/wildfly-8.2.1.Final-SNAPSHOT/standalone/configuration/mgmt-users.properties'
    Added user 'user' to file '/Applications/wildfly-8.2.1.Final-SNAPSHOT/domain/configuration/mgmt-users.properties'
    Added user 'user' with groups  to file '/Applications/wildfly-8.2.1.Final-SNAPSHOT/standalone/configuration/mgmt-groups.properties'
    Added user 'user' with groups  to file '/Applications/wildfly-8.2.1.Final-SNAPSHOT/domain/configuration/mgmt-groups.properties'
    Is this new user going to be used for one AS process to connect to another AS process?
    e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
    yes/no? yes
    To represent the user add the following to the server-identities definition 
    
  • JDBC の登録。JDBC 41 ドライバ(postgresql-9.4-1200.jdbc41.jar)をダウンロードする。ダウンロードした JDBC を登録し,それを使った Datasource (DolphinDS) を作成する。
    $ ./jboss-cli.sh --connect
    [standalone@localhost:9990 /] module add --name=org.postgres --resources=~/Downloads/postgresql-9.4-1200.jdbc41.jar --dependencies=javax.api,javax.transaction.api
    [standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
    {"outcome" => "success"}
    [standalone@localhost:9990 /] data-source add --jndi-name=java:jboss/datasouces/DolphinDS --name=DolphinDS --connection-url=jdbc:postgresql://localhost/dolphin --driver-name=postgres --user-name=dolphin
    [standalone@localhost:9990 /] quit
    
  • Datasource がセットされているのをブラウザで確認。
    http://localhost:9990/console にアクセスし,登録したユーザでログイン,Configuration > Datasources とクリック
  • ちなみに,ログの設定方法。
    [standalone@localhost:9990 /] /subsystem=logging/root-logger=ROOT:write-attribute(name=level,value=DEBUG)
    
    SQL を表示させるには
    [standalone@localhost:9990 /] /subsystem=logging/logger=org.hibernate.SQL:add(level=INFO)
    
    元に戻すには
    [standalone@localhost:9990 /] /subsystem=logging/logger=org.hibernate.SQL:change-log-level(level=INFO)
    
    WildFly の設定はこれで終了。^C で WildFly を終了する。zip で固めて他の環境へ持って行けるようにしておく。

NetBeans 8.0.2 で WildFly 起動

  • サービス > サーバ と選択し,右クリックから「サーバの追加」を選択,WildFly アプリケーションサーバを選択。
  • サーバの場所を指定,構成は standalone.xml にする。
  • 右クリック > 起動で,NetBeans から WildFly が起動される

« プリンタ故障 | トップページ | NetBeans でパッケージ作成:REST(2) »

OpenDolphin」カテゴリの記事