Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Externalize server.properties

    I would like to move server.properties outside of the .war file. Is there a way to do this?

    The goal is to be able to distribute the war file without the database configuration built into it.

    Thanks.

    #2
    The way to do is this to use JNDI-based configuration in server.properties (see the Admin Console) such that Connections are vended by the container and only the container knows the connection settings.

    Comment


      #3
      Thanks.

      I can setup JNDI in the app server. Is there any documentation on how to configue JNDI data sources in the eclipse plugin server?

      Comment


        #4
        On the SmartGWT side, use the Admin Console. For Eclipse/JNDI, refer to Eclipse documentation.

        Comment


          #5
          I am facing a similar problem using the JNDI datasource. There must be a trivial setting that must be missing. Perhaps the way the JNDI name is specified or some properties that are not required. Could you please help.


          1. I am using Jetty-env.xml to configure the JNDI datasource to my database. Added the resource-ref in the web.xml. I have confirmed it works since the rest of the application has no problem accessing it. These include some JPA datasources (.ds.xml) that have no problem fetching the data.


          2. The web.xml has the resource-ref information

          <resource-ref>
          <res-ref-name>jdbc/myDb</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
          </resource-ref>



          3. I changed the server.properties
          sql.myDb.interface.credentialsInURL: true
          sql.myDb.database.type: mysql
          sql.myDb.interface.type: jndi
          sql.myDb.driver.networkProtocol: tcp
          sql.myDb.autoJoinTransactions: true
          sql.myDb.driver.serverName: localhost
          sql.myDb.pool.enabled: false
          sql.myDb.driver.context: _container_
          sql.myDb.driver.driverType: thin
          sql.myDb.name: jdbc/myDb

          Getting a NullPointerException

          === 2010-07-08 11:02:18,769 [p0-3] DEBUG PoolableSQLConnectionFactory - [builtinApplication.menuInfo_fetch] Initializing SQL config for 'myDb' via JNDI
          === 2010-07-08 11:02:18,770 [p0-3] DEBUG JNDI - [builtinApplication.menuInfo_fetch] No configuration for JNDI context - assuming default initialContext
          === 2010-07-08 11:02:18,771 [p0-3] ERROR SQLConnectionManager - [builtinApplication.menuInfo_fetch] Caught exception
          java.lang.NullPointerException
          at javax.naming.InitialContext.getURLScheme(InitialContext.java:228)
          at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:277)
          at javax.naming.InitialContext.lookup(InitialContext.java:351)
          at com.isomorphic.sql.PoolableSQLConnectionFactory.makeUnpooledObject(PoolableSQLConnectionFactory.java:229)
          at com.isomorphic.sql.PoolableSQLConnectionFactory.makeObject(PoolableSQLConnectionFactory.java:297)
          at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:974)
          at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:72)
          at com.isomorphic.sql.SQLConnectionManager.getConnection(SQLConnectionManager.java:150)
          at com.isomorphic.sql.SQLDriver.getTransformedResults(SQLDriver.java:282)
          at com.isomorphic.sql.SQLDriver.executeQuery(SQLDriver.java:516)
          at com.isomorphic.sql.SQLDataSource.executeNativeQuery(SQLDataSource.java:332)
          at com.isomorphic.sql.SQLDataSource.executeNativeQuery(SQLDataSource.java:327)
          at com.isomorphic.sql.SQLDataSource.SQLExecute(SQLDataSource.java:1144)
          at com.isomorphic.sql.SQLDataSource.execute(SQLDataSource.java:248)
          at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:721)
          at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:658)
          at com.isomorphic.application.AppBase.execute(AppBase.java:491)
          at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1336)
          at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:155)
          at com.opengambit.spms.server.datasource.DataSourceServlet.handleDSRequest(DataSourceServlet.java:45)
          at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:106)
          at com.isomorphic.servlet.IDACall.doPost(IDACall.java:54)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
          at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
          at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
          at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:364)
          at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:219)
          at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
          at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:786)
          at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:431)
          at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
          at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:113)
          at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
          at org.mortbay.jetty.Server.handle(Server.java:325)
          at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:533)
          at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:870)
          at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:657)
          at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
          at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:391)
          at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:421)
          at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:497)
          === 2010-07-08 11:02:18,773 [p0-3] WARN RequestContext - dsRequest.execute() failed:
          java.sql.SQLException: java.lang.NullPointerException
          at com.isomorphic.sql.SQLConnectionManager.getConnection(SQLConnectionManager.java:175)
          at com.isomorphic.sql.SQLDriver.getTransformedResults(SQLDriver.java:282)
          at com.isomorphic.sql.SQLDriver.executeQuery(SQLDriver.java:516)
          at com.isomorphic.sql.SQLDataSource.executeNativeQuery(SQLDataSource.java:332)
          at com.isomorphic.sql.SQLDataSource.executeNativeQuery(SQLDataSource.java:327)
          at com.isomorphic.sql.SQLDataSource.SQLExecute(SQLDataSource.java:1144)
          at com.isomorphic.sql.SQLDataSource.execute(SQLDataSource.java:248)
          at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:721)
          at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:658)
          at com.isomorphic.application.AppBase.execute(AppBase.java:491)
          at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1336)
          at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:155)
          at com.opengambit.spms.server.datasource.DataSourceServlet.handleDSRequest(DataSourceServlet.java:45)
          at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:106)
          at com.isomorphic.servlet.IDACall.doPost(IDACall.java:54)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
          at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
          at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
          at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:364)
          at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:219)
          at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
          at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:786)
          at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:431)
          at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
          at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:113)
          at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
          at org.mortbay.jetty.Server.handle(Server.java:325)
          at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:533)
          at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:870)
          at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:657)
          at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
          at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:391)
          at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:421)
          at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:497)



          4. I used the showcase.war on Tomcat and used the Admin Console. It throws a NullPointerException as well when I switch from DataSource or to JNDI.
          ex:
          Database Name: myDb
          Database Type: mysql
          JNDI Name: jdbc/myDb

          (I added the showcase.xml with JNDI information to $CATALINA_HOME/conf/Catalina/localhost/showcase.xml and updated the web.xml )

          Tomcat Console:

          === 2010-07-08 10:12:08,969 [80-4] DEBUG BuiltinRPC - Testing DB connection for database: myDb with config: {
          "driver.portNumber":"3306",
          "interface.type":"jndi",
          "driver.networkProtocol":"tcp",
          "database.type":"mysql",
          "interface.credentialsInURL":"true",
          driver:"com.mysql.jdbc.jdbc2.optional.MysqlDataSou rce",
          "driver.user":"root",
          "driver.databaseName":"myDb",
          "driver.driverType":"thin",
          "driver.password":"password",
          "driver.context":"_container_",
          autoJoinTransactions:"true",
          dbName:"myDb",
          "pool.enabled":"false",
          "driver.serverName":"localhost",
          dbStatus:"Unable to connect",
          _selection_3:true,
          name:"jdbc/myDb"
          }

          Comment


            #6
            Hello akiran,

            The likely problem is that the actual JNDI name that must be used with the JNDI lookup interfaces differs in some way from the JNDI name you put in web.xml, such as a prefix or suffix like "jndi:". Or, perhaps Jetty doesn't like the slash character. We'd recommend renaming without the slash and trying a few plausible prefixes and consulting Jetty documentation.

            If that doesn't work, try accessing the JNDI DataSource via the JNDI API directly; if you can get that to work and think we might have a bug in how SmartGWT is using the API, please let us know.

            Comment


              #7
              Thanks for the quick response. My spring configuration has a lookup for the datasource using the slashes.

              <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/myDb" />

              I am pretty certain the resource is available because Jetty is displaying the message:
              Already bound jdbc/spmsdb to java:comp/env with java:comp/env/jdbc/spmsdb


              I am still wondering if the server.properties is the correct way of providing the JNDI name.
              sql.myDb.name: java:comp/env/jdbc/myDb

              Comment


                #8
                Tried using standard JNDI APIs


                try {
                Context ctx = new InitialContext();
                DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/myDb");
                Connection connection = dataSource.getConnection();
                System.out.println("Connection Successful.");
                System.out.println("Driver: "+ connection.getMetaData().getDriverName());
                System.out.println("Version:" + connection.getMetaData().getDriverMajorVersion()+"."+connection.getMetaData().getDriverMinorVersion());
                System.out.println("Catalog: " + connection.getCatalog());

                } catch (Exception ex) {
                ex.printStackTrace();
                }

                Response:
                Connection Successful.
                Driver: MySQL-AB JDBC Driver
                Version:5.1
                Catalog: myDb

                Comment


                  #9
                  Which variations of the name have you tried in the Admin Console? Try with/without the "java:" prefix, and if possible, try a name without any "/" characters.

                  Comment


                    #10
                    Admin Console:
                    java:comp/env/jdbc/myDb
                    jndi:comp/env/jdbc/myDb
                    java:comp/env/myDb
                    jndi:comp/env/myDb
                    myDb
                    None of them worked.


                    This is the Tomcat context in conf/Catalina/localhost/showcase.xml

                    <Context path="/showcase" debug="99" reloadable="true"
                    antiJARLocking="true" antiResourceLocking="false">
                    <Resource name="myDb"
                    type="javax.sql.DataSource"
                    url="jdbc:mysql://localhost/myDb"
                    driverClassName="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
                    username="root"
                    password="password"
                    />
                    </Context>

                    Comment


                      #11
                      It looks like your closing the context twice with the forward slash

                      Comment


                        #12
                        At this point it seems very likely that the Admin Console and/or your application is not running in the same Jetty context where you ran your test code. The JNDI lookup code we use looks just like yours except that it will actually fall back and try variations - at least 3 of your settings should have worked.

                        If you open the SQLDataSource Wizard in Visual Builder, do you see your JNDI names? That's another place we autodetect JNDI DataSources.

                        Comment

                        Working...
                        X