cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ulrich Mayring <u...@denic.de>
Subject Suggestion for Frontend.java
Date Tue, 27 Mar 2001 13:44:58 GMT
Hi folks,

As of 1.8.2 we have this code:

public static void print(ServletResponse response, String title, String
message) throws IOException {
        response.setContentType("text/html");
        PrintWriter out = new PrintWriter(response.getWriter());
        header(out, 80);
        out.println("<h3 align=\"center\">" + title + "</h3>");
        if (message != null) out.println("<blockquote><pre>" + message +
"</pre></blockquote>");
        footer(out);
    	}

I think it would be useful to introduce an additional try/catch Block
like this:

public static void print(ServletResponse response, String title, String
message) throws IOException {
        response.setContentType("text/html");
	try {
        	PrintWriter out = new PrintWriter(response.getWriter());
		... yaddayadda ...
		}
	catch (IllegalStateException e) {
		OutputStream out = response.getOutputStream();
		out.write("<h3 align=\"center\">" + title + "</h3>".getBytes());
		... yaddayadda ...
		out.flush ();
		}
	}

The thing is this method is supposed to print out an error that occurred
somewhere. Now suppose that error has something to do with an XSP page
calling response.getOutputStream() and outputting something by itself.
Then in the current code an exception is thrown by response.getWriter()
saying that getOutputStream() has already been called. The original
error, however, is lost since no output can take place.

This is actually a very troublesome issue, because I have hundreds of
XSP pages here that could potentially be the culprit, but I can't point
my finger on it, because I never see Cocoon's error message. I do have
the exception in my servlet log, but that doesn't tell me much. I am
pasting it below, just in case someone is interested. The exception
occurs every minute or so and we have so much traffic here that I really
can't tell who causes it.

The same enhancement could be applied to the status method, but I think
it's not necessary, because that method just builds the Cocoon status
page and there's no way to call getOutputStream() before that. Other
than that there is no place in Cocoon's source code that calls
response.getWriter()

Ulrich


<servletException> java.lang.IllegalStateException: Already called
getOutputStream.
        at java.lang.Throwable.fillInStackTrace(Native Method)
        at java.lang.Throwable.fillInStackTrace(Compiled Code)
        at java.lang.Throwable.<init>(Compiled Code)
        at java.lang.Exception.<init>(Compiled Code)
        at java.lang.RuntimeException.<init>(Compiled Code)
        at java.lang.IllegalStateException.<init>(Compiled Code)
        at org.apache.jserv.JServConnection.getWriter(Compiled Code)
        at org.apache.cocoon.Frontend.print(Compiled Code)
        at org.apache.cocoon.Frontend.error(Compiled Code)
        at org.apache.cocoon.Cocoon.service(Compiled Code)
        at javax.servlet.http.HttpServlet.service(Compiled Code)
        at org.apache.jserv.JServConnection.processRequest(Compiled
Code)
        at org.apache.jserv.JServConnection.run(Compiled Code)
        at java.lang.Thread.run(Compiled Code)

-- 
Ulrich Mayring
DENIC eG, Systementwicklung

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail: <cocoon-users-help@xml.apache.org>


Mime
View raw message