From torque-user-return-4025-apmail-db-torque-user-archive=db.apache.org@db.apache.org Thu Jan 29 10:34:06 2004 Return-Path: Delivered-To: apmail-db-torque-user-archive@www.apache.org Received: (qmail 95769 invoked from network); 29 Jan 2004 10:34:06 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 29 Jan 2004 10:34:06 -0000 Received: (qmail 12456 invoked by uid 500); 29 Jan 2004 10:33:15 -0000 Delivered-To: apmail-db-torque-user-archive@db.apache.org Received: (qmail 12398 invoked by uid 500); 29 Jan 2004 10:33:14 -0000 Mailing-List: contact torque-user-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Apache Torque Users List" Reply-To: "Apache Torque Users List" Delivered-To: mailing list torque-user@db.apache.org Received: (qmail 12294 invoked from network); 29 Jan 2004 10:33:13 -0000 Received: from unknown (HELO msx.drei.com) (213.94.78.66) by daedalus.apache.org with SMTP; 29 Jan 2004 10:33:13 -0000 Received: from msx.drei.com ([10.249.20.17]) by msx.drei.com with Microsoft SMTPSVC(5.0.2195.6713); Thu, 29 Jan 2004 11:33:22 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.0.6375.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: Web Applications Date: Thu, 29 Jan 2004 11:33:21 +0100 Message-ID: <90B3A0967470D44CB8FDE74907512328F1CDFD@av1s008.at-work.local> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Web Applications Thread-Index: AcPl5viehmsHvPe9TDijCS3w5nbR2QAZOWEQ From: =?iso-8859-1?Q?=22G=F6schl=2CSiegfried=22?= To: "Apache Torque Users List" X-OriginalArrivalTime: 29 Jan 2004 10:33:22.0317 (UTC) FILETIME=[51A863D0:01C3E653] X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi folks, here is the code snippet I use with a Struts Plugin to initialize = Torque. I tested with a Tomcat and Bea Weblogic /** * Tries to load the Torque configuration file using a file or as a = resource via * classloader *=20 * @param servletContext Used to determine the absolute path * @param fileName The name of the configuration file to use * @return The Torque configuration file * @throws IOException Failed to load the Configuration */ private Configuration getTorqueConfiguration( ServletContext = servletContext, String fileName ) throws Exception { // Do some diagnostic output this.getLogger().info( "Running on the following servlet container : = " + servletContext.getServerInfo() ); // Handle a missing configuration if( (fileName =3D=3D null) || (fileName.length() =3D=3D 0) ) { this.getLogger().info( "There was no value for the TORQUE config = file defined" ); =20 fileName =3D "/WEB-INF/conf/Torque.properties"; } // Try to load the config file as file from an exploded WAR or // from the classpath String tempFileName =3D servletContext.getRealPath(fileName); this.getLogger().info( "Using the following configuration file : " + = tempFileName ); if( ( tempFileName !=3D null) ) { File tempFile =3D new File( tempFileName ); if( tempFile.exists() ) { this.getLogger().info( "Try to load the following file using = the file system : " + tempFile.getAbsolutePath() ); return new PropertiesConfiguration( = tempFile.getAbsolutePath() ); =20 } } this.getLogger().info( "Try to load the following resource using a = class loader: " + fileName ); return new ClassPropertiesConfiguration( this.getClass(), fileName = ); =20 } -----Original Message----- From: Gary Shea [mailto:shea@gtsdesign.com] Sent: Wednesday, January 28, 2004 10:17 PM To: Apache Torque Users List Subject: RE: Web Applications Sounds like Herr Goeschl has found a way to get commons configuration to read the properties file directly. Until it's published somewhere, here's the relevant part of the initialization servlet I use. It's kinda dumb but doesn't require dealing with class loaders. I've only used it with Tomcat, but I assume (ulp!) it will work with any servlet container. Good luck! Gary public void contextInitialized( ServletContextEvent event ) { ServletContext context =3D event.getServletContext(); =20 context.log("Initializing Torque ..."); try { String fileName =3D = context.getInitParameter("torque-properties"); if (fileName =3D=3D null) { fileName=3D"WEB-INF/torque.properties"; } String realPath =3D context.getRealPath(fileName); if (realPath !=3D null) { context.log("Torque properties " + realPath); Torque.init(realPath); } else { InputStream stream =3D = context.getResourceAsStream(fileName); if (stream =3D=3D null) { context.log( "unable to open torque config file <" + fileName + "> as resource stream" ); return; } =20 /* * The Apache configuration project doesn't seem like it * will work from inside a servlet. I'm probably wrong... * but anyway, I get the properties the old way, and add the * contents of the properties to the Configuration object. * Yeah, this is ugly as sin... */ Properties properties =3D new Properties(); try { properties.load(stream); } catch (IOException e) { context.log( "Caught IOException loading <" + fileName + "> into a Properties object", e ); return; } =20 Configuration configuration =3D new = PropertiesConfiguration(); Enumeration names =3D properties.propertyNames(); while (names.hasMoreElements()) { String name =3D (String) names.nextElement(); String value =3D properties.getProperty(name); configuration.addProperty(name, value); } Torque.init(configuration); } } catch(Exception e){ context.log("Caught exception: ", e); } } [2004-01-28 10:22 +0100] Goschl,Siegfried (Siegfried.Goeschl@drei.com) = wrote: > Finding the Torque.properties file also depends on your application = server. In the case of BEA WebLogic I had the same problem with = unexploded WAR files. Therefore I used the class loading incarnation of = commons configuration - I can send you my source code to your private = mail account >=20 > If you have more thing to initialize and manage in as servlet (and = have a little bit of spare time) you should look at a service framework = such as Turbine or Avalaon. >=20 > Cheers, >=20 > Siegfried Goeschl >=20 > -----Original Message----- > From: Hassan Abolhassani [mailto:Hassan.Abolhassani@razorfish.co.jp] > Sent: Tuesday, January 27, 2004 7:33 AM > To: Apache Torque Users List > Subject: Re: Web Applications >=20 >=20 > >Hey everybody, st00pid newbie here... I've gone through the torque=20 > >tutorial successfully and experimented a bit beyond it but now I'm=20 > >trying to use torque in a web application for the first time and have = > >run into some trouble. I'm confused about the Torque.properties file = > >and the init() method. I've placed the Torque.properties file in the = > >root of my .war, in WEB-INF/, WEB-INF/classes, WEB-INF/lib, just = about=20 > >everywhere, but when I call init("Torque.properties") it can't find = it.=20 > > Where is it supposed to live and how do I reference it? =20 >=20 > My solution is to have an initializer servlet. It passes a phycial = path > of the properties file to the init(). Attached is a copy of that = servlet > that might be usefull for you.=20 >=20 > You need to make it called when the servlet engine is started. To do > that the following snippet in web.xml of your application will work: >=20 > > initializer > com.utility.Initializer >=20 > > log4j-property-file > WEB-INF/classes/log4j.properties > >=20 > > torque-property-file > WEB-INF/classes/Torque.properties > >=20 > 1 > >=20 > Please note that the servlet also initializes log4j, which you may = want > to ignore it. >=20 > >Also, do I=20 > >call init() in each class that uses Torque or do I need to somehow = only=20 > >call it once when the web app is deployed? Sorry if this is a dumb=20 > >question, but I can't find anything in the docs to help me. Thanks=20 > >much. >=20 > You only need to call init() one time. >=20 > --Travis Hanna >=20 > ___ >=20 > Razorfish Japan, Inc. >=20 > = =A5=A2=A5=DC=A5=EB=A5=CF=A5=C3=A5=B5=A5=CB=A1=A1=A5=CF=A5=C3=A5=B5=A5=F3 = Hassan Abolhassani [Technology network] > = =B3=F4=BC=B0=B2=F1=BC=D2=A1=A1=A5=EC=A1=BC=A5=B6=A1=BC=A5=D5=A5=A3=A5=C3=A5= =B7=A5=E5=A1=A6=A5=B8=A5=E3=A5=D1=A5=F3 > Hassan.Abolhassani@razorfish.co.jp > Tel:03-5436-9980 Fax:03-5436-9126 >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org > For additional commands, e-mail: torque-user-help@db.apache.org >=20 >=20 >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For additional commands, e-mail: torque-user-help@db.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For additional commands, e-mail: torque-user-help@db.apache.org