Package com.caucho.server.http

Examples of com.caucho.server.http.CauchoResponse


    if (request instanceof CauchoRequest)
      req = (CauchoRequest) request;
    else
      req = RequestAdapter.create((HttpServletRequest) request, _webApp);
   
    CauchoResponse res;
    ResponseAdapter resAdapt = null;
   
    if (response instanceof CauchoResponse)
      res = (CauchoResponse) response;
    else {
      resAdapt = ResponseAdapter.create((HttpServletResponse) response);
      res = resAdapt;
    }

    try {
      service(req, res);
    } catch (InterruptedException e) {
      log.log(Level.FINE, e.toString(), e);
     
      log.warning("XTP: interrupted for " + req.getPageURI());
     
      res.sendError(503, "Server busy: XTP generation delayed");
    } finally {
      if (resAdapt != null)
        resAdapt.close();
    }
  }
View Full Code Here


   */
  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);
    }
View Full Code Here

    req.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE, e);
    req.setAttribute(RequestDispatcher.ERROR_REQUEST_URI,
                     req.getRequestURI());

    if (res instanceof CauchoResponse) {
      CauchoResponse cauchoResponse = (CauchoResponse) res;
      cauchoResponse.killCache();
      cauchoResponse.setNoCache(true);
    }

    RequestDispatcher rd = req.getRequestDispatcher(errorPage);

    if (rd == null)
View Full Code Here

      _bodyOut = null;
    }
    else
      body = BodyContentImpl.allocate();

    CauchoResponse response = getCauchoResponse();

    body.init(_out);

    _out = body;

    response.setForbidForward(true);
    try {
      _bodyResponseStream.flushBuffer();
    } catch (IOException e) {
    }
    _bodyResponseStream.start();
    _bodyResponseStream.setWriter(body);
    _bodyResponseStream.setEncoding(response.getCharacterEncoding());
    response.setResponseStream(_bodyResponseStream);

    return body;
  }
View Full Code Here

   * Returns the top writer.
   */
  public PrintWriter getTopWriter()
    throws IOException
  {
    CauchoResponse response = getCauchoResponse();

    AbstractResponseStream currentStream = response.getResponseStream();

    response.setResponseStream(_responseStream);

    try {
      return response.getWriter();
    } finally {
      response.setResponseStream(currentStream);
    }
  }
View Full Code Here

    HttpServletRequest request = getCauchoRequest();

    request.setAttribute("javax.servlet.jsp.jspException", e);

    CauchoResponse response = getCauchoResponse();

    response.setForbidForward(false);
    response.setResponseStream(_responseStream);
    response.killCache();
    response.setNoCache(true);

    if (e instanceof ClientDisconnectException)
      throw (ClientDisconnectException) e;

    if (! (_servlet instanceof Page)) {
    }
    else if (getApplication() == null
             || getApplication().getJsp() == null
             || ! getApplication().getJsp().isRecompileOnError()) {
    }
    else if (e instanceof OutOfMemoryError) {
    }
    else if (e instanceof Error) {
      try {
        Path workDir = getApplication().getRootDirectory().lookup("WEB-INF/work");
        String className = _servlet.getClass().getName();
        Path path = workDir.lookup(className.replace('.', '/') + ".class");

        log.warning("Removing " + path + " due to " + e);

        path.remove();
      } catch (Exception e1) {
      }
      Page page = (Page) _servlet;

      page._caucho_unload();
      if (! page.isDead()) {
        page.setDead();
        page.destroy();
      }
    }

    _topOut.clearBuffer();

    if (_errorPage != null) {
      if (log.isLoggable(Level.FINER)) {
        log.log(Level.FINER, e.toString(), e);
      }
      else if (e instanceof DisplayableException) {
        log.warning(e.getMessage());
      }
      else {
        log.log(Level.WARNING, e.toString(), e);
      }

      request.setAttribute(EXCEPTION, e);
      request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE,
                           response.getStatus());
      request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, e);
      request.setAttribute(RequestDispatcher.ERROR_MESSAGE, e.getMessage());
      request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,
                           e.getClass());
      request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI,
                           request.getRequestURI());

      // jsp/01ck
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

      try {
        RequestDispatcher rd = getCauchoRequest().getRequestDispatcher(_errorPage);

        if (rd instanceof RequestDispatcherImpl) {
          getCauchoResponse().setHasError(true);

          ((RequestDispatcherImpl) rd).error(getCauchoRequest(), getCauchoResponse());
        }
        else {
          if (rd != null) {
            getCauchoResponse().killCache();
            getCauchoResponse().setNoCache(true);
            rd.forward(getCauchoRequest(), getCauchoResponse());
          }
          else {
            log.log(Level.FINE, e.toString(), e);
            throw new ServletException(L.l("`{0}' is an unknown error page.  The JSP errorPage directive must refer to a valid URL relative to the current web-app.",
                                           _errorPage));
          }
        }
       
        // jsp/01ck
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      } catch (FileNotFoundException e2) {
        log.log(Level.WARNING, e.toString(), e2);
        throw new ServletException(L.l("`{0}' is an unknown error page.  The JSP errorPage directive must refer to a valid URL relative to the current web-app.",
                                       _errorPage));
      } catch (IOException e2) {
View Full Code Here

    if (disp == null)
      throw new JspException(L.l("URL `{0}' does not map to any servlet",
               url));
   
    CauchoResponse response = (CauchoResponse) pageContext.getResponse();
    response.getResponseStream().setEncoding(null);

    disp.include(pageContext.getRequest(), response);
  } catch (FileNotFoundException e) {
    throw new JspException(L.l("`{0}' is an unknown file or servlet.",
             url));
  }
      }
      else
  handleExternalBody(context + url);
     
      return;
    }

    int colon = url.indexOf(':');
    int slash = url.indexOf('/');
    if (slash == 0 || colon < 0 || slash < 0 || slash < colon) {
      ServletRequest request = pageContext.getRequest();

      try {
  RequestDispatcher disp = request.getRequestDispatcher(url);

  if (disp == null)
    throw new JspException(L.l("URL `{0}' does not map to any servlet",
             url));
   
  CauchoResponse response = (CauchoResponse) pageContext.getResponse();
  response.getResponseStream().setEncoding(null);

  disp.include(pageContext.getRequest(), response);
      } catch (FileNotFoundException e) {
  throw new JspException(L.l("URL `{0}' is an unknown file or servlet.",
           url));
View Full Code Here

    }

    res.setContentLength((int) cache.getLength());

    if (res instanceof CauchoResponse) {
      CauchoResponse cRes = (CauchoResponse) res;

      cRes.getResponseStream().sendFile(cache.getPath(), cache.getLength());
    }
    else {
      OutputStream os = res.getOutputStream();
      cache.getPath().writeToStream(os);
    }
View Full Code Here

    throws ServletException, IOException
  {
    // This filter is always called before user filters so we know that
    // the request and response are AbstractRequest and Response.
    CauchoRequest req = (CauchoRequest) request;
    CauchoResponse res = (CauchoResponse) response;

    AbstractConstraint []constraints = null;
    if (_methodMap != null)
      constraints = _methodMap.get(req.getMethod());

    if (constraints == null)
      constraints = _constraints;

    AuthorizationResult result = AuthorizationResult.NONE;

    // XXX: better logging on failure

    boolean isPrivateCache = false;
    if (constraints != null) {
      for (AbstractConstraint constraint : constraints) {
        result = constraint.isAuthorized(req, res, _webApp);

        if (constraint.isPrivateCache())
          isPrivateCache = true;

        if (! result.isFallthrough())
          break;
      }
    }

    if (isPrivateCache)
      res.setPrivateCache(true);

    // server/1af3, server/12d2
    if (req.isLoginRequested() && req.login(result.isFail())) {
      if (result.isResponseSent())
        return;
    }

    if (result.isFail()) {
      if (! result.isResponseSent()
          && ! res.isCommitted()
          && res.getStatus() / 100 == 2) {
        res.sendError(HttpServletResponse.SC_FORBIDDEN);
      }

      return;
    }
View Full Code Here

  public void forward(ServletRequest topRequest, ServletResponse topResponse,
                      String method, Invocation invocation,
                      DispatcherType type)
    throws ServletException, IOException
  {
    CauchoResponse cauchoRes = null;

    boolean allowForward = _webApp.isAllowForwardAfterFlush();

    if (topResponse instanceof CauchoResponse) {
      cauchoRes = (CauchoResponse) topResponse;

      cauchoRes.setForwardEnclosed(! allowForward);
    }

    // jsp/15m8
    if (topResponse.isCommitted() && method == null && ! allowForward) {
      IllegalStateException exn;
      exn = new IllegalStateException(L.l("forward() not allowed after buffer has committed."));

      if (cauchoRes == null || ! cauchoRes.hasError()) {
        if (cauchoRes != null)
          cauchoRes.setHasError(true);
        throw exn;
      }

      _webApp.log(exn.getMessage(), exn);

      return;
    } else if ("error".equals(method) || (method == null)) {
      // server/10yg
     
      // } else if ("error".equals(method) || (method == null && ! allowForward)) {
      topResponse.resetBuffer();

      if (cauchoRes != null) {
        ServletResponse resp = cauchoRes.getResponse();

        while (resp != null) {
          if (allowForward && resp instanceof IncludeResponse) {
            // server/10yh
            break;
          }
          else if (resp instanceof CauchoResponse) {
            CauchoResponse cr = (CauchoResponse) resp;
            cr.resetBuffer();
            resp = cr.getResponse();
          } else {
            resp.resetBuffer();

            resp = null;
          }
View Full Code Here

TOP

Related Classes of com.caucho.server.http.CauchoResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.