Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

Re: LogSetter in <Context>

Howard Watson

2004-01-20

Replies:

See Attachement

>>> wbarker@(protected) >>>
If you could strip-down your web-app to a minimal version that reproduces
this problem, and post it to BugZilla (or even here, if you don't mind
p**sing off everyone on the list with a big download :), I'd really like to
take a look at it. With a quick eyeballing, I can't see anything in the
code that would produce what you describe.

"Howard Watson" <howardw@(protected)
news:s006834f.078@(protected)...
> Thanks for the reply:
>
> I'm using Tomcat3.3.1a for Netware. Took a look at what you talked
> about and had the same problems. But, I did learn a little more about
> the problem. Apparently, I was hacking the context file, deleting log
> files and restarting Tomcat before results were being written.
>
> The problem is not a failure to write to the log, but that it is taking
> about 5 minutes after restarting Tomcat before it will write to the log.
> Then I have exit out of the browser, start a new browser session and
> recreate the error. It then writes everything for that 5 minutes and up
> to the most recent error.
>
> Later, if I generate an error in a new browser session it will write
> that one error, but if I generate multiple errors in a browser session
> (the same error) I have to start a new browser session, recreate the
> error and then it writes all the missing errors including the most
> current one.
>
> Howard
>
> >>> wbarker@(protected) >>>
> Using the CVS HEAD (aka 3.3.2-dev), I have no problems with the
> default
> setup (which defines a <LogSetter> in the 'examples' Context).
>
> "Howard Watson" <howardw@(protected)
> news:s00536d6.043@(protected)...
> > Does any know of good document or a tutorial for using LogSetter
> within
> > a Tomcat3.3 <Context>? The log file is created but nothing is written
> to
> > it.
> >
> > I've searched the list and the Internet and find nothing explicit
> about
> > using name= or servletLogger= in <Context><LogSetter /></Context>.
> >
> > If I don't use LogSetter within the <Context>; servlet:inits are
> > written and getServletContext().log("Test ServertLog: ", eSQL);
> writes
> > an error to the <ContextManager> servlet_log correctly.
> >
> > Any ideas?
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
> For additional commands, e-mail: tomcat-user-help@(protected)




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)


**********************************************
JSP with a single submit button to call sqlError servlet. The database URL parameter is missing generating an error.
**********************************************
<%@(protected)"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Log Problem</title>
</head>
<body>
 <form action="servlet/logProblem" method="post">
   <div style="margin-top: 10%; height: 20%; text-align: center;">
     <input type="submit" value="Submit" tabindex="1" />
   </div>
 </form>
</body>
</html>

**********************************************
Servlet with missing database URL.
**********************************************
package logProb;

import java.io.*;
import java.net.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class sqlError extends HttpServlet {
 
 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
   response.setContentType("text/html");
   PrintWriter out = response.getWriter();
   
   HttpSession session = null;
   session = request.getSession(false);
   if (session == null){
     response.sendRedirect("sessionErr.html");
   }
   else {
     Connection conn = null;
     Statement stmt = null;
     ResultSet rs = null;
     String sSQL = null;

/////////attribute is not in the session, getConnection fails
     String sDBaddr = (String) session.getAttribute("dbAddr");

     try {
       /* Establish database connection */
       Class.forName("com.pervasive.jdbc.v2.Driver");
       conn = DriverManager.getConnection(sDBaddr);
       if (conn != null) {
         sbSQL = null;
         rs.close();
         stmt.close();
         conn.close();
       }
     }

     /* Catch ClassNotFound and SQL exceptions */
     catch (ClassNotFoundException eCNF) {
       out.println("<p>ClassNotFoundException encountered:" + eCNF.getMessage() + "</p>");
     }
     catch (SQLException eSQL) {
       out.println("<p>SQLException encountered: " + eSQL.getMessage() + "</p>");
////////////write error to sqlError_servlet_log
       getServletContext().log("Test ServletLog: ", eSQL);
     }

     finally {
       try {
         if (rs != null) {
           rs.close();
           rs=null;
         }
       } catch (Exception e) {}
       try {
         if (stmt != null) {
           stmt.close();
           stmt=null;
         }
       } catch (Exception e) {}
       try {
         if (conn != null) {
           conn.close();
           conn=null;
         }
       } catch (Exception e) {}
       try {
         if (out != null) {
           out.close();
           out=null;
         }
       } catch (Exception e) {}
     }
   }
 }
 

 protected void doGet(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
   processRequest(request, response);
 }
 
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
   processRequest(request, response);
 }
}

**********************************************
Servlet context with LogSetter
**********************************************
<Context path="/esgw"
 docBase="Sys:/pathTo/webapps/esgw"
 debug="0"
 reloadable="true" >
 <LogSetter name="sqlError_tc.log" path="logs/sqlError.log" />
 <LogSetter name="sqlError_servlet_log"
   path="logs/servlet_sqlError.log"
   servletLogger="true"/>
</Context>

**********************************************
web.xml
**********************************************
<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
 <servlet>
 <servlet-name>logProblem</servlet-name>
   <servlet-class>logProb.sqlError</servlet-class>
 </servlet>
</web-app>

**********************************************
First write to sqlError_servlet_log after multiple attempts
**********************************************
2004-01-20 10:49:56 - /esgw: TOMCAT/JSP/esgwCorp.jsp: init
2004-01-20 10:50:12 - /esgw: TOMCAT/JSP/LogProblem.jsp: init
2004-01-20 10:50:19 - /esgw: logProblem: init
2004-01-20 10:50:19 - /esgw: Test ServletLog:  - java.sql.SQLException: The url cannot be null
 at java.sql.DriverManager.getConnection (DriverManager.java:489)
 at java.sql.DriverManager.getConnection (DriverManager.java:193)
 at logProb.sqlError.processRequest(sqlError.java:37)
 at logProb.sqlError.doPost(sqlError.java:118)
 at javax.servlet.http.HttpServlet.service (HttpServlet.java)
 at javax.servlet.http.HttpServlet.service (HttpServlet.java)
 at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
 at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
 at org.apache.tomcat.core.Handler.service(Handler.java:235)
 at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
 at org.apache.tomcat.core.ContextManager.internalService (ContextManager.java:917)
 at org.apache.tomcat.core.ContextManager.service (ContextManager.java:833)
 at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Interceptor.java:341)
 at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
 at java.lang.Thread.run (Thread.java:536)

2004-01-20 10:53:17 - /esgw: Test ServletLog:  - java.sql.SQLException: The url cannot be null
 at java.sql.DriverManager.getConnection (DriverManager.java:489)
 at java.sql.DriverManager.getConnection (DriverManager.java:193)
 at logProb.sqlError.processRequest(sqlError.java:37)
 at logProb.sqlError.doPost(sqlError.java:118)
 at javax.servlet.http.HttpServlet.service (HttpServlet.java)
 at javax.servlet.http.HttpServlet.service (HttpServlet.java)
 at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
 at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
 at org.apache.tomcat.core.Handler.service(Handler.java:235)
 at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
 at org.apache.tomcat.core.ContextManager.internalService (ContextManager.java:917)
 at org.apache.tomcat.core.ContextManager.service (ContextManager.java:833)
 at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Interceptor.java:341)
 at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
 at java.lang.Thread.run (Thread.java:536)

2004-01-20 10:55:27 - /esgw: Test ServletLog:  - java.sql.SQLException: The url cannot be null
 at java.sql.DriverManager.getConnection (DriverManager.java:489)
 at java.sql.DriverManager.getConnection (DriverManager.java:193)
 at logProb.sqlError.processRequest(sqlError.java:37)
 at logProb.sqlError.doPost(sqlError.java:118)
 at javax.servlet.http.HttpServlet.service (HttpServlet.java)
 at javax.servlet.http.HttpServlet.service (HttpServlet.java)
 at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
 at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
 at org.apache.tomcat.core.Handler.service(Handler.java:235)
 at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
 at org.apache.tomcat.core.ContextManager.internalService (ContextManager.java:917)
 at org.apache.tomcat.core.ContextManager.service (ContextManager.java:833)
 at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Interceptor.java:341)
 at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
 at java.lang.Thread.run (Thread.java:536)

2004-01-20 10:56:46 - /esgw: Test ServletLog:  - java.sql.SQLException: The url cannot be null
 at java.sql.DriverManager.getConnection (DriverManager.java:489)
 at java.sql.DriverManager.getConnection (DriverManager.java:193)
 at logProb.sqlError.processRequest(sqlError.java:37)
 at logProb.sqlEr
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.