Hi Rob,

I have the same problem as you have.
I can tell you what I did but it is not as good as I want it to be.
Maybe others will help us with a better solution.

So I wrote SilentErrorValve.java. This is insufficient because one has
to have a response otherwise (in my case with apache httpd amd
mod_jk), I get 2 errors, the second being an error from mod_jk where
the error page is not found. But it is a start, and at least I don't
get a stack trace which was my primary objective.

To enable the custom response, I need the attribute
errorReportValveClass="mypackage.SilentErrorValve" in every <Host
entry in server.xml.

What I would prefer is to put the HTML code instead of a file into
web.xml such as (I am making this up - it would not work):
<error-page>
     <error-code>404</error-code>
     <content>
         <html><![CDATA[<body>Not found</body>]]></html>
     </content>
</error-page>


But that is still ugly. What I would really like is that Tomcat and
mod_jk would pass on every error to Apache httpd as a 500 server
error. The reason is that in any case httpd has to have error response
pages and everyone hates creating two sets of pages for the same
thing.

In my case, tomcat does not serve any static pages, only generated
content, so it does not even have a document directory where it could
read files from.

BTW where is the correct use of <error-page> documented?


Regards,
Bernard

package mypackage;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.Globals;
import org.apache.catalina.valves.ValveBase;

public class SilentErrorValve extends ValveBase{
    /**
     * Invoke the next Valve in the sequence. When the invoke returns,
check
     * the response state, and output an error report is necessary.
     *
     * @param request The servlet request to be processed
     * @param response The servlet response to be created
     *
     * @exception IOException if an input/output error occurs
     * @exception ServletException if a servlet error occurs
     */
    public void invoke(Request request, Response response)
        throws IOException, ServletException {

        // Perform the request
        getNext().invoke(request, response);

        ServletRequest sreq = (ServletRequest) request;
        Throwable throwable =
            (Throwable) sreq.getAttribute(Globals.EXCEPTION_ATTR);

        ServletResponse sresp = (ServletResponse) response;
        if (sresp.isCommitted()) {
            return;
        }

        if (throwable != null) {

            // The response is an error
            response.setError();

            // Reset the response (if possible)
            try {
                sresp.reset();
            } catch (IllegalStateException e) {
                ;
            }

            response.sendError
                (HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

        }

        response.setSuspended(false);

// The difference from ErrorReportValve is that we don't return a
report
// in the response.
//        try {
//            report(request, response, throwable);
//        } catch (Throwable tt) {
//            tt.printStackTrace();
//        }

    }
    
    
    
}







On Wed, 15 Jun 2005 09:17:35 +0100, you wrote:

>Hi there, I am using tomcat 5.5 as an RTSP server, and I need to send
>response codes back, but I do not need to send any HTML response back. I
>know that I can change the response page that is returned by editing web.xml
>and adding the following
>
><error-page>
>     <error-code>404</error-code>
>     <location>/index.html</location>
></error-page>
>
>But what I need is to prevent tomcat from sending an error page altogether.
>It seems to me that I could get all of the error codes to redirect to an
>empty page, but this is sloppy, I would much rather change something to
>prevent tomcat from sending a page back.
>
>Any help much appreciated
>
>Rob
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]


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

Reply via email to