コード例 #1
0
  /**
   * The service method gets the JSP/XTP page and executes it. The request and response objects are
   * converted to Caucho objects so other servlet runners will produce the same results as the
   * Caucho servlet runner.
   */
  public void service(ServletRequest req, ServletResponse res)
      throws ServletException, IOException {
    CauchoRequest request;
    CauchoResponse response;
    ResponseAdapter resAdapt = null;

    if (req instanceof CauchoRequest) request = (CauchoRequest) req;
    else request = RequestAdapter.create((HttpServletRequest) req, _webApp);

    if (res instanceof CauchoResponse) response = (CauchoResponse) res;
    else {
      resAdapt = ResponseAdapter.create((HttpServletResponse) res);
      response = resAdapt;
    }

    Page page = null;

    try {
      page = getPage(request, response);

      if (page == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
      }

      page.service(request, response);
    } catch (JspParseException e) {
      if (e.getErrorPage() != null) forwardErrorPage(request, response, e, e.getErrorPage());
      else throw new ServletException(e);
    } catch (ClientDisconnectException e) {
      throw e;
    } catch (Throwable e) {
      if (page != null
          && page.getErrorPage() != null
          && forwardErrorPage(request, response, e, page.getErrorPage())) {
      } else if (e instanceof IOException) {
        log.log(Level.FINE, e.toString(), e);
        throw (IOException) e;
      } else if (e instanceof ServletException) {
        log.log(Level.FINE, e.toString(), e);
        throw (ServletException) e;
      } else {
        log.log(Level.FINE, e.toString(), e);
        throw new ServletException(e);
      }
    }

    if (resAdapt != null) {
      resAdapt.close();
      ResponseAdapter.free(resAdapt);
    }
  }
コード例 #2
0
  /**
   * Removes an attribute from the servlet context.
   *
   * @param name the name of the attribute to remove.
   */
  public void removeAttribute(String name) {
    Object oldValue;

    synchronized (_attributes) {
      oldValue = _attributes.remove(name);
    }

    // Call any listeners
    if (_applicationAttributeListeners != null) {
      ServletContextAttributeEvent event;

      event = new ServletContextAttributeEvent(this, name, oldValue);

      for (int i = 0; i < _applicationAttributeListeners.size(); i++) {
        ServletContextAttributeListener listener;

        Object objListener = _applicationAttributeListeners.get(i);
        listener = (ServletContextAttributeListener) objListener;

        try {
          listener.attributeRemoved(event);
        } catch (Throwable e) {
          log.log(Level.FINE, e.toString(), e);
        }
      }
    }
  }
コード例 #3
0
 /** Utility method to serialize an exception and its stack trace to simple HTML. */
 private final void serializeException(PrintWriter osw, Throwable t) {
   osw.write("<b>Exception</b>: " + t.toString() + "\n<br/><br/>");
   osw.write("<b>Stack trace:</b>");
   osw.write(
       "<pre style=\"margin: 1px solid red; padding: 3px; font-family: sans-serif; font-size: small;\">");
   t.printStackTrace(osw);
   osw.write("</pre>");
 }
コード例 #4
0
ファイル: error_jsp.java プロジェクト: Susritha/sahithi
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    Throwable exception = org.apache.jasper.runtime.JspRuntimeLibrary.getThrowable(request);
    if (exception != null) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("<head>\r\n");
      out.write("\r\n");
      out.write("<title>Error Page</title>\r\n");
      out.write("</head>\r\n");
      out.write("\r\n");
      out.write("<body bgcolor=\"blue\">\r\n");
      out.write("\t<font size=\"16\" color=\"white\">Your page generated an error:\"<br />\r\n");
      out.write("\t\tException:<br /></font>\r\n");
      out.write("\t");
      out.print(exception.toString());
      out.write("\r\n");
      out.write("\r\n");
      out.write("</body>\r\n");
      out.write("</html>");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try {
            out.clearBuffer();
          } catch (java.io.IOException e) {
          }
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else log(t.getMessage(), t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }