Hi All,

I am using Tomcat 4.0.3 on Win2K. and am having a problem invoking
a servlet. I have one servlet that is started by Tomcat. It periodically
checks a mail server for incoming messages, and calls another
servlet to  process the messages.

The problem is that if there are messages on the server before Tomcat
starts, those messages are not processed by the second servlet. However,
any messages that come in after Tomcat starts are processed correctly.

Here is a Java code fragment from the first servlet:

import java.io.*;
import javax.mail.Message;
import javax.servlet.*;
import javax.servlet.http.*;
import org.w3c.dom.*;

public class  EmailMonitor extends HttpServlet {
...
public void doGet(HttpServletRequest request,HttpServletResponse response) {
...
  try {
    processMail(request,response);
  }
  catch (Exception ex) {
   Debug.log(getClass().getName()+".doGet(): ", ex);
  }
}
 ...
private void processMail(HttpServletRequest request, HttpServletResponse
response)
  throws IOException, ServletException {

  Document doc = null;
  EmailProcessor ePro  = new EmailProcessor(); // my class

  Message[] messages = ePro.getMailMessages();
  int n = messages.length;
  for (int i = 0; i < n; i++) {
    ePro.processMessage(messages[i]); // method in EmailProcessor
    doc = ePro.getDoc();
    callDestinationServlet(doc, request, response);
   ...
  }
  ePro.closeFolder();
}

private void callDestinationServlet(Document doc, HttpServletRequest
request,HttpServletResponse response)
  throws IOException, ServletException {

  ServletContext context = getServletContext();
  System.err.println("servlet context: "+ context.toString());  // 1
  String strDispatch = RequestParse.getDestinationVal(doc); // get the
servlet name from the email message
  System.err.println("servlet name: "+ strDispatch);  // 2
  if (strDispatch == null) {
    throw new KGException("No destination servlet specified for email
processing"); // my exception class
  }
  request.setAttribute(ReplicateServer.HTTP_REQUEST_ATTR_KGMESSAGES_DOC,
doc);
  System.err.println("servlet request: "+ request.toString());  // 3
  RequestDispatcher rd = request.getRequestDispatcher(strDispatch);
  System.err.println("rd: "+ rd.toString());  // 4
  try
  {
    rd.include(request, response); // invoke the second servlet
  }
  catch (Exception e)
  {
    // do something with exception
  }
}
}

The values of the debug println statements in the problem case are:
1. servlet context: org.apache.catalina.core.ApplicationContextFacade@3cb23e
2. servlet name: com.kg.replicate.KGReplicateServer
3. servlet request: org.apache.catalina.servlets.InvokerHttpRequest@27b0bf
4. rd: org.apache.catalina.core.ApplicationDispatcher@1903f4

When things go right, these values are:
1. servlet context: org.apache.catalina.core.ApplicationContextFacade@3cb23e
2. servlet name: com.kg.replicate.KGReplicateServer
3. servlet request: org.apache.catalina.connector.HttpRequestFacade@40f7a8
4. rd: org.apache.catalina.core.ApplicationDispatcher@1903f4

Can anyone tell me why a different class is used in (3) when messages
already
exist on the server? Even though it gets the correct name for the servlet
(4),
debugging lines in that servlet tell me that it is never entered, and
rd.include()
doesn't throw an exception.

I have done extensive searches on this problem, but have not found a
solution.

Thanks very much for any help.

Leona Slepetis





--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@;jakarta.apache.org>

Reply via email to