You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christopher Mark Balz <Ch...@yahoo.com> on 2002/07/12 17:02:58 UTC

Servlet dying silently under ssl.

Running tomcat 3.2 on Win2K with MySql.  Use Cygwin and Emacs dev
tools.

I have a simple servlet running under ssl (public-private key) that is 
dying silently and unexpectedly.  It was working flawlessly and then 
stopped working without there being any change anywhere on my entire 
machine that I would notice as something that would cause the servlet to 
die silently (can't get any logging).  I don't know where to look next 
for the problem and hope for some suggestions.

Prior to my latest reboot, I couldn't even 'tail' my tomcat.log.  At 
that time when I ran this very simple servlet that was just working 
recently, tomcat.log became 416 Kb and wouldn't 'tail'.  The servlet 
accepts a 'post'-method http form submission, and other servlets that do 
the same but not under ssl still run fine.

I can get no 'servlet.log''s from the servlet that is dying.  Two 
reboots ago, tomcat.log was also huge and showed what appeared to be
low-level i/o errors from running the dying servlet.  The symptoms on 
the client are that after http form submission the page just flashes 
(refreshes) and resets itself, with no server error message.

The only defining change from when the dying servlet used to work that
I can see is that the machine (a laptop running Win2K) shut itself
down when on battery -- perhaps it ran low on juice.  But all else works 
fine and since then I've shutdown and rebooted three times, to no avail.

web.xml and the simple servlet in question are below, as well as a 
relevant section from servlet.xml, and the tomcat.log and servlet.log 
from my latest reboot and attempt.

Any clues?

servlet.log
-------------------------------------------------------
2002-07-11 22:07:54 - path="/examples" :jsp: init
2002-07-11 22:07:54 - path="/dynasurv" :jsp: init
2002-07-11 22:07:54 - path="/admin" :jsp: init
2002-07-11 22:07:54 - path="/dynasurv.tar.gz" :jsp: init
2002-07-11 22:07:54 - path="/dynasurv.zip" :jsp: init
2002-07-11 22:07:54 - path="/olddynasurv.tar.gz" :jsp: init
2002-07-11 22:07:55 - path="" :jsp: init
2002-07-11 22:07:55 - path="/test" :jsp: init


tomcat.log
-------------------------------------------------------
2002-07-11 22:07:45 - ContextManager: Adding context Ctx( /examples )
2002-07-11 22:07:45 - Ctx( /dynasurv ): Set debug to 9
2002-07-11 22:07:45 - ContextManager: Adding context Ctx( /dynasurv )
2002-07-11 22:07:45 - ContextManager: Adding context Ctx( /admin )
2002-07-11 22:07:45 - ContextManager: Adding context Ctx( /dynasurv.tar.gz )
2002-07-11 22:07:45 - ContextManager: Adding context Ctx( /dynasurv.zip )
2002-07-11 22:07:45 - ContextManager: Adding context Ctx( 
/olddynasurv.tar.gz )
2002-07-11 22:07:45 - ContextManager: Adding context Ctx(  )
2002-07-11 22:07:45 - ContextManager: Adding context Ctx( /test )
2002-07-11 22:07:54 - Ctx( /dynasurv ): XmlReader - init  /dynasurv 
webapps/dynasurv
2002-07-11 22:07:54 - Ctx( /dynasurv ): Reading C:\Program 
Files\jakarta-tomcat-3.2.4\webapps\dynasurv\WEB-INF\web.xml
2002-07-11 22:07:54 - Ctx( /dynasurv ): Loading -2147483646 jsp
2002-07-11 22:07:55 - PoolTcpConnector: Starting HttpConnectionHandler 
on 8080
2002-07-11 22:07:56 - PoolTcpConnector: Starting HttpConnectionHandler 
on 8443
2002-07-11 22:07:56 - PoolTcpConnector: Starting Ajp12ConnectionHandler 
on 8007
2002-07-11 22:21:22 - Ctx( /dynasurv ): Get real path 
/static/QueryTool/index.html C:\Program 
Files\jakarta-tomcat-3.2.4\webapps\dynasurv\static\QueryTool\index.html 
C:\Program Files\jakarta-tomcat-3.2.4\webapps\dynasurv
2002-07-11 22:26:06 - Ctx( /dynasurv ): Get real path 
/static/QueryTool/index.html C:\Program 
Files\jakarta-tomcat-3.2.4\webapps\dynasurv\static\QueryTool\index.html 
C:\Program Files\jakarta-tomcat-3.2.4\webapps\dynasurv
2002-07-11 22:26:13 - Ctx( /dynasurv ): Get real path 
/static/QueryTool/index.html C:\Program 
Files\jakarta-tomcat-3.2.4\webapps\dynasurv\static\QueryTool\index.html 
C:\Program Files\jakarta-tomcat-3.2.4\webapps\dynasurv
2002-07-11 22:26:17 - Ctx( /dynasurv ): Get real path 
/static/QueryTool/index.html C:\Program 
Files\jakarta-tomcat-3.2.4\webapps\dynasurv\static\QueryTool\index.html 
C:\Program Files\jakarta-tomcat-3.2.4\webapps\dynasurv



 >From server.xml:
-------------------------------------------------------

         <Context path="/dynasurv"
                  docBase="webapps/dynasurv"
                  crossContext="false"
                  debug="9"
                  reloadable="true" >
         </Context>

------------------------------------------------


 >From web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!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>

   <!-- Servlets: -->

   <servlet>
    <servlet-name>
       DynaForm
    </servlet-name>
    <servlet-class>
       com.treelogic_swe.frameworks.dynaForm.DynaForm
    </servlet-class>
      <init-param>
       <param-name>
           dbDriver
        </param-name>
        <param-value>
           org.gjt.mm.mysql.Driver
        </param-value>
      </init-param>
      <init-param>
       <param-name>
           dbUrl
       </param-name>
       <param-value>
          jdbc:mysql://localhost:3306/survey_test
       </param-value>
      </init-param>
      <init-param>
       <param-name>
          dbTable
       </param-name>
       <param-value>
          longtest
       </param-value>
      </init-param>
      <init-param>
       <param-name>
          dbRowFormatUrl
       </param-name>
       <param-value>
          file://C:/Program 
Files/jakarta-tomcat-3.2.4/webapps/dynasurv/WEB-INF/config/survey1.xml
       </param-value>
      </init-param>
      <init-param>
       <param-name>
           debug
        </param-name>
        <param-value>
           true
        </param-value>
      </init-param>
   </servlet>

   <servlet>
    <servlet-name>
       QueryTopowest
    </servlet-name>
    <servlet-class>
       com.treelogic_swe.queryTopowest.QueryTopowest
    </servlet-class>
      <init-param>
       <param-name>
           dbDriver
        </param-name>
        <param-value>
           org.gjt.mm.mysql.Driver
        </param-value>
      </init-param>
      <init-param>
       <param-name>
           dbUrl
       </param-name>
       <param-value>
          jdbc:mysql://localhost:3306/survey_test
       </param-value>
      </init-param>
      <init-param>
       <param-name>
          dbTable
       </param-name>
       <param-value>
          longtest
       </param-value>
      </init-param>
      <init-param>
       <param-name>
             debug
       </param-name>
       <param-value>
             true
       </param-value>
      </init-param>
     </servlet>

   <!-- Security Constraints -->

   <security-constraint>

     <web-resource-collection>
       <web-resource-name>
          QueryTopowest
       </web-resource-name>
       <url-pattern>
          /servlet/QueryTopowest
       </url-pattern>
       <http-method>
          GET
       </http-method>
       <http-method>
          POST
       </http-method>
     </web-resource-collection>

     <web-resource-collection>
       <web-resource-name>
          QueryTool
       </web-resource-name>
       <url-pattern>
          /static/QueryTool/index.html
       </url-pattern>
     </web-resource-collection>

     <auth-constraint>
       <role-name>
          owner
       </role-name>
       <role-name>
          deployer
       </role-name>
     </auth-constraint>
     <user-data-constraint>
       <transport-guarantee>
          CONFIDENTIAL
       </transport-guarantee>
     </user-data-constraint>
   </security-constraint>

   <!-- Login configs: -->
   <login-config>
     <auth-method>
       BASIC
     </auth-method>
     <realm-name>
       Default
     </realm-name>
   </login-config>

</web-app>


Servlet itself (it is really quite simple):
------------------------------------------------


package com.treelogic_swe.queryTopowest;

import java.util.Enumeration;

import java.io.PrintWriter;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class QueryTopowest extends HttpServlet {
     private static final String [] SUPPORTED_QUERIES = {
         "SELECT userEmail FROM longtest",
         "SELECT userName, userEmail FROM longtest"
     };
     private static final int [] QUERY_NUM_COLUMNS = { 1, 2 };

     // todo: create an array of prepared statements, and work from that.
     private static final String QUERY_KEY = "query_selection";
     private static String beginResult = "<br><br><br>----------------- 
Results: <br>";

     // HTTP response strings:
     private static final String OPENING = "<html><body>";
     private static final String CLOSING = "</body></html>";
     private static final String FAILED  = "Please contact <a 
href='mailto:chris@treelogic-swe.com'> " +
         "technical support</a>.";
     private static final String QUICK_RESPONSE = "<br>Here is the 
information " +
         "you requested.&nbsp;&nbsp;<i>Thank you for using 
DynaSurv!</i><br>";

     private static ServletContext sc = null;
     private static int uniqueEntryId = -1;
     private static boolean debug = true;
      private static String dbTable = null;

     private Connection conn = null;

     /**
      * This method creates the database connection that is shared
      * across all requests of this servlet
      * @param config a <code>ServletConfig</code> value
      * @exception ServletException
      */
     public void init( ServletConfig config )
         throws ServletException {
         sc.log("Starting init method of QueryTopowest.");
         String highestUniqueId = "SELECT MAX(Survey_Id) FROM longtest";

         Statement stmt = null;
         ResultSet rs = null;
         InputStream in = null;

         String url = null;
         String driver = null;

         sc = config.getServletContext();
         sc.log("\n\n *********** New Session QueryTopowest: Succesfully 
obtained servlet context for DynaSurv.\n");
         debug = (new 
Boolean(config.getInitParameter("debug"))).booleanValue();
         // Get db properties (properties are in the web.xml file):
         url = config.getInitParameter("dbUrl");
         driver = config.getInitParameter("dbDriver");
         dbTable = config.getInitParameter("dbTable");

         try {
             /*-
              *  The driver objects register themselves with the driver 
manager
              *  at the time of loading,
              *  and the following ligne forces the loading of the 
(MySQL or other)
              *  driver (it registers itself).
              */
             Class.forName(driver).newInstance();
             conn = DriverManager.getConnection(url);
             sc.log("Database connection successfully obtained.");
             conn.setAutoCommit(false);
             // Test db connection for integrity:
             stmt = conn.createStatement();
             rs = stmt.executeQuery(highestUniqueId);
             if (rs.next()) {
                 uniqueEntryId = rs.getInt(1); // Gets the highest 
unique survey i.d.
             }
             sc.log("uniqueEntryId is initialized as "+uniqueEntryId);
             // Close the statement object, which also closes the resultset.
             stmt.close();
             if (uniqueEntryId < 0) {
                 sc.log("Problem with database connection if " +
                        "this is not a new db table.  This db table has 
no " +
                        "greatest unique entry id number." );
             }
         } catch (ClassNotFoundException e) {
             String msg = "*** Couldn't load database driver.";
             sc.log(msg, e);
             throw new UnavailableException(msg);
         } catch (SQLException e) {
             String msg = "*** Couldn't get db connection.";
             sc.log(msg, e);
             throw new UnavailableException(msg);
         } catch (IllegalAccessException e) {
             String msg = "*** Couldn't get access to db connection.";
             sc.log(msg, e);
             throw new UnavailableException(msg);
         } catch (InstantiationException e) {
             String msg = "*** Couldn't create db connection.";
             sc.log(msg, e);
             throw new UnavailableException(msg);
         }
     }


     /**
      * Describe <code>doQuery</code> method here.
      *
      * @param query a <code>String</code> value
      * @return a <code>ResultSet</code> value
      * @exception SQLException if an error occurs
      */
     ResultSet doQuery (String query) throws SQLException {
         try {
             PreparedStatement pstmt = null;
             pstmt = conn.prepareStatement(query);
             return pstmt.executeQuery();
         } catch (java.sql.SQLException e) {
             String msg = "*** Couldn't get db connection.";
             sc.log(msg, e);
         } // end of try-catch
         return null;
     }


     /**
      * This is the <code>doPost</code> method.
      * @param req  The request submitted by the http user agent.
      * @param res  The response submitted by the servlet, in composed HTML.
      * @throws ServletException
      * @throws IOException
      */
     public synchronized void doPost(HttpServletRequest req, 
HttpServletResponse res)
         throws ServletException, IOException {
         ResultSet rs = null;
         String  nameValues = "";
         Enumeration reqFieldNames = null;

         PrintWriter out = null;

         String rowMsg;
         String name;

         int queriesIndex = (new 
Integer(req.getParameter(QUERY_KEY))).intValue();

         // -------------- Get result of database query request: 

         try {
             rs = doQuery(SUPPORTED_QUERIES[queriesIndex]);
         } catch (SQLException e) {
             String msg = "*** Couldn't get db connection.";
             sc.log(msg, e);
             throw new UnavailableException(msg);
         } // end of try-catch


         // -------------- Prepare http response:
         sc.log("Preparing http response.");
         try {
             out = res.getWriter();
             if (debug) {
                 nameValues += "<table style='border-color: green;'>";
                 reqFieldNames = req.getParameterNames();
                 while(reqFieldNames.hasMoreElements()) {
                     name = (String)reqFieldNames.nextElement();
                     nameValues += "<tr><td>" + name + " </td><td>"
                         + req.getParameter(name) + "</td></tr>";
                 }
                 nameValues += "</table>";
             } else {
                 nameValues = QUICK_RESPONSE;
             }
         } catch (IOException e) {
             sc.log("** Problem with I/O: ", e);
             res.sendError(res.SC_INTERNAL_SERVER_ERROR);
         }

         // --------------  Respond to browser:
         try {
             nameValues += beginResult;
             while (rs.next()) {
                 for (int I=0; I < QUERY_NUM_COLUMNS[queriesIndex]; I++) {
                     nameValues += rs.getString( (I+1) ) + "      ";
                 } // end of for ()
                 nameValues += "<br>";
             } // end of while ()

             // Respond to client user agent:
             try {
                 if (debug) {
                     rowMsg = "SUCCESS.";
                 } else {
                     rowMsg = "";
                 }
                 out.println(OPENING + rowMsg + nameValues + CLOSING);
             } catch (Exception e) {
                 sc.log("** Problem with out.println call: ", e);
                 res.sendError(res.SC_INTERNAL_SERVER_ERROR);
             }
         } catch (SQLException e) {
             String msg = "*** Couldn't get db connection.";
             sc.log(msg, e);
             throw new UnavailableException(msg);
         } catch (Exception e) {
             try {
                 sc.log("** Problem executing db query.", e);
                 res.sendError(res.SC_INTERNAL_SERVER_ERROR);
             }  finally {
                 try {
                     if (conn != null) {
                         conn.close();
                     }
                 } catch (SQLException g) {
                     sc.log("** Failed to close db connection.", g);
                     res.sendError(res.SC_INTERNAL_SERVER_ERROR);
                 }
             }
         }
     }
}




-- 
". . . / This Cabinet is formd of Gold / And Pearl & Crystal shining bright
And within it opens into a World / . . .
Another England there I saw / Another London with its Tower
Another Thames & other Hills / And another pleasant Surrey Bower
. . ."
- from "The Crystal Cabinet", a poem by William Blake.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>