View Javadoc
1 /* Reattore HTTP Server 2 3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 $Id: FallbackErrorInterceptor.java,v 1.5 2003/03/05 04:31:57 michaelh Exp $ 20 */ 21 22 package juju.reattore.server.intercept.impl; 23 24 import java.text.MessageFormat; 25 26 import juju.reattore.io.impl.ByteSourceSink; 27 import juju.reattore.protocol.http.*; 28 import juju.reattore.server.intercept.Interceptor; 29 30 /*** Last chance error handler that returns a simple HTML page. 31 32 @tag fallback 33 @group Interceptor 34 */ 35 public class FallbackErrorInterceptor 36 implements Interceptor { 37 38 private static final String DEFAULT = 39 "<html><head><title>Error {0}</title></head>" 40 + "<body><h1>Error {0}</h1>" 41 + "<p>Error {0} occured while fetching <tt>{1}</tt>" 42 + "</body></html>"; 43 44 private String msg; 45 46 /*** Use the default message. 47 48 @see #FallbackErrorInterceptor 49 */ 50 public FallbackErrorInterceptor() { 51 this.msg = DEFAULT; 52 } 53 54 /*** Set the message to return. 55 56 Create a new fallback handler with the given message/message 57 format. The parameters are: 58 <ul> 59 <li>{0} - The error code.</li> 60 <li>{1} - The path.</li> 61 </ul> 62 63 @param msg The new message. 64 */ 65 public void setMessage(String msg) { 66 this.msg = msg; 67 } 68 69 /*** @see Interceptor */ 70 public boolean process(HttpRequest req, HttpResponse resp) { 71 72 String out = MessageFormat.format(msg, 73 new Object[] { 74 new Integer(resp.getStatus()), 75 req.getPath() 76 }); 77 78 resp.setBody(new ByteSourceSink(out.getBytes())); 79 resp.setHeader(HttpConstants.CONTENT_TYPE, HttpConstants.TEXT_HTML); 80 81 return true; 82 } 83 }

This page was automatically generated by Maven