Package com.caucho.server.http

Examples of com.caucho.server.http.CauchoRequest


                  HttpServletResponse res,
                  ServletContext application)
    throws IOException
  {
    // server/1kk7
    CauchoRequest cRequest = (CauchoRequest) req;
    HttpServletResponseImpl responseImpl = (HttpServletResponseImpl) res;

    AbstractHttpRequest absRequest = cRequest.getAbstractHttpRequest();
    HttpServletRequestImpl request = absRequest.getRequestFacade();
    AbstractHttpResponse response = responseImpl.getAbstractHttpResponse();

    // skip excluded urls
    if (_excludes.length > 0) {
View Full Code Here


   * @return true if the user plays the named role
   */
  @Override
  public boolean isUserInRole(Principal user, String role)
  {
    CauchoRequest request
      = (CauchoRequest) TcpSocketLink.getCurrentRequest();

    return isUserInRole(request,
                        null, // request.getResponse(),
                        request.getServletContext(),
                        user,
                        role);
  }
View Full Code Here

  public void doFilter(ServletRequest request, ServletResponse response)
    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()) {
View Full Code Here

    throws ServletException, IOException
  {
    if (_requestCharacterEncoding != null)
      request.setCharacterEncoding(_requestCharacterEncoding);

    CauchoRequest oldRequest = null;
    AbstractHttpResponse cauchoResponse = null;

    if (_isRequestSecure == null) {
    }
    else if (request instanceof HttpServletRequestImpl) {
      HttpServletRequestImpl req = (HttpServletRequestImpl) request;

      req.setSecure(_isRequestSecure);
    }
    else {
      CauchoRequest cauchoRequest
        = new SetRequestSecureFilterChain.SecureServletRequestWrapper((HttpServletRequest) request,
                                                                      _isRequestSecure);

      /* XXX:
      if (response instanceof CauchoResponse
View Full Code Here

  @Override
  public void service(ServletRequest request, ServletResponse response)
    throws ServletException, IOException
  {
    CauchoRequest cauchoReq = null;
    HttpServletRequest req;
    HttpServletResponse res;

    if (request instanceof CauchoRequest) {
      cauchoReq = (CauchoRequest) request;
      req = cauchoReq;
    }
    else
      req = (HttpServletRequest) request;

    res = (HttpServletResponse) response;

    boolean isInclude = false;
    String uri;

    uri = (String) req.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
    if (uri != null)
      isInclude = true;
    else
      uri = req.getRequestURI();
   
    Cache cache = _localCache.get(uri);

    String filename = null;
   
    String cacheUrl = null;

    if (cache == null) {
      cacheUrl = getCacheUrl(req, uri);
     
      cache = _pathCache.get(cacheUrl);
     
      if (cache != null)
        _localCache.put(uri, cache);
    }
   
    if (cache == null) {
      CharBuffer cb = new CharBuffer();
      String servletPath;

      if (cauchoReq != null)
        servletPath = cauchoReq.getPageServletPath();
      else if (isInclude)
        servletPath = (String) req.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
      else
        servletPath = req.getServletPath();

      if (servletPath != null)
        cb.append(servletPath);

      String pathInfo;
      if (cauchoReq != null)
        pathInfo = cauchoReq.getPagePathInfo();
      else if (isInclude)
        pathInfo
          = (String) req.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
      else
        pathInfo = req.getPathInfo();

      if (pathInfo != null)
        cb.append(pathInfo);

      String relPath = cb.toString();

      if (_isCaseInsensitive)
        relPath = relPath.toLowerCase(Locale.ENGLISH);

      filename = getServletContext().getRealPath(relPath);
      Path path = _context.lookupNative(filename);

      // only top-level requests are checked
      if (cauchoReq == null || cauchoReq.getRequestDepth(0) != 0) {
      }
      else if (relPath.regionMatches(true, 0, "/web-inf", 0, 8)
               && (relPath.length() == 8
                   || ! Character.isLetterOrDigit(relPath.charAt(8)))) {
        res.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
      }
      else if (relPath.regionMatches(true, 0, "/meta-inf", 0, 9)
               && (relPath.length() == 9
                   || ! Character.isLetterOrDigit(relPath.charAt(9)))) {
        res.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
      }

      if (relPath.endsWith(".DS_store")) {
        // MacOS-X security hole with trailing '.'
        res.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
      }
      else if (! CauchoSystem.isWindows() || relPath.length() == 0) {
      }
      else if (path.isDirectory()) {
      }
      else if (path.isWindowsInsecure()) {
        // Windows security issues with trailing '.'
        res.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
      }

      // A null will cause problems.
      for (int i = relPath.length() - 1; i >= 0; i--) {
        char ch = relPath.charAt(i);

        if (ch == 0) {
          res.sendError(HttpServletResponse.SC_NOT_FOUND);
          return;
        }
      }

      ServletContext webApp = getServletContext();

      String mimeType = webApp.getMimeType(relPath);

      boolean isPathReadable = path.canRead();
      Path jarPath = null;

      if (! isPathReadable) {
        String resource = "META-INF/resources" + relPath;
        URL url = webApp.getClassLoader().getResource(resource);

        if (url != null)
          jarPath = Vfs.lookup(url);
      }

      cache = new Cache(path, jarPath, relPath, mimeType);

      _localCache.put(uri, cache);
     
      _pathCache.put(cacheUrl, cache);
    }
    else if (cache.isModified()) {
      cache = new Cache(cache.getFilePath(),
                        cache.getJarPath(),
                        cache.getRelPath(),
                        cache.getMimeType());
     
      cacheUrl = getCacheUrl(req, uri);
      _pathCache.put(cacheUrl, cache);
      _localCache.put(uri, cache);
    }

    if (_isGenerateSession)
      req.getSession(true);

    if (cache.isDirectory()) {
      if (! uri.endsWith("/")) {
        String queryString = req.getQueryString();
       
        if (queryString != null)
          sendRedirect(res, uri + "/?" + queryString);
        else
          sendRedirect(res, uri + "/");
      }
      else if (_dir != null)
        _dir.forward(req, res);
      else
        res.sendError(HttpServletResponse.SC_NOT_FOUND);
     
      return;
    }

    if (! cache.canRead()) {
      if (isInclude)
        throw new FileNotFoundException(uri);
      else
        res.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    // server/4500, #4218
    String method = req.getMethod();
    if (! method.equalsIgnoreCase("GET")
        && ! method.equalsIgnoreCase("HEAD")
        && ! method.equalsIgnoreCase("POST")) {
      res.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED,
                    "Method not implemented");
      return;
    }

    String ifMatch = req.getHeader("If-None-Match");
    String etag = cache.getEtag();

    if (ifMatch != null && ifMatch.equals(etag)) {
      res.addHeader("ETag", etag);
      res.sendError(HttpServletResponse.SC_NOT_MODIFIED);
      return;
    }

    String lastModified = cache.getLastModifiedString();

    if (ifMatch == null) {
      String ifModified = req.getHeader("If-Modified-Since");

      boolean isModified = true;

      if (ifModified == null) {
      }
      else if (ifModified.equals(lastModified)) {
        isModified = false;
      }
      else {
        long ifModifiedTime;
       
        QDate date = QDate.allocateLocalDate();

        try {
          ifModifiedTime = date.parseDate(ifModified);
        } catch (Exception e) {
          log.log(Level.FINER, e.toString(), e);

          ifModifiedTime = 0;
        }
       
        QDate.freeLocalDate(date);

        isModified = (ifModifiedTime == 0
                      || ifModifiedTime != cache.getLastModified());
      }

      if (! isModified) {
        if (etag != null)
          res.addHeader("ETag", etag);
        res.sendError(HttpServletResponse.SC_NOT_MODIFIED);
        return;
      }
    }

    res.addHeader("ETag", etag);
    res.addHeader("Last-Modified", lastModified);
   
    if (_isEnableRange && cauchoReq != null && cauchoReq.isTop())
      res.addHeader("Accept-Ranges", "bytes");

    if (_characterEncoding != null)
      res.setCharacterEncoding(_characterEncoding);
View Full Code Here

  public void service(ServletRequest request, ServletResponse response)
    throws ServletException, IOException
  {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    CauchoRequest cReq = null;

    if (req instanceof CauchoRequest)
      cReq = (CauchoRequest) req;

    String sessionId = req.getRequestedSessionId();

    String uri;
    if (req.isRequestedSessionIdFromURL()) {
      uri =  (req.getRequestURI() + ";jsessionid=" +
              req.getRequestedSessionId());
    }
    else
      uri = req.getRequestURI();

    String queryString = null;

    if (cReq != null)
      queryString = cReq.getPageQueryString();
    else {
      queryString
        = (String) req.getAttribute(RequestDispatcher.INCLUDE_QUERY_STRING);

      if (queryString == null)
View Full Code Here

    if (! _enable) {
      res.sendError(404);
      return;
    }
   
    CauchoRequest cauchoReq = null;

    if (req instanceof CauchoRequest)
      cauchoReq = (CauchoRequest) req;

    String uri = req.getRequestURI();
    boolean redirect = false;
    String encoding = CharacterEncoding.getLocalEncoding();
    if (encoding == null)
      res.setContentType("text/html");
    else
      res.setContentType("text/html; charset=" + encoding);

    boolean isInclude = false;

    if (cauchoReq != null) {
      uri = cauchoReq.getPageURI();
      isInclude = ! uri.equals(cauchoReq.getRequestURI());
    }
    else {
      uri = (String) req.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
      if (uri != null)
        isInclude = true;
      else
        uri = req.getRequestURI();
    }

    StringBuilder cb = new StringBuilder();
    String servletPath;

    if (cauchoReq != null)
      servletPath = cauchoReq.getPageServletPath();
    else if (isInclude)
      servletPath = (String) req.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
    else
      servletPath = req.getServletPath();
       
    if (servletPath != null)
      cb.append(servletPath);
     
    String pathInfo;
    if (cauchoReq != null)
      pathInfo = cauchoReq.getPagePathInfo();
    else if (isInclude)
      pathInfo = (String) req.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
    else
      pathInfo = req.getPathInfo();
       
View Full Code Here

   * Once the bean's selected, it will be applied.
   */
  public void service(ServletRequest request, ServletResponse response)
    throws IOException, ServletException
  {
    CauchoRequest req = (CauchoRequest) request;
    CauchoResponse res = (CauchoResponse) response;

    if (_urlPrefix == null) {
      synchronized (this) {
        if (_urlPrefix == null)
          serverInit(req);
      }
    }

    if (! req.getMethod().equals("POST")) {
      if (log.isLoggable(Level.FINE))
        log.log(Level.FINE, this + " unexpected method " + req.getMethod());
     
      String protocol = _protocolContainer.getName();
      res.setStatus(500, protocol + " Protocol Error");
      PrintWriter out = res.getWriter();
      out.println(protocol + " expects a POST containing an RPC call.");
      return;
    }

    try {
      String pathInfo = req.getPathInfo();
      String queryString = req.getQueryString();
     
      CharBuffer cb = new CharBuffer();
      cb.append(pathInfo);
      cb.append('?');
      cb.append(queryString);
     
      InputStream is = req.getInputStream();

      if (_isDebug) {
      }

      Skeleton skeleton  = (Skeleton) _beanMap.get(cb);

      if (skeleton == null) {
        // If this was a load just to force the initialization, then return
        if (req.getParameter("ejb-load") != null)
          return;
     
        if (_exception != null)
          throw _exception;

        try {
          if (pathInfo == null)
            pathInfo = "";

          skeleton = _protocolContainer.getSkeleton(pathInfo, queryString);
        } catch (Exception e) {
          log.log(Level.WARNING, e.toString(), e);

          skeleton = _protocolContainer.getExceptionSkeleton();

          if (skeleton != null) {
            skeleton._service(req.getInputStream(), res.getOutputStream(), e);

            return;
          }
          else
            throw e;
        }

        if (skeleton == null)
          throw new ServletException(L.l("Can't load skeleton for '{0}?{1}'",
                                         pathInfo, queryString));

        if (skeleton != null) {
          skeleton.setDebug(_isDebug);
          _beanMap.put(cb, skeleton);
        }
      }

      skeleton._service(req.getInputStream(), res.getOutputStream());
    } catch (ServletException e) {
      e.printStackTrace();
      throw e;
    } catch (Throwable e) {
      e.printStackTrace();
View Full Code Here

   * @param res the servlet response
   */
  public void service(ServletRequest request, ServletResponse response)
    throws IOException, ServletException
  {
    CauchoRequest req;
   
    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

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

TOP

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

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.