Re: Capturing HTML using Tomcat 4
Hi, I'm not sure if this is what you mean. You could simply run the following code to capture the output of the jsp. ~~ String htmlText; URL u = new URL(http://www.server.com:8080/application/some.jsp;); BufferedReader htmlPage = new BufferedReader(new InputStreamReader( u.openStream())); while((htmlText = htmlPage.readLine()) != null){ System.out.println(htmlText); } regards, Luke On Thu, 2004-10-07 at 07:39, David Wall wrote: I've been looking through archives and such for examples of how to capture the HTML output from a given JSP programmatically so I can archive or do other things with that HTML. For example, we might do this to record the text of an agreement that was displayed to a user, in which a JSP generated the agreement HTML page. The pages may be generated from either HTTP GET or POST. It would be nice to perhaps just have a servlet include the response from a JSP, passing along the GET/POST request to that JSP, but then have the servlet capture the JSP's response in a string for processing/storage. O'Reilly has a caching servlet that may help, but I was wondering if anybody had come out with an elegant way to do this. Thanks, David - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [OFF-TOPIC]Yoav -- RE: Some pretty basic Tomcat ConnectionPooling Questions????
Hi, You are right! that statement should be there! kind regards, Luke On Tue, 2004-09-14 at 06:08, Caroline Jen wrote: I saw your Tomcat connection pool class. Your class opens and gets a 'conn' object from the connection pool. Where in your code returns the 'conn' object for use? Should there be a statemenet like: return conn; somewhere? 1. Declaration of private global variables: code private Context ctx = null; private DataSource ds = null; private Connection conn; /code 2. an init() method: code // init does DataSource lookup public void init(ServletConfig config) throws ServletException { super.init(config); try { ctx = new InitialContext(); if(ctx == null) { throw new Exception(No Context); } ds = (DataSource)ctx.lookup(java:comp/env/jdbc/mb); } // end try block catch(Exception e) { e.printStackTrace(); } } // end init() /code 3. an openConnection() method: code private void openConnection() { try { if(ds != null) { conn = ds.getConnection(); if(conn != null) { message = Got Connection to DB + conn.toString(); } } } // end try block catch(Exception e) { e.printStackTrace(); } } //end method openConnection() /code 4. a destroy() method that nulls the DataSource: code public void destroy() { ds = null; } /code --- Luke (Terry) Vanderfluit [EMAIL PROTECTED] wrote: Hi Yoav and all, Thanks for your reply, But you went a bit too far: the DataSource lookup is potentially expensive. That you can do in the init() method and keep a reference to the DataSource, because keeping that reference doesn't use a connection resource. Then in your servlet methods, get a connection from the DataSource, use it, and release it. In your servlet destroy method, null out your DataSource reference. So the DataSource lookup is done once, the DataSource reference is kept as a private non-static member variable of the servlet class, and the Connenctions are used only within methods, they're not class member variables. So now I have changed my code to: 1. Declaration of private global variables: code private Context ctx = null; private DataSource ds = null; private Connection conn; /code 2. an init() method: code // init does DataSource lookup public void init(ServletConfig config) throws ServletException { super.init(config); try { ctx = new InitialContext(); if(ctx == null) { throw new Exception(No Context); } ds = (DataSource)ctx.lookup(java:comp/env/jdbc/mb); } // end try block catch(Exception e) { e.printStackTrace(); } } // end init() /code 3. an openConnection() method: code private void openConnection() { try { if(ds != null) { conn = ds.getConnection(); if(conn != null) { message = Got Connection to DB + conn.toString(); } } } // end try block catch(Exception e) { e.printStackTrace(); } } //end method openConnection() /code 4. a destroy() method that nulls the DataSource: code public void destroy() { ds = null; } /code remarks -the conn.close() is called in the methods that call openConnection(). -I'm thinking of doing an 'include' for the openConnection method, so I don't have the code for the same method sitting in multiple classes. Would that be a good idea? (maintainability, yes but in terms of overhead?) /remarks Would this be the 'leanest' scenario for a database connection? thanks again, Luke -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [OFF-TOPIC]Yoav -- RE: Some pretty basic Tomcat ConnectionPooling Questions????
Hi, Caroline is referring to my 'openConnection()' method which is missing a 'return' statement. see below regards, Luke Your class opens and gets a 'conn' object from the connection pool. Where in your code returns the 'conn' object for use? Should there be a statemenet like: return conn; somewhere? 3. an openConnection() method: code private void openConnection() { try { if(ds != null) { conn = ds.getConnection(); if(conn != null) { message = Got Connection to DB + conn.toString(); } } } // end try block catch(Exception e) { e.printStackTrace(); } return conn; } //end method openConnection() /code -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [OFF-TOPIC]RE: Some pretty basic Tomcat ConnectionPooling Questions????
Hi, further to this thread I have now implemented the database connection as follows: ~~~ To get a database connection via an external class see below the code that does this: 1. the init() method that gets the DataSource from an external connection. 2. a method that queries the database and gets the connection from an external class. 3. the DBConnection class itself 4. a destroy method that sets the DataSource to null within the calling class. I'm pretty sure that doing 'conn = DBConnection.getDBConnection()' is a good move so as not duplicate code. question However, I'm not sure about 'ds = DBConnection.getDataSource()'... that might just as well go as code in the init() method itself. What is more efficient? /question question Alistair had some interesting comments, namely that 1. We should rename the DBConnection class to DBConnectionFactory. I have often wondered what a factory is in this sense, could you elaborate? 2. Adding a finalize() method in the external class -- wouldn't that nullify the DataSource before we are finished with it? -- isn't that doubling up with the destroy() method? -- how much better would it be to nullify the DataSource in a finalize() method, a destroy() method or both? 3. I'd like to find out more about 'adding a static reference to itself and adding a static method called getInstance()' -- how much more efficient would that be? -- how do I implement that? /question This is very interesting and I'm sure it leads to a lot cleaner runnning of the application. ~ 1. The init() method withing the calling servlet: // init does DataSource lookup public void init(ServletConfig config) throws ServletException { super.init(config); try {ds = DBConnection.getDataSource();} catch (Exception e) {} } // end init() === 2. A method within the calling servlet that uses the external class to set up a Database connection: // this method populates a bean private void populateCLBean() { conn = DBConnection.getDBConnection(); try { Statement stmt = conn.createStatement(); ResultSet rst = stmt.executeQuery(select * from category;); while(rst.next()) { Category c = new Category(); c.setCategoryName(rst.getString(categoryname)); clBean.addCategory(c); } // end while block rst.close(); stmt.close(); conn.close(); } // end try block catch(Exception e) { } } // end method populateCLBean() 3. The external class: package mb; import java.sql.Connection; import java.sql.SQLException; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; public class DBConnection { private static String message; private static Connection conn = null; private static InitialContext ctx = null; private static DataSource ds = null; public static DataSource getDataSource() { try { ctx = new InitialContext(); ds = (DataSource)ctx.lookup(java:comp/env/jdbc/mb); } // end try block catch(Exception e) { } // end catch block return ds; } // end method getDataSource() public static Connection getDBConnection() { try { conn = ds.getConnection(); } // end try block catch(Exception e) { } return conn; } // end method getDBConnection() } // end class DBConnection == 4. The destroy method within the calling class. public void destroy() { ds = null; } //end method destroy() == -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [OFF-TOPIC] Some pretty basic TomcatConnectionPooling Questions????
Hi Chuck, you are right! however this is now too redundant to go in to. See my next post on this topic for a further evolution of this database connection subject matter. regards, Luke On Tue, 2004-09-14 at 11:44, Caldarale, Charles R wrote: From: Luke (Terry) Vanderfluit [mailto:[EMAIL PROTECTED] Subject: RE: [OFF-TOPIC] Some pretty basic TomcatConnectionPooling Questions Caroline is referring to my 'openConnection()' method which is missing a 'return' statement. Then you'll also need to change the return type on the method definition. private void openConnection() { - 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] -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[OFF-TOPIC]Yoav -- RE: Some pretty basic Tomcat Connection Pooling Questions????
Hi Yoav and all, - Hold the connection for as little a time as possible. That is, get it from the pool, use it, and return it to the pool as soon as possible. - That means you don't get the connection in a servlet init() method and return it in a destroy() method. That's too long a time to hold connections usually. - Always return connections to the pool. Typically, this is done in the finally clause of a try/catch block to ensure it is executed even if the JDBC operation fails. - You create your pool once, preferably when the app starts up, and you close the pool itself once, preferably when the app shuts down. A ServletContextListener is good for this purpose. Make sure you close the pool. - Servlets and other classes use the pool as needed. You don't have to use a one connection per servlet design (in fact those usually don't work in the real world). I've been using connection pooling via an init() method. Above you say that one should avoid that. So now I have put the connection code inside the method that actually does the database work and dispensed with the init() method. Before I made this change I didn't have a conn.close() statement or a finally clause anywhere either (I DID have resultset.close and statement.close()). Now I have added a conn.close() statement after each database interaction has been completed. Both versions of the code work. Would you say the it is optimised after having gotten rid of the init() method? this is the code in it's latter version: ~~~ try { //establish the connection Context ctx = new InitialContext(); if(ctx == null) { throw new Exception(No Context); } DataSource ds = (DataSource)ctx.lookup(java:comp/env/jdbc/mb); if(ds != null) { conn = ds.getConnection(); //conn is a global variable if(conn != null) { message = Got Connection to DB + conn.toString(); } } } // end try block catch(Exception e) { e.printStackTrace(); } try { //carry out the database query Statement stmt = conn.createStatement(); ResultSet rst = stmt.executeQuery(select * from category where categoryname not like '%Timetable%';); while(rst.next()) { Category c = new Category(); c.setCategoryName(rst.getString(categoryname)); clBean.addCategory(c); } // end while block rst.close(); stmt.close(); conn.close(); } // end try block catch(Exception e) { } ~~ Appreciate your help, kind regards, Luke -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [OFF-TOPIC]Yoav -- RE: Some pretty basic Tomcat ConnectionPooling Questions????
Hi Yoav and all, Thanks for your reply, But you went a bit too far: the DataSource lookup is potentially expensive. That you can do in the init() method and keep a reference to the DataSource, because keeping that reference doesn't use a connection resource. Then in your servlet methods, get a connection from the DataSource, use it, and release it. In your servlet destroy method, null out your DataSource reference. So the DataSource lookup is done once, the DataSource reference is kept as a private non-static member variable of the servlet class, and the Connenctions are used only within methods, they're not class member variables. So now I have changed my code to: 1. Declaration of private global variables: code private Context ctx = null; private DataSource ds = null; private Connection conn; /code 2. an init() method: code // init does DataSource lookup public void init(ServletConfig config) throws ServletException { super.init(config); try { ctx = new InitialContext(); if(ctx == null) { throw new Exception(No Context); } ds = (DataSource)ctx.lookup(java:comp/env/jdbc/mb); } // end try block catch(Exception e) { e.printStackTrace(); } } // end init() /code 3. an openConnection() method: code private void openConnection() { try { if(ds != null) { conn = ds.getConnection(); if(conn != null) { message = Got Connection to DB + conn.toString(); } } } // end try block catch(Exception e) { e.printStackTrace(); } } //end method openConnection() /code 4. a destroy() method that nulls the DataSource: code public void destroy() { ds = null; } /code remarks -the conn.close() is called in the methods that call openConnection(). -I'm thinking of doing an 'include' for the openConnection method, so I don't have the code for the same method sitting in multiple classes. Would that be a good idea? (maintainability, yes but in terms of overhead?) /remarks Would this be the 'leanest' scenario for a database connection? thanks again, Luke -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DataSourceRealm can not find JNDI name in context
-location /taglib taglib taglib-uri/tags/struts-html/taglib-uri taglib-location/WEB-INF/lib/struts-html.tld/taglib-location /taglib taglib taglib-uri/tags/struts-logic/taglib-uri taglib-location/WEB-INF/lib/struts-logic.tld/taglib-location /taglib taglib taglib-uri/tags/struts-nested/taglib-uri taglib-location/WEB-INF/lib/struts-nested.tld/taglib-location /taglib taglib taglib-uri/tags/struts-tiles/taglib-uri taglib-location/WEB-INF/lib/struts-tiles.tld/taglib-location /taglib !-- JSTL Tag Library Descriptors -- taglib taglib-uri/tags/jstl/core/taglib-uri taglib-location/WEB-INF/lib/c.tld/taglib-location /taglib taglib taglib-uri/tags/jstl/fmt/taglib-uri taglib-location/WEB-INF/lib/fmt.tld/taglib-location /taglib !-- DisplayTags tags. -- taglib taglib-uri/tags/displaytag/taglib-uri taglib-location/WEB-INF/lib/displaytag-12.tld/taglib-location /taglib /web-app This is the exception when user try login: 2004-09-09 15:43:46 DataSourceRealm[/yeguadas]: Excepción realizando autenticación javax.naming.NameNotFoundException: El nombre jdbc no este asociado a este contexto at org.apache.naming.NamingContext.lookup(NamingContext.java:768) at org.apache.naming.NamingContext.lookup(NamingContext.java:151) at org.apache.catalina.realm.DataSourceRealm.open(DataSourceRealm.java:437) at org.apache.catalina.realm.DataSourceRealm.authenticate(DataSourceRealm.java:277) at org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:129) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:534) Angel Cervera Claudio Telf. +34 670819234 Mail: [EMAIL PROTECTED] Web: http://www.acervera.com Msn Messenger: [EMAIL PROTECTED] Yahoo Messenger: angelcervera AOL Messenger: angelcervera - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
database connection pool in server.xml -- conf/Catalina/localhost/app.xml
Hi, I've tried to put the database connection details in a separate file in CATALINA_HOME/conf/Catalina/localhost/. That didn't work however, so I've had to revert back to putting that same stuff in the conf/server.xml file to get it working again this is the app specific code that I have in server.xml (and it works), the same code that I put in an app.xml file in the CATALINA_HOME/conf/Catalina/localhost/ directory (and it doesn't work), what do I need to add or change? !-- ~~~ -- !-- ~~ MEGABOARD APPLICATION ADDED 1 September 2004 ~~~ -- !-- ~ megaboard application ~~~ -- !-- ~~~ -- Context path=/megaboard docBase=megaboard debug=0 reloadable=true Valve className=org.apache.catalina.valves.AccessLogValve directory=webapps/megaboard/logs prefix=mbAccessLog. suffix=.log pattern=common resolveHosts=false/ Logger className=org.apache.catalina.logger.FileLogger prefix=mblog. suffix=.txt timestamp=true/ Resource name=jdbc/mb auth=Container type=javax.sql.DataSource/ ResourceParams name=jdbc/mb parameter namefactory/name valueorg.apache.commons.dbcp.BasicDataSourceFactory/value /parameter !-- Maximum number of dB connections in pool. Set to 0 for no limit. -- parameter namemaxActive/name value100/value /parameter !-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit. -- parameter namemaxIdle/name value30/value /parameter !-- Maximum time to wait for a dB connection to become available in ms, in this example 10 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. -- parameter namemaxWait/name value1/value /parameter parameter nameremoveAbandoned/name valuetrue/value /parameter parameter nameusername/name valueluke/value /parameter parameter namepassword/name value/value /parameter parameter namedriverClassName/name valueorg.postgresql.Driver/value /parameter parameter nameurl/name valuejdbc:postgresql:megaboard/value /parameter /ResourceParams /Context !-- ~~~ -- !-- END MEGABOARD APPLICATION -- !-- ~~~ -- ~~~ -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
tomcat 5.0.27 xml schema or DTD for server.xml
Hi, I am running tomcat 5.0.27. I'm looking for a copy of the xml schema for the server.xml file. I've looked on the jakarta website and in the 2.4 servlet spec, but can't find it, Maybe there's only a DTD at this stage, Anyone know where to find it? TIA, Luke -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: tomcat 5.0.27 xml schema or DTD for server.xml
Hi, Actually my intentions are modest. I want to validate whether the tags in server.xml are properly nested. I've had difficulty with this in web.xml before (when setting url-mappings). That's besides the general goal of improving my understanding of tomcat's configuration terminlogy. L. On Mon, 2004-08-30 at 13:39, Benjamin Armintor wrote: You wouldn't find it in the servlet spec, because it's specific to Tomcat. Check the archives, but as I recall, there's no published grammar for the server.xml: It's parsed in non-validating mode by the Digester. A DTD wouldn't work because the attributes for an element are arbitrary (to accomodate user implementations of the Catalina interfaces). I appreciate the idea: I wrote a schema for the 4.1.x server.xml when I wanted one to validate against, but it was kind of a bear. What are you trying to do? -- Benjamin Armintor -Original Message- From: Luke (Terry) Vanderfluit [mailto:[EMAIL PROTECTED] Sent: Sun 8/29/2004 10:53 PM To: [EMAIL PROTECTED] Subject: tomcat 5.0.27 xml schema or DTD for server.xml Hi, I am running tomcat 5.0.27. I'm looking for a copy of the xml schema for the server.xml file. I've looked on the jakarta website and in the 2.4 servlet spec, but can't find it, Maybe there's only a DTD at this stage, Anyone know where to find it? TIA, Luke -- Luke (Terry) Vanderfluit Mobile: 0421 276 282 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]