Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/tripi/asp/SetStatusExceptionHandler.java


1   /**
2    * ArrowHead ASP Server 
3    * This is a source file for the ArrowHead ASP Server - an 100% Java
4    * VBScript interpreter and ASP server.
5    *
6    * For more information, see http://www.tripi.com/arrowhead
7    *
8    * Copyright (C) 2002  Terence Haddock
9    *
10   * This program is free software; you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License as published by
12   * the Free Software Foundation; either version 2 of the License, or
13   * (at your option) any later version.
14   *
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Public License for more details.
19   *
20   * You should have received a copy of the GNU General Public License
21   * along with this program; if not, write to the Free Software
22   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23   *
24   */
25  package com.tripi.asp;
26  
27  import java.io.OutputStream;
28  import java.io.PrintWriter;
29  import java.io.IOException;
30  import java.util.Properties;
31  import org.apache.log4j.Category;
32  
33  /**
34   * This class handles an exception by setting the status on the response object.
35   *
36   * @author Terence Haddock
37   * @version 0.9
38   */
39  public class SetStatusExceptionHandler implements AspExceptionHandler
40  {
41      /** Debugging class */
42      static Category DBG = Category.getInstance(SetStatusExceptionHandler.class);
43  
44      /** Exception code */
45      int status = 500;
46  
47      /**
48       * This function configures any properties
49       */
50      public void configureExceptionHandler(Properties prop)
51      {
52          String statusStr = prop.getProperty("Status");
53          if (statusStr != null) status = Integer.parseInt(statusStr);
54      }
55  
56      /**
57       * This function is called when an exception occurs
58       * @param ex Exception which occured
59       */
60      public boolean onExceptionOccured(AspContext ctx, AspException ex)
61          throws AspException
62      {
63          if (DBG.isDebugEnabled()) DBG.debug("Setting the response status to "
64              + status);
65          Response rsp = ctx.getAspResponse();
66          rsp.Status(status);
67          return true;
68      }
69  }
70