2013-12-16 3 views
5

Ich arbeite mich durch das Lift Application Development Cookbook von Gilberto T. Garcia Jr. und bin dabei auf ein Problem gestoßen, das ich nicht lösen kann. Ich habe den Quellcode Chap06-map-table kopiert und ich versuche ihn so zu modifizieren, dass er mit meiner IBM i (iSeries, AS/400, i5) Datenbank funktioniert. Ich konnte es mit der ersten Verbindungsart mit Squeryl Record arbeiten lassen. Allerdings kann ich nicht herausfinden, wie man dies mithilfe einer JNDI-Datenquelle zum Laufen bringt. Ich habe ein paar Tage damit verbracht, das Internet nach Beispielen zu durchsuchen, um dies einzurichten, und habe kein gutes Beispiel für eine DB/400-Datenbankverbindung gefunden. Unten ist der Fehler, den ich erhalte, wenn ich versuche, den Container und den Code, den ich geändert habe, zu starten, damit es funktioniert. Jede Hilfe wäre willkommen. Es scheint einige Auswahlmöglichkeiten für die Datenquellenklasse von jt4oo.jar (jtOpen) zu geben, und ich bin mir nicht sicher, welche die beste wäre oder vielleicht eine andere. Ich habe das mit jedem der drei versucht und nehme an, dass der erste der richtige ist.Der Anforderer kann die Verbindung nicht herstellen. Jetty, Lift/Scala, iSeries DB2/400

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

Danke. Bob

Dies ist der Beginn des Fehlers:

> 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... 

Mein Build.sbt Datei:

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" 
) 
} 

Das ist mein boot.scala Datei:

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) 
    ) 
    } 


} 
Dies ist

mein Anlegesteg-env-XML-Datei

<!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> 
+2

Sie bekommen eine SQLException aus dem JDBC-Treiber zu sagen Sie, dass es nicht mit der Datenbank verbinden kann. Überprüfen Sie, ob Ihre URL, Benutzername und Passwort korrekt sind. Wenn sie richtig aussehen, versuchen Sie, von dem Computer aus, auf dem Ihre App läuft, eine Verbindung zum Server herzustellen, ohne Java zu verwenden, und prüfen Sie, ob das erfolgreich ist. Möglicherweise finden Sie auch weitere Informationen darüber, warum die Datenbank Verbindungen in den DB-Protokollen verweigert. –

+0

Das Zitat scheint in Ihrer Datenbank uri verlegt zu sein: '" jdbc: as400: // www. [Server] .com; libraries = PLAY2TEST "; naming = system; fehler = voll;' sollte '" jdbc: as400: // www. [server] .com; libraries = PLAY2TEST; naming = system; fehler = voll; "' – jamesallman

+0

Ich habe das Zitat korrigiert, tatsächlich wurden sie komplett entfernt. Funktioniert immer noch nicht. Für eine Nicht-Datenquellenverbindung funktioniert das Folgende. 'Import org.squeryl.Session Import org.squeryl.adapters.DB2Adapter Import net.liftweb.squerylrecord.SquerylRecord Class.forName ("com.ibm.as400.access.AS400JDBCDriver") def connection = Driver. getConnection ("jdbc: as400: // www. {Server] .com /; Benennung = 1; Bibliotheken = PLAY2TEST;", "[Benutzer]", "[Kennwort]") SquerylRecord.initWithSquerylSession (Session.create (Verbindung, neue DB2Adapter)) ' –

Antwort

1

Okay, ich habe es geschafft, verbunden werden. Ein Problem waren die Anführungszeichen in der Datei jetty-env-xml. Und der Benutzername/das Passwort, das ich verwendet habe, hat anscheinend nicht die Autorität, die erforderlich ist, um das zu funktionieren. Ich bin mir nicht sicher, warum dies die gleiche ID/das gleiche Passwort ist, das ich für meine gesamte iSeries-Entwicklung verwende. Im Moment bin ich ein anderes Benutzerprofil mit der Befugnis des Sicherheitsbeauftragten, bis ich herausfinden kann, was passiert oder welche Behörden benötigt werden.

Sobald ich angemeldet war, konnte ich keine Bibliotheksliste für den Benutzer festlegen, was dazu führte, dass SQL fehlschlug. Es suchte nach einem Bibliotheksnamen, der mit der Benutzer-ID identisch war. Zurzeit habe ich dieses Problem gelöst, indem ich eine neue Bibliothek erstellt habe, die genauso heißt wie die Benutzer-ID.

Ein anderes Problem hier ist, dass, obwohl ich sowohl die ID als auch das Passwort liefere, ich aufgefordert werde, die ID/das Passwort einzugeben, bevor es eine Verbindung herstellt. Die ID und die URL sind ausgefüllt, aber das Passwort muss immer neu eingegeben werden.

Ich habe die aktuelle Quelle für die Datei jetty-env-xml und die Datei boot.scala aufgenommen. Hoffentlich kann das anderen helfen.

Danke an Dave und James für ihre Hilfe!

Bob

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) 
    ) 
    } 
} 

Anlegesteg-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> 
+0

Ich konnte auch als QUSER anmelden. Es scheint etwas anderes in meinem Profil zu sein, das mich davon abhielt, es zu benutzen, um mich anzumelden. –

Verwandte Themen