Package org.w3c.www.protocol.http

Examples of org.w3c.www.protocol.http.Reply


    public boolean exceptionFilter(Request request, HttpException ex) {
  // if it was a proxy connection, try a direct one
  // add test for exception here
  if(request.hasProxy()) {
      Reply reply       = null;
      HttpManager hm    = HttpManager.getManager();
      request.setProxy(null);
      if ( debug )
    System.out.println("["+getClass().getName()+"]: direct fetch "
           +"for " + request.getURL());
View Full Code Here


     * Forbid access to the given request.
     * @param request The request to apply the rule too.
     */

    public Reply apply(Request request) {
  Reply reply = request.makeReply(HTTP.OK);
  reply.setContent("<h1>Access forbidden</h1>"
       + "<p>Access to "+request.getURL()
       + " is forbidden by proxy dispatcher rules.");
  reply.setContentType(org.w3c.www.mime.MimeType.TEXT_HTML);
  return reply;
    }
View Full Code Here

  // Now restart the request we the right auth infos:
  if ( request.hasProxy() )
      request.setProxyAuthorization(credentials);
  else
      request.setAuthorization(credentials);
  Reply retry = request.getManager().runRequest(request);
  if ( retry.getStatus() / 100 != 4 ) {
      // We did succeed, register server/realm infos:
      registerRealm(request, reply, credentials);
      // Create the local auth filter:
      if ( request.hasProxy() ) {
    LocalAuthFilter.installProxyAuth(manager, credentials);
View Full Code Here

  int lb = r.getLastPosition();
  int sz;
  if (fb > cl-1) { // first byte already out of range
      HttpContentRange cr = HttpFactory.makeContentRange("bytes", 0,
                     cl - 1, cl);
      Reply rr;
      rr = request.makeReply(HTTP.REQUESTED_RANGE_NOT_SATISFIABLE);
      rr.setContentLength(-1);
      rr.setHeaderValue(rr.H_CONTENT_RANGE, cr);
      rr.setContentMD5(null);
      return rr;
  }
  if ((fb < 0) && (lb >= 0)) { // ex: bytes=-20 final 20 bytes
      if (lb >= cl)   // cut the end
    lb = cl;
      sz = lb;
      fb = cl - lb;
      lb = cl - 1;
  } else if (lb < 0) {  // ex: bytes=10- the last size - 10
      lb = cl-1;
      sz = lb-fb+1;
  } else {              // ex: bytes=10-20
      if (lb >= cl// cut the end
    lb = cl-1;
      sz = lb-fb+1;
  }
  if ((fb < 0) || (lb < 0) || (fb <= lb)) {
      HttpContentRange cr = null;
      fb = (fb < 0) ? 0 : fb;
      lb = ((lb > cl) || (lb < 0)) ? cl : lb;
      cr = HttpFactory.makeContentRange("bytes", fb, lb, cl);
      // Emit reply:
      Reply rr = request.makeReply(HTTP.PARTIAL_CONTENT);
      try {
    rr.setContentMD5(null); // just in case :)
    rr.setContentLength(sz);
    rr.setHeaderValue(rr.H_CONTENT_RANGE, cr);
    rr.setStream(new ByteRangeOutputStream(getFile(), fb, lb+1));
    return rr;
      } catch (IOException ex) {
      }
  }
  return null;
View Full Code Here

    {
  // If the resource is currently being uploaded, wait:
  waitUpload();
  // Now perform the request:
  try {
      Reply   reply       = null;
      boolean needsEntity = true;
      // Handle range requests:
      HttpRange ranges[] = request.getRange();
      if ((ranges != null) && (ranges.length == 1))
    reply = handleRangeRequest(request, ranges[0]);
      // Handle full retreivals:
      if ( reply == null ) {
    int status = getStatus();
    // Try validating first
    // NOTE: We know we are only dealing with GETs and HEADs here
    // otherwise the cache wouldn't be used...
    int cim = checkIfMatch(request);
    if ( (cim == COND_FAILED) || (cim == COND_WEAK) ) {
        status      = HTTP.PRECONDITION_FAILED;
        needsEntity = false;
        reply = request.makeReply(status);
        reply.setContent("Pre-conditions failed.");
        throw new HttpException(request, reply, "pre-condition");
          } else if ( checkIfUnmodifiedSince(request) == COND_FAILED ) {
        status      = HTTP.PRECONDITION_FAILED;
        reply = request.makeReply(status);
        reply.setContent("Pre-conditions failed.");
         throw new HttpException(request, reply, "pre-condition");
    } else if ( checkValidators(request) == COND_FAILED ) {
        status      = HTTP.NOT_MODIFIED;
        needsEntity = false;
    }
    // Emit reply:
    reply = request.makeReply(status);
    if ( needsEntity ) {
        reply.setStream(getInputStream());
    }
      }
      setReplyHeaders(reply);
      // Check if entity is needed:
      String mth = request.getMethod();
      if ( mth.equals("HEAD") || mth.equals("OPTIONS") )
    reply.setStream(null);
//      filter.markUsed(this);
      return reply;
  } catch (IOException ex) {
//      if (debug)
//    ex.printStackTrace();
View Full Code Here

     * @param the request that requested this entity
     * @param the reply triggered by this request
     */
    protected void updateInfo(Request request, Reply rep) {
  String   mth       = request.getMethod();
  Reply    reply     = (Reply) rep.getClone();
  boolean  hasEntity = !(mth.equals("HEAD") || mth.equals("OPTIONS"));
  // is it a revalidation?
  if (!request.hasState(CacheState.STATE_REVALIDATION)) {
      // no, go for it!
      HttpCacheControl hcc = reply.getCacheControl();
      // first we should NOT cache headers protected by a no-cache
      // per rfc2616@14.9
      if (hcc != null) {
    String nocache[] = hcc.getNoCache();
    if (nocache != null) {
        for (int i=0; i< nocache.length; i++) {
      reply.setHeaderValue(nocache[i], null);
        }
    }
      }
      setStatus(reply.getStatus());
      setContentType(reply.getContentType());
      setContentLength(reply.getContentLength());
      setLastModified(reply.getLastModified());
      setContentMD5(reply.getContentMD5());
      String vary[] = reply.getVary();
      setVary(vary);
      if (vary != null) {
    // update the conneg headers
    ArrayDictionary a = null;
    for (int i=0; i< vary.length; i++) {
        if (vary[i].equals("*")) {
      continue;
        }
        if (a == null) {
      a = new ArrayDictionary(vary.length);
        }
        a.put (vary[i].toLowerCase(), request.getValue(vary[i]));
    }
    // FIXME we should be able to update to save multiple
    // matches, but with a limitation of course
    if (a != null) {
        setConnegHeaders(a);
    }
      }
      if (reply.hasHeader(reply.H_ETAG)) {
    setETag(reply.getETag().toString());
      } else {
    // be safe here!
    setETag(null);
      }
      ArrayDictionary a = new ArrayDictionary(5, 5);
      Enumeration     e = reply.enumerateHeaderDescriptions();
      while ( e.hasMoreElements() ) {
    HeaderDescription d = (HeaderDescription) e.nextElement();
    // Skip all well-known headers:
    if ( d.isHeader(Reply.H_CONTENT_TYPE)
         || d.isHeader(Reply.H_CONTENT_LENGTH)
         || d.isHeader(Reply.H_LAST_MODIFIED)
         || d.isHeader(Reply.H_ETAG)
         || d.isHeader(Reply.H_AGE)
         || d.isHeader(Reply.H_DATE)
         || d.isHeader(Reply.H_VARY)
         || d.isHeader(Reply.H_CONNECTION)
         || d.isHeader(Reply.H_PROXY_CONNECTION)
         || d.isHeader(Reply.H_TRANSFER_ENCODING)
         || d.isHeader(Reply.H_CONTENT_MD5)
         || d.getName().equalsIgnoreCase("keep-alive"))
        continue;
    // This is an extra header:
    a.put(d.getName(), reply.getValue(d));
      }
      setExtraHeaders(a);
      // FIXME add the headers ;)
     
  }
View Full Code Here

    }
    request.setState(STATE_NOCACHE, Boolean.TRUE);
    return null;
      } else {
    // disconnected, abort now!
    Reply reply = request.makeReply(HTTP.GATEWAY_TIMEOUT);
    reply.setContent("The cache cannot be use for "
         + "<p><code>"+request.getMethod()+"</code> "
         + "<strong>"+request.getURL()+"</strong>"
         + ". <p>It is disconnected.");
    return reply;
      }
  }
  // let's try to get the resource!

  String requrl = request.getURL().toExternalForm();
  // in the pre-cache, wait for full download
  // FIXME should be better than this behaviour...
  // see EntityCachedResource perform's FIXME ;)
  if (precache.containsKey(requrl)) {
      if (debug)
    System.out.println("*** Already downloading: "+ requrl);
      try {
    CachedResource cr = (CachedResource)precache.get(requrl);
    return cr.perform(request);
      } catch (Exception ex) {
    // there was a problem with the previous request,
    // it may be better to do it by ourself
      }
  }
 
  CachedResource res = null;
  try {
      res = store.getCachedResourceReference(requrl);
  } catch (InvalidCacheException ex) {
      res = null;
  }

  // Is this a push resource ?
  try {
      if(PushCacheManager.instance().isPushResource(res)) {
    EntityCachedResource ecr=(EntityCachedResource)
        res.lookupResource(request);
         
    if(ecr!=null) {
        Reply reply = ecr.perform(request);
        return reply;
    }
      }
  }
  catch(Exception e) {
    e.printStackTrace();
  }
  // /PSLH


  // are we disconnected?
  if (request.checkOnlyIfCached() || !connected ) {
      // and no entries...
      EntityCachedResource ecr = null;
      if (res != null) {
    ecr = (EntityCachedResource) res.lookupResource(request);
      }
      if ((res == null) || (ecr == null)) {
    if ( debug )
        trace(request, "unavailable (disconnected).");
    Reply reply = request.makeReply(HTTP.GATEWAY_TIMEOUT);
    reply.setContent("The cache doesn't have an entry for "
         + "<p><strong>"+request.getURL()+"</strong>"
         + ". <p>And it is disconnected.");
    return reply;
      }
      // yeah!
      if (debug) {
    trace(request, (connected) ? " hit - only if cached" :
          " hit while disconneced" );
      }
      if (!validator.isValid(ecr, request)) {
    addWarning(request, WARN_STALE);
      }
      addWarning(request, WARN_DISCONNECTED);
      Reply reply = ecr.perform(request);
    // Add any warnings collected during processing to the reply:
      setWarnings(request, reply);
//FIXME      request.setState(STATE_HOW, HOW_HIT);
      return reply;
  }

  // in connected mode, we should now take care of revalidation and such
  if (res != null) {
      // if not fully loaded, ask for a revalidation FIXME
      if ((res.getLoadState() == CachedResource.STATE_LOAD_PARTIAL) ||
    (res.getLoadState() == CachedResource.STATE_LOAD_ERROR)) {
    setRequestRevalidation(res, request);
    return null;
      }

      if ( validator.isValid(res, request) ) {
    try {
        store.updateResourceGeneration(res);
    } catch (InvalidCacheException ex) {
        // should be ok so...
    }
//FIXME      request.setState(STATE_HOW, HOW_HIT);
    Reply rep = res.perform(request);
    return rep;
      } else {
    if (debug) {
        System.out.println("*** Revalidation asked for " + requrl);
    }
View Full Code Here

TOP

Related Classes of org.w3c.www.protocol.http.Reply

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.