protected void flushStream() throws IOException {
    synchronized (_logLock) {
      if (_os != null) _os.flush();

      if (_zipOut != null) _zipOut.flush();
    }
  }
  /**
   * Logs a message to the error log.
   *
   * @param log the error log to write the message.
   * @param message the message to write
   * @param e the exception to write
   */
  public void log(
      String message,
      Throwable e,
      HttpServletRequest request,
      HttpServletResponse response,
      ServletContext application)
      throws IOException {
    WriteStream logStream = getLogStream();

    if (logStream == null) return;

    Throwable t = e;
    while (t != null) {
      e = t;

      if (e instanceof ServletException) t = ((ServletException) e).getRootCause();
      else if (e instanceof ExceptionWrapper) t = ((ExceptionWrapper) e).getRootCause();
      else t = null;
    }

    CharBuffer cb = CharBuffer.allocate();

    QDate.formatLocal(cb, CurrentTime.getCurrentTime(), "[%Y/%m/%d %H:%M:%S] ");

    cb.append(message);

    logStream.log(cb.close());

    if (e != null && !(e instanceof CompileException)) logStream.log(e);

    logStream.flush();
  }
Example #3
0
  public void execute(Path path) throws IOException {
    QuercusPage page = parse(path);

    WriteStream os = new WriteStream(StdoutStream.create());

    os.setNewlineString("\n");
    os.setEncoding("iso-8859-1");

    Env env = createEnv(page, os, null, null);
    env.start();

    try {
      env.execute();
    } catch (QuercusDieException e) {
      log.log(Level.FINER, e.toString(), e);
    } catch (QuercusExitException e) {
      log.log(Level.FINER, e.toString(), e);
    } catch (QuercusErrorException e) {
      log.log(Level.FINER, e.toString(), e);
    } finally {
      env.close();

      os.flush();
    }
  }
  @Override
  public void close(int code, String msg) {
    if (_isWriteClosed.getAndSet(true)) return;

    try {
      WriteStream out = getWriteStream();

      out.write(0x88);
      out.write(0x00);
      out.flush();
    } catch (IOException e) {
      log.log(Level.WARNING, e.toString(), e);
    } finally {
      disconnect();
    }
  }
  /**
   * Logs an error.
   *
   * @param message the error message
   * @param request the servlet request
   * @param response the servlet response
   * @param application the servlet context
   */
  public void log(
      String message,
      HttpServletRequest request,
      HttpServletResponse response,
      ServletContext application)
      throws IOException {
    WriteStream logStream = getLogStream();

    if (logStream == null) return;

    CharBuffer cb = CharBuffer.allocate();

    QDate.formatLocal(cb, CurrentTime.getCurrentTime(), "[%Y/%m/%d %H:%M:%S] ");

    cb.append(message);

    logStream.log(cb.close());

    logStream.flush();
  }
  @Override
  public int doCommand(WatchdogArgs args, WatchdogClient client, WebAppDeployClient deployClient) {
    String fileName = args.getDefaultArg();

    if (fileName == null) {
      throw new ConfigException(L.l("Cannot find a filename in command line"));
    }

    CommitBuilder commit = createCommitBuilder(args);

    try {
      WriteStream out = Vfs.openWrite(System.out);

      deployClient.getFile(commit.getId(), fileName, out);

      out.flush();
    } catch (IOException e) {
      throw ConfigException.create(e);
    }

    return 0;
  }
Example #7
0
  private boolean handleRequest(
      HttpServletRequest req,
      HttpServletResponse res,
      ClientSocket stream,
      OutputStream out,
      boolean keepalive)
      throws ServletException, IOException {
    ReadStream rs = stream.getInputStream();
    WriteStream ws = stream.getOutputStream();

    writeHeader(ws, FCGI_BEGIN_REQUEST, 8);

    int role = FCGI_RESPONDER;

    ws.write(role >> 8);
    ws.write(role);
    ws.write(keepalive ? FCGI_KEEP_CONN : 0); // flags
    for (int i = 0; i < 5; i++) ws.write(0);

    setEnvironment(stream, ws, req);

    InputStream in = req.getInputStream();
    TempBuffer tempBuf = TempBuffer.allocate();
    byte[] buf = tempBuf.getBuffer();
    int len = buf.length;
    int sublen;

    writeHeader(ws, FCGI_PARAMS, 0);

    boolean hasStdin = false;
    while ((sublen = in.read(buf, 0, len)) > 0) {
      hasStdin = true;
      writeHeader(ws, FCGI_STDIN, sublen);
      ws.write(buf, 0, sublen);
    }

    TempBuffer.free(tempBuf);
    tempBuf = null;

    /*
    if (hasStdin)
      writeHeader(fcgiSocket, ws, FCGI_STDIN, 0);
    */
    writeHeader(ws, FCGI_STDIN, 0);

    ws.flush();

    FastCGIInputStream is = new FastCGIInputStream(stream);

    int ch = parseHeaders(res, is);

    if (ch >= 0) out.write(ch);

    TempBuffer tb = TempBuffer.allocate();
    byte[] buffer = tb.getBuffer();

    while ((sublen = is.read(buffer, 0, buffer.length)) > 0) {
      out.write(buffer, 0, sublen);
    }

    TempBuffer.free(tb);

    return !is.isDead() && keepalive;
  }
  @Override
  public void flush() throws IOException {
    WriteStream out = getWriteStream();

    out.flush();
  }