01: /*
02: * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: */
07: package winstone.testApplication.servlets;
08:
09: import java.io.IOException;
10: import java.io.Writer;
11:
12: import javax.servlet.ServletException;
13: import javax.servlet.UnavailableException;
14: import javax.servlet.http.HttpServlet;
15: import javax.servlet.http.HttpServletRequest;
16: import javax.servlet.http.HttpServletResponse;
17:
18: /**
19: * Used to test the unavailable exception processing
20: *
21: * @author <a href="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
22: * @version $Id: UnavailableServlet.java,v 1.2 2006/02/28 07:32:49 rickknowles Exp $
23: */
24: public class UnavailableServlet extends HttpServlet {
25: protected boolean errorAtInit;
26:
27: public void init() throws ServletException {
28: String errorTime = getServletConfig().getInitParameter(
29: "errorTime");
30: this .errorAtInit = ((errorTime == null) || errorTime
31: .equals("init"));
32: if (this .errorAtInit)
33: throw new UnavailableException(
34: "Error thrown deliberately during init");
35: }
36:
37: protected void doGet(HttpServletRequest request,
38: HttpServletResponse response) throws ServletException,
39: IOException {
40: if (!this .errorAtInit)
41: throw new UnavailableException(
42: "Error thrown deliberately during get");
43:
44: Writer out = response.getWriter();
45: out
46: .write("This should not be shown, because we've thrown unavailable exceptions");
47: out.close();
48: }
49:
50: }
|