예제 #1
0
  /**
   * Attempts to send an internal server error HTTP error, if possible. Otherwise simply pushes the
   * exception message to the output stream.
   *
   * @param message Message to be printed to the logger and to the output stream.
   * @param t Exception that caused the error.
   */
  protected void filterError(String message, Throwable t) {
    log.error("XSLT filter error: " + message, t);
    if (false == origResponse.isCommitted()) {
      // Reset the buffer and previous status code.
      origResponse.reset();
      origResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      origResponse.setContentType("text/html; charset=UTF-8");
    }

    // Response committed. Just push the error to the output stream.
    try {
      final OutputStream os = origResponse.getOutputStream();
      final PrintWriter osw = new PrintWriter(new OutputStreamWriter(os, "iso8859-1"));
      osw.write("<html><body><!-- " + XSLTFilterConstants.ERROR_TOKEN + " -->");
      osw.write("<h1 style=\"color: red; margin-top: 1em;\">");
      osw.write("Internal server exception");
      osw.write("</h1>");
      osw.write("<b>URI</b>: " + origRequest.getRequestURI() + "\n<br/><br/>");
      serializeException(osw, t);
      if (t instanceof ServletException && ((ServletException) t).getRootCause() != null) {
        osw.write("<br/><br/><h2>ServletException root cause:</h2>");
        serializeException(osw, ((ServletException) t).getRootCause());
      }
      osw.write("</body></html>");
      osw.flush();
    } catch (IOException e) {
      // Not much to do in such case (connection broken most likely).
      log.debug("Filter error could not be returned to client.");
    }
  }
예제 #2
0
 public boolean save(File file, String options) {
   PrintWriter writer = PApplet.createWriter(file);
   boolean result = write(writer);
   writer.flush();
   writer.close();
   return result;
 }
예제 #3
0
 /**
  * ** Encodes the specified DBRecordKyes into XML and writes it to ** a specified PrintWriter
  * ** @param out The PrintWriter ** @param dbrk The list of DBRecordKeys
  */
 public static void printXML(PrintWriter out, DBRecordKey... dbrk) {
   if (out != null) {
     out.write("<" + DBFactory.TAG_RecordKeys + ">\n");
     for (int i = 0; i < dbrk.length; i++) {
       dbrk[i].printXML(out, 4);
     }
     out.write("</" + DBFactory.TAG_RecordKeys + ">\n");
     out.flush();
   }
 }
예제 #4
0
 /**
  * ** Encodes this DBRecordKey into XML and writes it to a specified PrintWriter ** @param out The
  * PrintWriter ** @param indent The number of spaces to indent ** @param sequence Optional
  * sequence value ** @param soapXML True for SOAP XML
  */
 public void printXML(PrintWriter out, int indent, int sequence, boolean soapXML) {
   if (out != null) {
     out.write(this.toXML(null, indent, sequence, soapXML).toString());
     out.flush();
   }
 }
예제 #5
0
 // Sends this object and its kids to a Writer with an indent of 2 spaces,
 // including the declaration at the top so that the output will be valid XML.
 public boolean write(PrintWriter output) {
   output.print(format(2));
   output.flush();
   return true;
 }