5

私は、Gilberto T. Garcia Jr による Lift アプリケーション開発クックブックに取り組んでいますが、解決できないように見える問題に遭遇しました。ソース コード Chap06-map-table をコピーして、IBM i (iSeries、AS/400、i5) データベースで動作するように変更しようとしています。Squeryl Record を使用した最初のタイプの接続で動作させることができました。ただし、JNDI データソースを使用してこれを機能させる方法がわかりません。これを設定する例をインターネットで検索するのに数日を費やしましたが、DB/400 データベース接続を含む良い例は見つかりませんでした。以下は、コンテナを起動しようとしたときに発生するエラーと、それを機能させるために変更したコードです。どんな助けでも大歓迎です。jt4oo からのデータ ソース クラスにはいくつかの選択肢があるようです。jar (jtOpen) であり、どちらを使用するのが最適か、またはおそらく別のものがあるかどうかはわかりません。私は3つのそれぞれでこれを試してきましたが、最初のものが正しいと仮定しています。

com.ibm.as400.access.AS400JDBCManagedConnectionPoolDataSource
com.ibm.as400.access.AS400JDBCConnectionPoolDataSource
com.ibm.as400.access.AS400JDBCDataSource

ありがとう。ボブ

これはエラーの始まりです:

> container:start
[info] jetty-8.0.4.v20111024
[info] No Transaction manager found - if your webapp requires one, please config
ure one.
[info] NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
[info] started o.e.j.w.WebAppContext{/,[file:/C:/Users/Bob/Lift26Projects/scala_
210/chap06-map-table/src/main/webapp/]}
[info] started o.e.j.w.WebAppContext{/,[file:/C:/Users/Bob/Lift26Projects/scala_
210/chap06-map-table/src/main/webapp/]}
18:21:47.062 [pool-7-thread-1] ERROR n.liftweb.http.provider.HTTPProvider - Fail
ed to Boot! Your application may not run properly
java.sql.SQLException: The application requester cannot establish the connection
. ("jdbc:as400://www.busapp.com;libraries=PLAY2TEST";naming=system;errors=full;)
        at com.ibm.as400.access.JDError.throwSQLException(JDError.java:524) ~[jt
400-6.7.jar:JTOpen 6.7]
        at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConne
ction.java:3142) ~[jt400-6.7.jar:JTOpen 6.7]
        at com.ibm.as400.access.AS400JDBCManagedDataSource.createPhysicalConnect...

私の Build.sbt ファイル:

name := "Lift 2.5 starter template"
version := "0.0.1"
organization := "net.liftweb"
scalaVersion := "2.10.0"
resolvers ++= Seq("snapshots" at "http://oss.sonatype.org/content/repositories/snapshots",
          "staging"         at "http://oss.sonatype.org/content/repositories/staging",
          "releases"        at "http://oss.sonatype.org/content/repositories/releases"
            )
seq(com.github.siasia.WebPlugin.webSettings :_*)
unmanagedResourceDirectories in Test <+= (baseDirectory) { _ / "src/main/webapp" }
scalacOptions ++= Seq("-deprecation", "-unchecked")
env in Compile := Some(file("./src/main/webapp/WEB-INF/jetty-env.xml") asFile)
libraryDependencies ++= {
  val liftVersion = "2.5"
  Seq(
    "net.liftweb"       %% "lift-webkit"        % liftVersion        % "compile",
    "net.liftmodules"   %% "lift-jquery-module_2.5" % "2.3",
    "org.eclipse.jetty"     % "jetty-webapp"       % "8.0.4.v20111024"  % "container",
    "org.eclipse.jetty"     % "jetty-plus"         % "8.0.4.v20111024"  % "container",
    "ch.qos.logback"    % "logback-classic"     % "1.0.6",
    "org.specs2"        %% "specs2"             % "1.14"           % "test",
    "net.liftweb"       %% "lift-squeryl-record" % liftVersion % "compile",
    "net.sf.jt400"    % "jt400"       % "6.7",
    "org.liquibase"    %  "liquibase-maven-plugin" % "3.0.2"
  )
}

これは私の boot.scala ファイルです:

package bootstrap.liftweb

    import _root_.liquibase.database.DatabaseFactory
    import _root_.liquibase.database.jvm.JdbcConnection
    import _root_.liquibase.exception.DatabaseException
    import _root_.liquibase.Liquibase
    import _root_.liquibase.resource.FileSystemResourceAccessor
    import net.liftweb._
    import util._
    import Helpers._
    import common._
    import http._
    import sitemap._
    import Loc._
    import net.liftmodules.JQueryModule
    import net.liftweb.http.js.jquery._
    import net.liftweb.squerylrecord.SquerylRecord
    import org.squeryl.Session
    import java.sql.{SQLException, DriverManager}
    import org.squeryl.adapters.DB2Adapter
    import javax.naming.InitialContext
    import javax.sql.DataSource
    import code.model.LiftBookSchema
    /**
    * A class that's instantiated early and run.  It allows the application
    * to modify lift's environment
    */
    class Boot {
     def runChangeLog(ds: DataSource) {
     val connection = ds.getConnection
       try {
        val database = DatabaseFactory.getInstance().
         findCorrectDatabaseImplementation(new JdbcConnection(connection))
        val liquibase = new Liquibase(
        "database/changelog/db.changelog-master.xml",
        new FileSystemResourceAccessor(),
        database
        )

      liquibase.update(null)
      } catch {
        case e: SQLException => {
         connection.rollback()
         throw new DatabaseException(e)
       }
     }
    }
    def boot {

    // where to search snippet
    LiftRules.addToPackages("code")

    prepareDb()


    // Build SiteMap
    val entries = List(
      Menu.i("Home") / "index", // the simple way to declare a menu

      // more complex because this menu allows anything in the
      // /static path to be visible
      Menu(Loc("Static", Link(List("static"), true, "/static/index"),
        "Static Content")))

    // set the sitemap.  Note if you don't want access control for
    // each page, just comment this line out.
    LiftRules.setSiteMap(SiteMap(entries: _*))

    //Show the spinny image when an Ajax call starts
    LiftRules.ajaxStart =
      Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd)

    // Make the spinny image go away when it ends
    LiftRules.ajaxEnd =
      Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)

    // Force the request to be UTF-8
    LiftRules.early.append(_.setCharacterEncoding("UTF-8"))

    // Use HTML5 for rendering
    LiftRules.htmlProperties.default.set((r: Req) =>
      new Html5Properties(r.userAgent))

    //Init the jQuery module, see http://liftweb.net/jquery for more information.
    LiftRules.jsArtifacts = JQueryArtifacts
    JQueryModule.InitParam.JQuery = JQueryModule.JQuery172
    JQueryModule.init()

  }

  def prepareDb() {

    Class.forName("com.ibm.as400.access.AS400JDBCManagedConnectionPoolDataSource")

    val ds = new InitialContext().lookup("java:/comp/env/jdbc/dsliftbook").asInstanceOf[DataSource]

    runChangeLog(ds)

    SquerylRecord.initWithSquerylSession(
      Session.create(
        ds.getConnection,
        new DB2Adapter)
    )
  }


}

これは私の jetty-env-xml ファイルです

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <New id="dsliftbook" class="org.eclipse.jetty.plus.jndi.Resource">
   <Arg></Arg>
   <Arg>jdbc/dsliftbook</Arg>
   <Arg>
      <New class="com.ibm.as400.access.AS400JDBCManagedConnectionPoolDataSource">
         <Set name="serverName">"jdbc:as400://www.[server].com;libraries=PLAY2TEST";naming=system;errors=full;</Set>
         <Set name="user">[user]</Set>
         <Set name="password">[password]</Set>
       </New>
   </Arg>
    </New>
</Configure>
4

1 に答える 1

1

無事、接続できました。1 つの問題は、jetty-env-xml ファイルの引用符でした。そして、私が使用していたユーザー名/パスワードは、これを機能させるために必要な権限ではなかったようです。これは、すべての iSeries 開発で使用する ID/パスワードと同じであるため、理由はわかりません。したがって、今のところ、何が起こっているか、またはどのような権限が必要かを理解できるまで、セキュリティ担当者の権限を持つ別のユーザー プロファイルになります。

サインオンすると、ユーザーのライブラリー・リストを設定できず、これが原因で SQL が失敗していました。ユーザー ID と同じライブラリー名を探していました。とりあえず、ユーザー ID と同じ名前の新しいライブラリを作成することで、この問題を回避しました。

ここでのもう 1 つの問題は、ID とパスワードの両方を提供しているにもかかわらず、接続する前に ID/パスワードの入力を求められることです。ID と URL は入力されますが、パスワードは常に再入力する必要があります。

jetty-env-xml ファイルと boot.scala ファイルの現在のソースを含めました。うまくいけば、これは他の人を助けるかもしれません。

Dave と James の協力に感謝します。

ボブ

boot.scala:

package bootstrap.liftweb

// import _root_.liquibase.database.DatabaseFactory
// import _root_.liquibase.database.jvm.JdbcConnection
// import _root_.liquibase.exception.DatabaseException
// import _root_.liquibase.Liquibase
// import _root_.liquibase.resource.FileSystemResourceAccessor
import net.liftweb._
import util._
import Helpers._

import common._
import http._
import sitemap._
import Loc._
import net.liftmodules.JQueryModule
import net.liftweb.http.js.jquery._
import net.liftweb.squerylrecord.SquerylRecord
import org.squeryl.Session
import java.sql.{SQLException, DriverManager}
import org.squeryl.adapters.DB2Adapter
import javax.naming.InitialContext
import javax.sql.DataSource
import code.model.LiftBookSchema
import com.ibm.as400.access.AS400JDBCManagedConnectionPoolDataSource



/**
 * A class that's instantiated early and run.  It allows the application
 * to modify lift's environment
 */
class Boot {
  // def runChangeLog(ds: DataSource) {
  //   val connection = ds.getConnection

  //   try {
  //     val database = DatabaseFactory.getInstance().
  //       findCorrectDatabaseImplementation(new JdbcConnection(connection))

  //     val liquibase = new Liquibase(
  //       "database/changelog/db.changelog-master.xml",
  //       new FileSystemResourceAccessor(),
  //       database
  //     )

  //     liquibase.update(null)
  //   } catch {
  //     case e: SQLException => {
  //       connection.rollback()
  //       throw new DatabaseException(e)
  //     }
  //   }
  // }

  def boot {

    // where to search snippet
    LiftRules.addToPackages("code")

    prepareDb()


    // Build SiteMap
    val entries = List(
      Menu.i("Home") / "index", // the simple way to declare a menu

      // more complex because this menu allows anything in the
      // /static path to be visible
      Menu(Loc("Static", Link(List("static"), true, "/static/index"),
        "Static Content")))

    // set the sitemap.  Note if you don't want access control for
    // each page, just comment this line out.
    LiftRules.setSiteMap(SiteMap(entries: _*))

    //Show the spinny image when an Ajax call starts
    LiftRules.ajaxStart =
      Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd)

    // Make the spinny image go away when it ends
    LiftRules.ajaxEnd =
      Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)

    // Force the request to be UTF-8
    LiftRules.early.append(_.setCharacterEncoding("UTF-8"))

    // Use HTML5 for rendering
    LiftRules.htmlProperties.default.set((r: Req) =>
      new Html5Properties(r.userAgent))

    //Init the jQuery module, see http://liftweb.net/jquery for more information.
    LiftRules.jsArtifacts = JQueryArtifacts
    JQueryModule.InitParam.JQuery = JQueryModule.JQuery172
    JQueryModule.init()

  }

  def prepareDb() {

    Class.forName("com.ibm.as400.access.AS400JDBCManagedConnectionPoolDataSource")

    val ds = new InitialContext().lookup("java:/comp/env/jdbc/dsliftbook").asInstanceOf[DataSource]

    // runChangeLog(ds)

    SquerylRecord.initWithSquerylSession(Session.create(ds.getConnection, new DB2Adapter)
    )
  }
}

jetty-env-xml

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <New id="dsliftbook" class="org.eclipse.jetty.plus.jndi.Resource">
   <Arg></Arg>
   <Arg>jdbc/dsliftbook</Arg>
   <Arg>
      <New class="com.ibm.as400.access.AS400JDBCManagedConnectionPoolDataSource">
         <Set name="serverName">www.[server].com</Set>
         <Set name="user">DBUSER</Set>
         <Set name="password">DBUSER</Set>
      </New>
   </Arg>
    </New>
</Configure>
于 2013-12-17T22:36:59.607 に答える