Logging

2002-02-28 Thread Jay Wright


Using Tomcat 4, I am trying to accomplish writing logs (preferrably via
System.out and System.err) that have a timestamp on each and every write.
Iplanet and JavaWebServer did this automatically.  It is important to write
to these logs and have them timestamped, WITHOUT writing code that is in any
way web-server specific.

What I have learned about Tomcat 4 logging is this:  All System.out and
System.err print statements go by default to the catalina.out file.  Each
context within tomcat can be written to a specific file via the logger
component.  

There are a couple of questions that I'm trying to understand.

First - can the catalina.out file be configured through tomcat components
such that all System.out and System.err entries are timestamped.  

Two - What are the api calls to write to the logger file and can I
specifiy the verbosity (the level of the entry 0-4) with each entry?

I'm hesitant to use the logger since I'm unfamiliar with whether or not
that code would be portable to other web servers?

Thanks,
Jay

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




HttpServletResponseWrapper error.

2002-01-21 Thread Jay Wright


I am writing to this list after inquiries elsewhere have turned up no
adequate responses.  I hope it is the correct forum for the question, since
I am having trouble on Tomcat whereas I didn't on Resin and need to know how
the Tomcat container handles the HttpServletResponseWrapper.

I have a servlet which needs to write a JSP page's resultant HTML to a file
instead of sending it back to the browser. 

I do this by wrapping the response with HttpServletResponseWrapper, calling
RequestDispatcher and forward on the wrapped response, which runs the JSP
and writes the resultant HTML to a file, then forward control to a
thankyou.html page. 

This works with Resin. However, in Tomcat, when I wrap the response, I
commit the original response object and can not forward to a thank you
page. I catch a java.lang.IllegalStateException: Cannot forward after
response has been committed. In my debug tests, the response is committed
during the RequestDispatchers forward method.

I need to avoid this.  The templates (1 and 2) are all JavaServer Pages
whose output (HTML) is intercepted and written to file by the
MyServletResponse wrapper. How do I do this without committing the
response object. I could find no way of duplicating or cloning the object
before passing it to MyServletResponse's constructor.  Nor could I close the
ServletOutputStreams.  Any ideas?  This worked wonderfully on Resin, but not
Tomcat 4.0.1.  I prefer to use Tomcat. 

If this cannot work, I need to know so I can move on.  If there is a better
way to handle it, I'm open to that as well.  Additionally it is ENTIRELY
reasonable to assume that I have implemented the wrapper incorrectly. 

Thank you,
Jay Wright

THE SERVLET CODE: 

MyServletResponse wrapper1 = new MyServletResponse (response,
1_content.txt); 
MyServletResponse wrapper2 = new MyServletResponse (response,
2_content.txt); 

rd = request.getRequestDispatcher(template1); 
rd.include(request, wrapper1); 
wrapper1.close(); 

rd = request.getRequestDispatcher(template2); 
rd.include(request, wrapper2 ); 
wrapper2 .close(); 

request.getRequestDispatcher(getScreenFlowManager().getTemplate(locale)).for
ward(request, response); 

MY WRAPPER CLASS: 

public class MyServletResponse extends HttpServletResponseWrapper { 

private PrintWriter printWriter; 
private ServletOutputStream servletOutputStream; 
 
/** 
* Constructor 
*/ 
public MyServletResponse (HttpServletResponse response, String filename)
throws java.io.IOException { 
   super(response); 
  servletOutputStream = response.getOutputStream(); 
  File file = new File(filename); 
  String fileCreated = file.toString(); 
   printWriter = new PrintWriter(new BufferedWriter(new
FileWriter(fileCreated))); 
} 

public ServletOutputStream getOutputStream() throws java.io.IOException
{ 
   return servletOutputStream; 
} 

public void setOutputStream(ServletOutputStream sos) throws
java.io.IOException { 
servletOutputStream = sos; 
} 

public PrintWriter getWriter() throws java.io.IOException { 
return printWriter; 
} 

public void close() { 
this.printWriter.close(); 
} 
} 

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]