Re: Flexible way of defining application variables in text format?
On 9/29/05, matador [EMAIL PROTECTED] wrote: Leon Rosenberg [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: now how exactly writing a thread which polls the db is less messy, than writing a thread that polls a file? regards leon no need for threads with db. change the val in the db then the next time the page loads, the new value is there. one can get the val from the db however they wish (presentation layer, service, dao, etc) First: you can load your property files on each request as well. Second: you ever tried to request same value from db on each request, which would mean in our case 100 times per second per webserver? Which db is able to serve it? regards leon - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flexible way of defining application variables in text format?
Leon Rosenberg [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: First: you can load your property files on each request as well. really, using what? im curious -- struts and regular properties files out of the box dont support that behaviour, so you would have to 'roll your own' i think. ive seen several different impls, what are you using? Second: you ever tried to request same value from db on each request, which would mean in our case 100 times per second per webserver? Which db is able to serve it? that seems a bit high, but maybe you're working on bigger stuff. its not an issue with my stuff, much smaller apps etc. but as an alternative for smaller apps, you could just stick it in a data structure and use some sort of cache manager to handle it i think (e.g, oscache from opensymphony). - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Re: Flexible way of defining application variables in text format?
From: news [mailto:[EMAIL PROTECTED] On Behalf Of matador Subject: Re: Flexible way of defining application variables in text format? First: you can load your property files on each request as well. really, using what? Try the java.util.Properties.load() method. You can check the lastModified() time stamp on the underlying file first to bypass the reload, if desired. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flexible way of defining application variables in text format?
database. using props files you have to bounce the app to get changes to take effect unless you write your own properties loader that runs as a thread, or checks file timestamps, etc. imo, its all too messy, db based config is far superior now how exactly writing a thread which polls the db is less messy, than writing a thread that polls a file? regards leon - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flexible way of defining application variables in text format?
Leon Rosenberg [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: now how exactly writing a thread which polls the db is less messy, than writing a thread that polls a file? regards leon no need for threads with db. change the val in the db then the next time the page loads, the new value is there. one can get the val from the db however they wish (presentation layer, service, dao, etc) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[OT] RE: Flexible way of defining application variables in text format?
Hi, Just enter your variables into a text file called abc.properties with name/value pairs, e.g var1=val1 var2=val2 Although these will not automatically appear in application scope. You will need to write a tiny Servlet that you configure in web.xml, pass the filename as a servlet parameter, and set the servlet to load-on-startup=1. In your servlet, retrieve the filename and load the properties into a HashMap. Finally add it to the servlet context. Your application can now use the map from application scope, and better still, you can use it in JSTL syntax with $applicationScope.myprops['var1'] There are other ways but this is my recommended way. Allistair. -Original Message- From: Seak, Teng-Fong [mailto:[EMAIL PROTECTED] Sent: 27 September 2005 09:37 To: Tomcat Users List Subject: Flexible way of defining application variables in text format? My webapp needs some application string variables for configuration. For the moment, I hard-code them as class static properties and compiled. But I'd like to know if there's any method to define such variables in a text file, something like the global.asa in ASP where we could simply write something like this withing the application_onstart subroutine: application(myvar) = my value I like them to be withing text file because if even there's a need to change config, I'd like to just launch a text editor, edit it and start again! I don't want to install Eclipse or other IDE in deployment server just in case we need to change some parameter and have to compile everything. This is very inconvenient, non professional and stupid. And the client would probably not appreciate this. OK, I know I could write a wrapper function to parse that text file and assign the correct values, but is there a simpler way? Is the answer lying in the web.xml file? But its syntax seems quite complicated that I've no idea what to begin. TIA - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] FONT SIZE=1 FACE=VERDANA,ARIAL COLOR=BLUE --- QAS Ltd. Registered in England: No 2582055 Registered in Australia: No 082 851 474 --- /FONT FONT SIZE=1 FACE=VERDANA,ARIAL COLOR=BLACK Disclaimer: The information contained within this e-mail is confidential and may be privileged. This email is intended solely for the named recipient only; if you are not authorised you must not disclose, copy, distribute, or retain this message or any part of it. If you have received this message in error please contact the sender at once so that we may take the appropriate action and avoid troubling you further. Any views expressed in this message are those of the individual sender. QAS Limited has the right lawfully to record, monitor and inspect messages between its employees and any third party. Your messages shall be subject to such lawful supervision as QAS Limited deems to be necessary in order to protect its information, its interests and its reputation. Whilst all efforts are made to safeguard Inbound and Outbound emails, QAS Limited cannot guarantee that attachments are virus free or compatible with your systems and does not accept any liability in respect of viruses or computer problems experienced. /FONT
RE: Flexible way of defining application variables in text format?
To make this easier in the presentation tier, you would probably want to make this method a static member of some class (if using scriplet), or a tag if attempting a non-scripted presentation tier (recommended). Allistair. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 27 September 2005 09:50 To: tomcat-user Subject: Re:Flexible way of defining application variables in text format? in web.xml u can set all the constants u want as: env-entry env-entry-namenameVariavle/env-entry-name env-entry-valuevalueVariable/env-entry-value env-entry-typejava.lang.String or whatelse/env-entry-type /env-entry and use this for getting them public static String getEnvVar(String name) throws NamingException { String var=; try { Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup( java:comp/env ); var = (String) envCtx.lookup( name ); } catch (NamingException e) { e.printStackTrace(); } return var; } regards!! -- Initial Header --- From : Seak, Teng-Fong [EMAIL PROTECTED] To : Tomcat Users List tomcat-user@jakarta.apache.org Cc : Date : Tue, 27 Sep 2005 10:36:30 +0200 Subject : Flexible way of defining application variables in text format? My webapp needs some application string variables for configuration. For the moment, I hard-code them as class static properties and compiled. But I'd like to know if there's any method to define such variables in a text file, something like the global.asa in ASP where we could simply write something like this withing the application_onstart subroutine: application(myvar) = my value I like them to be withing text file because if even there's a need to change config, I'd like to just launch a text editor, edit it and start again! I don't want to install Eclipse or other IDE in deployment server just in case we need to change some parameter and have to compile everything. This is very inconvenient, non professional and stupid. And the client would probably not appreciate this. OK, I know I could write a wrapper function to parse that text file and assign the correct values, but is there a simpler way? Is the answer lying in the web.xml file? But its syntax seems quite complicated that I've no idea what to begin. TIA - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] FONT SIZE=1 FACE=VERDANA,ARIAL COLOR=BLUE --- QAS Ltd. Registered in England: No 2582055 Registered in Australia: No 082 851 474 --- /FONT FONT SIZE=1 FACE=VERDANA,ARIAL COLOR=BLACK Disclaimer: The information contained within this e-mail is confidential and may be privileged. This email is intended solely for the named recipient only; if you are not authorised you must not disclose, copy, distribute, or retain this message or any part of it. If you have received this message in error please contact the sender at once so that we may take the appropriate action and avoid troubling you further. Any views expressed in this message are those of the individual sender. QAS Limited has the right lawfully to record, monitor and inspect messages between its employees and any third party. Your messages shall be subject to such lawful supervision as QAS Limited deems to be necessary in order to protect its information, its interests and its reputation. Whilst all efforts are made to safeguard Inbound and Outbound emails, QAS Limited cannot guarantee that attachments are virus free or compatible with your systems and does not accept any liability in respect of viruses or computer problems experienced. /FONT - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flexible way of defining application variables in text format?
On Tuesday 27 September 2005 15:36, Seak, Teng-Fong wrote: My webapp needs some application string variables for configuration. For the moment, I hard-code them as class static properties and compiled. But I'd like to know if there's any method to define such variables in a text file, something like the global.asa in ASP where we could simply write something like this withing the application_onstart subroutine: application(myvar) = my value any better idea than this one ? without modification web.xml :-D this is example to to read - import lib.ConfLineSeparator; ... ... ConfLineSeparator c = new ConfLineSeparator(/whereis/thefile/file.conf); out.println(c.getConf(dbPwd,VALUEifMissing)); ... ... this is example data file /whereis/thefile/file.conf -- #CONFig Text Mode, #Place many Configuration here #Format is : property=value or property = value #there is no SPACE, space is WASTE of String :-p #value is value not value or 'value' #all Chars are case sensitive #Add # char to comment # Db Conf dbPwd=secret Try this API Class file - package lib; import java.io.*; import java.util.Vector; public class ConfLineSeparator { String[] all; int i=0; String currentProp, currentVal; Vector p; Vector v; public ConfLineSeparator(String file) { all = new String[2000]; //maximum p = new Vector(); v = new Vector(); readFile(file); processNow(); } public void readFile(String file) { debug( Reading +file); try { i=0; FileInputStream fstream = new FileInputStream(file); DataInputStream in = new DataInputStream(fstream); while (in.available() !=0){ i++; in.readLine(); } in.close(); all = new String[i]; i=0; fstream = new FileInputStream(file); in = new DataInputStream(fstream); while (in.available() !=0){ all[i++] = in.readLine(); debug( Reading Got this data +all[i-1]); } in.close(); } catch (Exception e) { debug( Reading Exception +e.getMessage()); } } public void processNow() { // trim it for (int z=0;z all.length; z++) { all[z] = all[z].trim(); } i=0; for (int z=0;z all.length; z++) { if (all[z].startsWith(#)) { } else if (all[z].startsWith(#end)) { return; } else if (all[z].indexOf('=')==-1) { } else if (all[z]==null || all[z]==) { } else { try { p.add(i,new String(all[z].substring(0,all[z].indexOf('=')).trim())); v.add(i,new String(all[z].substring(all[z].indexOf('=')+1,all[z].length()).trim())); } catch (Exception e) { } debug((i) + = +p.get(i)+ value_is +v.get(i)); i++; } } } public String getConf(String prop, String IfValueNotFound) { try { int tmp = p.indexOf(prop); if (tmp =0 tmpv.size()) return (String) v.get(tmp); else return IfValueNotFound; } catch (Exception e) { //e.printStackTrace(); return IfValueNotFound; } } public void debug(String x) { //System.out.println(x); } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flexible way of defining application variables in text format?
NoKideen wrote: On Tuesday 27 September 2005 15:36, Seak, Teng-Fong wrote: My webapp needs some application string variables for configuration. For the moment, I hard-code them as class static properties and compiled. But I'd like to know if there's any method to define such variables in a text file, something like the global.asa in ASP where we could simply write something like this withing the application_onstart subroutine: application(myvar) = my value any better idea than this one ? without modification web.xml :-D this is example to to read - import lib.ConfLineSeparator; ... ... ConfLineSeparator c = new ConfLineSeparator(/whereis/thefile/file.conf); out.println(c.getConf(dbPwd,VALUEifMissing)); ... ... this is example data file /whereis/thefile/file.conf -- #CONFig Text Mode, #Place many Configuration here #Format is : property=value or property = value #there is no SPACE, space is WASTE of String :-p #value is value not value or 'value' #all Chars are case sensitive #Add # char to comment # Db Conf dbPwd=secret Try this API Class file - package lib; import java.io.*; import java.util.Vector; public class ConfLineSeparator { String[] all; int i=0; String currentProp, currentVal; Vector p; Vector v; public ConfLineSeparator(String file) { all = new String[2000]; //maximum p = new Vector(); v = new Vector(); readFile(file); processNow(); } public void readFile(String file) { debug( Reading +file); try { i=0; FileInputStream fstream = new FileInputStream(file); DataInputStream in = new DataInputStream(fstream); while (in.available() !=0){ i++; in.readLine(); } in.close(); all = new String[i]; i=0; fstream = new FileInputStream(file); in = new DataInputStream(fstream); while (in.available() !=0){ all[i++] = in.readLine(); debug( Reading Got this data +all[i-1]); } in.close(); } catch (Exception e) { debug( Reading Exception +e.getMessage()); } } public void processNow() { // trim it for (int z=0;z all.length; z++) { all[z] = all[z].trim(); } i=0; for (int z=0;z all.length; z++) { if (all[z].startsWith(#)) { } else if (all[z].startsWith(#end)) { return; } else if (all[z].indexOf('=')==-1) { } else if (all[z]==null || all[z]==) { } else { try { p.add(i,new String(all[z].substring(0,all[z].indexOf('=')).trim())); v.add(i,new String(all[z].substring(all[z].indexOf('=')+1,all[z].length()).trim())); } catch (Exception e) { } debug((i) + = +p.get(i)+ value_is +v.get(i)); i++; } } } public String getConf(String prop, String IfValueNotFound) { try { int tmp = p.indexOf(prop); if (tmp =0 tmpv.size()) return (String) v.get(tmp); else return IfValueNotFound; } catch (Exception e) { //e.printStackTrace(); return IfValueNotFound; } } public void debug(String x) { //System.out.println(x); } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Use commons.configuration. Works beautifully and has the advantage that you don't need to change your deployment descriptor or server.xml if you want to change the configuration. With commons-configuration you can also reload and write the properties, store them in xml, a database or a simple
RE: Flexible way of defining application variables in text format?
From: NoKideen [mailto:[EMAIL PROTECTED] Subject: Re: Flexible way of defining application variables in text format? Try this API Class file Is there some reason you went to all this trouble rather than using java.util.Properties? - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Flexible way of defining application variables in text format?
I use a properties file stored in the WEB-INF directory. Modifying the web.xml is too error prone. Using another XML file is a lot harder than a properties file. Just use the servlet context getResourceAsStream(), and pass that to the properties.load() method. George Sexton MH Software, Inc. http://www.mhsoftware.com/ Voice: 303 438 9585 -Original Message- From: Seak, Teng-Fong [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 27, 2005 2:37 AM To: Tomcat Users List Subject: Flexible way of defining application variables in text format? My webapp needs some application string variables for configuration. For the moment, I hard-code them as class static properties and compiled. But I'd like to know if there's any method to define such variables in a text file, something like the global.asa in ASP where we could simply write something like this withing the application_onstart subroutine: application(myvar) = my value I like them to be withing text file because if even there's a need to change config, I'd like to just launch a text editor, edit it and start again! I don't want to install Eclipse or other IDE in deployment server just in case we need to change some parameter and have to compile everything. This is very inconvenient, non professional and stupid. And the client would probably not appreciate this. OK, I know I could write a wrapper function to parse that text file and assign the correct values, but is there a simpler way? Is the answer lying in the web.xml file? But its syntax seems quite complicated that I've no idea what to begin. TIA - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flexible way of defining application variables in text format?
On Tuesday 27 September 2005 16:48, Jilles van Gurp wrote: NoKideen wrote: this is example to to read - import lib.ConfLineSeparator; ... ... ConfLineSeparator c = new ConfLineSeparator(/whereis/thefile/file.conf); out.println(c.getConf(dbPwd,VALUEifMissing)); ... ... Use commons.configuration. Works beautifully and has the advantage that you don't need to change your deployment descriptor or server.xml if you want to change the configuration. With commons-configuration you can also reload and write the properties, store them in xml, a database or a simple text file. is there any example, I'd still confuse how to read dot properties file I think may API was to odds :-D, yeah that was trouble but there is one thing I like is comments using # - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Flexible way of defining application variables in text format?
From: NoKideen [mailto:[EMAIL PROTECTED] Subject: Re: Flexible way of defining application variables in text format? is there any example, I'd still confuse how to read dot properties file I think may API was to odds :-D, yeah that was trouble but there is one thing I like is comments using # Fullly supported by the java.util.Properties class. Read the API spec. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flexible way of defining application variables in text format?
Seak, Teng-Fong [EMAIL PROTECTED] wrote in news:4339048E.30608 @yahoo.com: My webapp needs some application string variables for configuration. For the moment, I hard-code them as class static properties and compiled. But I'd like to know if there's any method to define such variables in a text file, something like the global.asa in ASP where we could simply write something like this withing the application_onstart subroutine: application(myvar) = my value TIA database. using props files you have to bounce the app to get changes to take effect unless you write your own properties loader that runs as a thread, or checks file timestamps, etc. imo, its all too messy, db based config is far superior - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]