Announcement

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

    Properties file - Any other options

    Isomorphic,

    We defined most of the configuration details in server.properties file. As of now, this server.properties will be inside my war file. I want to place this file into some location in my server rather than placing inside the artifact(inside the context)

    Is there is any way i can differentiate property file such as one for development environment, one for testing etc..

    As we have many instances, plan is to give war file + server.properties(which can be configurable accordingly). Is this can be done? Please direct me.

    Thanks,
    Yathish

    #2
    You can use spring to inject properties file from anywhere in the classpath.

    Comment


      #3
      server.properties will be loaded from anywhere in the classpath, and properties can be dynamically defined using the Config class. If you prefer to manage things at the file level, handle inclusion of different files into different builds via 'ant' or whatever build system you're using.

      Comment


        #4
        isomorphic,

        is it possible to set the values of server.properties file by reading other files? if so please let me know.
        My thought process is, depending on the environment, i can set the properties of server.properties file.

        or is there is a way to have more than one server.properties file for all kind of environment and specify in the build to take the appropriate server.properties file depending on the environment?

        Please let me know.

        Thanks,
        Yathish

        Comment


          #5
          You can use the server-side Config class to programmatically inject properties that you load from other files.

          Comment


            #6
            can i get some sample example to implement this? please redirect to some link if you know.

            Comment


              #7
              Config.getGlobal().put("propertyName", "value")

              Comment


                #8
                Thanks for this.

                I have a property sql.Oracle.driver.serverName in my server.properties. Shall i delete this and assign the appropriate value through DMI?

                As these properties are must, this one would be the first DMI of any application is it? which is the better approach to handle my scenario(load servername as per the environment like dev/test/prod)

                JNDI or by loading properties through DMI?

                Comment


                  #9
                  You haven't shared anything about why this property is being injected dynamically so we can't offer much specific advice, except to say, you would only insert this via DMI if the database config is highly dynamic, such as differing based on the logged-in user.

                  If you're just trying to keep passwords out of the filesystem or similar, you'd generally make the calls from a load-on-startup servlet that runs right after the Init servlet. Or use JNDI.

                  Comment


                    #10
                    Finally I am going with JNDI. Reason being, we have different stages and we dont want to change server.properties file each stage.

                    Here is my changes.
                    Code:
                    <Resource name="jdbc/MIDatabase" type="javax.sql.DataSource"
                        auth="Container"
                        username="abc" password="abc"
                        driverClassName="oracle.jdbc.driver.OracleDriver"
                        url="jdbc:oracle:thin:@valid URL"/>
                    and

                    Code:
                    sql.Oracle.driver.name: java:comp/env/jdbc/MIDatabase
                    sql.Oracle.database.type: oracle
                    sql.Oracle.interface.credentialsInURL: false
                    sql.Oracle.driver.driverType: thin
                    sql.Oracle.driver.networkProtocol: tcp
                    sql.Oracle.driver.portNumber: 1521
                    sql.Oracle.useURL: true
                    sql.Oracle.driver: oracle.jdbc.pool.OracleDataSource
                    sql.Oracle.autoJointTransactions: true
                    sql.Oracle.interface.type: jndi

                    But still i am getting some error as show below.

                    Code:
                    === 2012-04-05 17:29:46,442 [80-3] DEBUG PoolableSQLConnectionFactory - [builtinApplication.retrieveClientID] Initializing SQL config for 'Oracle' via JNDI
                    === 2012-04-05 17:29:46,449 [80-3] ERROR SQLConnectionManager - [builtinApplication.retrieveClientID] Caught exception
                    javax.naming.NameNotFoundException: Name java:comp is not bound in this Context
                    	at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
                    	at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
                    	at com.isomorphic.sql.PoolableSQLConnectionFactory.makeUnpooledObject(PoolableSQLConnectionFactory.java:267)
                    	at com.isomorphic.sql.PoolableSQLConnectionFactory.makeObject(PoolableSQLConnectionFactory.java:340)
                    	at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1148)
                    	at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:74)
                    	at com.isomorphic.sql.SQLConnectionManager.getConnection(SQLConnectionManager.java:156)
                    	at com.isomorphic.sql.SQLDriver.getTransformedResults(SQLDriver.java:310)
                    	at com.isomorphic.sql.SQLDriver.executeQuery(SQLDriver.java:626)
                    	at com.isomorphic.sql.SQLDataSource.executeNativeQuery(SQLDataSource.java:391)
                    	at com.isomorphic.sql.SQLDataSource.executeNativeQuery(SQLDataSource.java:385)
                    	at com.isomorphic.sql.SQLDataSource.SQLExecute(SQLDataSource.java:1316)
                    	at com.isomorphic.sql.SQLDataSource.processRequest(SQLDataSource.java:293)
                    	at com.isomorphic.sql.SQLDataSource.executeFetch(SQLDataSource.java:237)
                    	at com.isomorphic.datasource.DataSource.execute(DataSource.java:1289)
                    	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:1948)
                    	at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:199)
                    	at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:156)
                    	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:121)
                    	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:73)
                    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
                    	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
                    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                    	at com.sun.identity.agents.filter.AmAgentBaseFilter.allowRequestToContinue(AmAgentBaseFilter.java:131)
                    	at com.sun.identity.agents.filter.AmAgentBaseFilter.doFilter(AmAgentBaseFilter.java:76)
                    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
                    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
                    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
                    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
                    	at java.lang.Thread.run(Thread.java:619)

                    Let me know how can we avoid this?

                    Comment


                      #11
                      Looks like your <Resource> declaration does not cause the JNDI connection to be registered under the name you're using for sql.Oracle.driver.name. The actual JNDI path can differ by container - see your container's docs.

                      Comment


                        #12
                        Thanks for the reply.

                        Here is my next question.

                        We have 2 environments(Dev and prod) and i am planning to have 2 server.properties like dev.server.properties and prod.server.properties.

                        In my catalina.sh i will set whether it is dev or prod by passing an environment variable. Can we load {$server-env}.server.properties file? If so how can we load?

                        Altogether, we need to load environment specific server.properties file based on $server-env.

                        Let me know how can we achieve this.

                        Thanks,
                        Yathish

                        Comment


                          #13
                          If you want to do this, you need to load the .properties files with your own Java code. There are some Properties-related utility classes in the JDK. Apply the properties via Config.put().

                          Comment


                            #14
                            Originally posted by Isomorphic View Post

                            If you're just trying to keep passwords out of the filesystem or similar, you'd generally make the calls from a load-on-startup servlet that runs right after the Init servlet.
                            Could you please point me to the documentation on how to specify/create my own load-on-startup servlet so that I can programmatically alter server properties? Or better yet provide a code snippet.

                            Comment


                              #15
                              Originally posted by dbscott525 View Post
                              Could you please point me to the documentation on how to specify/create my own load-on-startup servlet so that I can programmatically alter server properties? Or better yet provide a code snippet.
                              Answer to my own question and to help others.

                              Something like this goes in web.xml:

                              Code:
                              <servlet>
                                  <servlet-name>LoadOnStartupServlet</servlet-name>
                                  <display-name>LoadOnStartupServlet</display-name>
                                  <servlet-class>com.cedarcone.MVP1.server.LoadOnStartupServlet</servlet-class>
                                  <load-on-startup>1</load-on-startup>
                              </servlet>
                              Here is a sample servlet code with the config call:

                              Code:
                              import java.io.IOException;
                              import java.io.PrintWriter;
                              
                              import javax.servlet.ServletException;
                              import javax.servlet.http.HttpServlet;
                              import javax.servlet.http.HttpServletRequest;
                              import javax.servlet.http.HttpServletResponse;
                              
                              import com.isomorphic.base.Config;
                              
                              public class LoadOnStartupServlet extends HttpServlet {
                              
                              	private static final long serialVersionUID = -7712949313915129282L;
                              
                              	public void init() throws ServletException {
                              		System.err.println("Mesage at Startup");
                              	}
                              
                              	public void doGet(HttpServletRequest request, HttpServletResponse response)
                              			throws ServletException, IOException {
                              		Config.getGlobal().put("propertyName", "value");
                              		response.setContentType("text/html");
                              		PrintWriter pw = response.getWriter();
                              		pw.println("<b>Message to the Client</b>");
                              		pw.close();
                              	}
                              
                              	public void doPost(HttpServletRequest request, HttpServletResponse response)
                              			throws ServletException, IOException {
                              		doGet(request, response);
                              	}
                              }

                              Comment

                              Working...
                              X