Examples of Reply


Examples of org.w3c.jigsaw.http.Reply

     */
    protected Reply getOtherResource(Request request)
  throws ProtocolException, ResourceException
    {
  // we don't manage this kind of resource
  Reply error = request.makeReply(HTTP.NOT_IMPLEMENTED) ;
  error.setContent("Method GET not implemented.<br><br>"+
       "The administration server does not use plain "+
       "HTTP but a variant of it. The only tool available "+
       "for now is an application called <b>JigAdmin</b>. "+
       "Please read the documentation.");
  throw new HTTPException (error) ;
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

    protected Reply dupReply(Request request
           , org.w3c.www.protocol.http.Reply rep)
  throws HTTPException, IOException
    {
  Reply reply = request.makeReply(rep.getStatus());
  // get rid of "by default" headers wchich SHOULD NOT be modified
  reply.setHeaderValue(Reply.H_SERVER, null);
        // Duplicate reply header values:
  Enumeration e = rep.enumerateHeaderDescriptions();
  while ( e.hasMoreElements() ) {
      HeaderDescription d = (HeaderDescription) e.nextElement();
      HeaderValue       v = rep.getHeaderValue(d);
      if ( v != null )
    reply.setHeaderValue(d, v);
  }
  // Get rid of hop by hop headers:
  reply.setHeaderValue(Reply.H_CONNECTION, null);
  reply.setHeaderValue(Reply.H_PROXY_CONNECTION, null);
  reply.setHeaderValue(Reply.H_PROXY_AUTHENTICATE, null);
  reply.setHeaderValue(Reply.H_PUBLIC, null);
  reply.setHeaderValue(Reply.H_TRANSFER_ENCODING, null);
  reply.setHeaderValue(Reply.H_UPGRADE, null);
  reply.setHeaderValue(Reply.H_TRAILER, null);
  reply.removeHeader("keep-alive");
  // Get rid of the fields enumerated in the connection header:
  String conn[] = rep.getConnection();
  if (conn != null) {
      for (int i = 0 ; i < conn.length ; i++)
    reply.removeHeader(conn[i]);
  }
  // check if nasty people are mixing Content-Length and chunking
  if (reply.getContentLength() >= 0 ) {
      String te[] = rep.getTransferEncoding() ;
      if ( te != null ) {
    for (int i = 0 ; i < te.length ; i++) {
        if (te[i].equals("chunked")) {
      reply.setContentLength(-1);
        }
    }
      }
  }
  // Update the via route:
  reply.addVia(getVia());
  // Update the reply output stream:
  try {
      reply.setStream(rep.getInputStream());
  } catch (Exception ex) {};
  // if reply is using bad HTTP version we should close it
  if (rep.getMajorVersion() == 0) {
      reply.setKeepConnection(false);
  }
  // if HTTP/1.0 and no Content-Length also...
  if ((rep.getMajorVersion() == 1) &&
      (rep.getMajorVersion() == 0) &&
      (reply.getContentLength() == -1)) {
      reply.setKeepConnection(false);
  }
  // check the age
  int age = rep.getAge();
  if (age >= 0 ) {
      // check if it is an heuristic expiration without a warning
      if (age > 86400) {
    if ((rep.getExpires() == -1) && (rep.getMaxAge() == -1) &&
        (rep.getSMaxAge() == -1)) {
        // rfc2616: 13.2.4 on behalf of a bad upstream server
        HttpWarning w[] = rep.getWarning();
        boolean doit = true;
        if (w != null) {
      for (int i=0; doit && (i<w.length); i++) {
          doit = (w[i].getStatus() != 113);
      }
        }
        if (doit) {
      reply.addWarning(WARN_HEURISTIC);
        }
    }
      }
  }
  reply.setProxy(true);
  return reply;
    }
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

  int sz;

  if (fb > cl-1) { // first byte already out of range
      HttpContentRange cr = HttpFactory.makeContentRange("bytes", 0,
                     cl - 1, cl);
      Reply rr;
      rr = createDefaultReply(request,
            HTTP.REQUESTED_RANGE_NOT_SATISFIABLE);
      rr.setContentLength(-1);
      rr.setHeaderValue(rr.H_CONTENT_RANGE, cr);
      if (getMD5Flag())
    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 = createDefaultReply(request, HTTP.PARTIAL_CONTENT);
      // FIXME check for MD5 of only the subpart
      try { // create the MD5 for the subpart
    if (getMD5Flag()) {
        String s = null;
        try {
      ByteRangeOutputStream br;
      br = new ByteRangeOutputStream(fresource.getFile(),
                   fb, lb+1);
      Md5 md5 = new Md5 (br);
      byte b[] = md5.getDigest();
      Base64Encoder b64;
      ByteArrayOutputStream bs = new ByteArrayOutputStream();
      b64 = new Base64Encoder(new ByteArrayInputStream(b),
            bs);
      b64.process();
      s = bs.toString();
        } catch (Exception md_ex) {
      // default to null, no action here then
        }
        if (s == null)
      rr.setContentMD5(null);
        else
      rr.setContentMD5(s);
    }
          rr.setContentLength(sz);
    rr.setHeaderValue(rr.H_CONTENT_RANGE, cr);
    rr.setStream(new ByteRangeOutputStream(fresource.getFile(),
                   fb,
                   lb+1));
    return rr;
      } catch (IOException ex) {
      }
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

        try {
            dresource.delete();
        } catch (MultipleLockException ex) {
        }
        // Emit an error back:
        Reply error = request.makeReply(HTTP.NOT_FOUND) ;
        error.setContent ("<h1>Document not found</h1>"+
                 "<p>The document "+
              request.getURL()+
              " is indexed but not available."+
              "<p>The server is misconfigured.") ;
        throw new HTTPException (error) ;
    }
    refresh =
      (dresource.getDirectory().lastModified() >
                                             listing_stamp);
      }
  }
  if ((! computeContainerListing(refresh)) &&
      ( checkIfModifiedSince(request) == COND_FAILED )) {
      // Is it an IMS request ?
      Reply reply = createDefaultReply(request, HTTP.NOT_MODIFIED) ;
      return reply;
  }
  // New content or need update:
  Reply reply = createDefaultReply(request, HTTP.OK) ;
  reply.setLastModified(listing_stamp) ;
  reply.setStream(listing) ;
  // check MD5
  return reply ;
    }
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

     * @param request The request to make a reply for.
     * @return An instance of Reply, suited to answer this request.
     */

    public Reply createDefaultReply(Request request, int status) {
  Reply reply = request.makeReply(status);
  updateCachedHeaders();
  if ( status != HTTP.NOT_MODIFIED ) {
      if ( contentlength != null )
    reply.setHeaderValue(Reply.H_CONTENT_LENGTH, contentlength);
      if ( contenttype != null )
    reply.setHeaderValue(Reply.H_CONTENT_TYPE, contenttype);
      if ( lastmodified != null )
    reply.setHeaderValue(Reply.H_LAST_MODIFIED, lastmodified);
      if ( contentencoding != null ) {
    reply.setHeaderValue(Reply.H_CONTENT_ENCODING,contentencoding);
      }
      if ( contentlanguage != null )
    reply.setHeaderValue(Reply.H_CONTENT_LANGUAGE,contentlanguage);

  }
  long maxage = getMaxAge();
  if ( maxage >= 0 ) {
      if (reply.getMajorVersion() >= 1 ) {
    if (reply.getMinorVersion() >= 1) {
        reply.setMaxAge((int) (maxage / 1000));
    }
    // If max-age is zero, say what you mean:
    long expires = (System.currentTimeMillis()
        + ((maxage == 0) ? -1000 : maxage));
    reply.setExpires(expires);
      }
  }
  // Set the date of the reply (round it to secs):
  reply.setDate((System.currentTimeMillis() / 1000L) * 1000L);

  if (fresource != null) {
      // Set the entity tag:
      if ( getETag() != null ) {
    reply.setETag(etag);
      }
      if ( status != HTTP.NOT_MODIFIED ) {
    if ( acceptRanges ) {
        reply.setHeaderValue(reply.H_ACCEPT_RANGES,_accept_ranges);
    }
    if ( getMD5Flag()) {
        reply.setHeaderValue(reply.H_CONTENT_MD5, getMd5Digest());
    }
      }
  }
  return reply;
    }
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

    public ReplyInterface perform(RequestInterface ri)
  throws org.w3c.tools.resources.ProtocolException,
         org.w3c.tools.resources.ResourceException
    {
  Request request = (Request) ri;
  Reply   reply  = null;
  boolean stated = false;
  // check the expectations
  if (!checkExpect(request)) {
      reply = createDefaultReply(request, HTTP.EXPECTATION_FAILED);
      reply.setContent("The requested expectation could not be"+
           " met by the resource");
      return reply;
  }
  // Perform the request:
  try {
      if (request.getMaxForwards() != -1) { // 14.31 decrement the value
    if (request.getMaxForwards() == 0) {
        if (request.getMethod().equals("TRACE") ||
      request.getMethod().equals("OPTIONS"))
      return super.perform(request);
    }
      }

      org.w3c.www.protocol.http.Request     req = dupRequest(request);
      org.w3c.www.protocol.http.Reply       rep = null;
      // Perform the request
      rep = manager.runRequest(req);
      // Dump back the client reply into a server reply:
      reply = dupReply(request, rep);
      // Update statistics:
      updateStatistics(req);
      stated = true;
      // Trace the request (debug):
      if ( getTraceRequest() ) {
//    if ( req.hasState(CacheFilter.STATE_HOW) ) {
//        System.out.println(request.getURL()+": "+
//               CacheFilter.getHow(req));
//    }
//    if ( req.hasState(micp) )
//        System.out.println(req.getURL()+": (icp) "+
//               req.getState(micp));
      }
  } catch (HTTPException shex) {
      // An server-side HTTP-related error happened
      if (debug) {
    System.out.println("HTTP Server Exception while running"
           +" request:");
    shex.printStackTrace();
      }
      // Make sure the request is accounted:
      if ( ! stated ) {
    synchronized(this) {
        reqcount++;
        reqerred++;
    }
    stated = true;
      }
      Reply r = (Reply) shex.getReply();
      if (reply == null) {
    // Send an appropriate error message back:
    reply = request.makeReply(HTTP.BAD_GATEWAY);
    boolean showerr =
        props.getBoolean(httpd.DISPLAY_URL_ON_ERROR_P, false);
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

        if (ls.countRemainingComponents() == 1)
      rr = dresource.createResource(name, request);
        else
      rr = dresource.createDirectoryResource(name);
        if (rr == null) {
      Reply error =
          request.makeReply(HTTP.UNSUPPORTED_MEDIA_TYPE);
      error.setContent(
          "Failed to create resource "+
          name +" : "+
          "Unable to create the appropriate file:"+
          request.getURLPath()+
          " this media type is not supported");
      throw new HTTPException (error);
        }
    } else if (rr == null) {
        Reply error = request.makeReply(HTTP.FORBIDDEN) ;
        error.setContent("You are not allowed to create resource "+
             name +" : "+
             dresource.getIdentifier()+
             " is not extensible.");
        throw new HTTPException (error);
    }
      }
  }
  if ( super.lookup(ls, lr) ) {
      if ( ! ls.isDirectory() && ! ls.isInternal() ) {
    // The directory lookup URL doesn't end with a slash:
    Request request = (Request)ls.getRequest() ;
    if ( request == null ) {
        lr.setTarget(null);
        return true;
    }
    URL url = null;
    try {
        if ((request != null ) &&
      request.hasState(Request.ORIG_URL_STATE)) {
      URL oldurl;
      oldurl = (URL)request.getState(Request.ORIG_URL_STATE);
      url = new URL(oldurl, oldurl.getFile() + "/");
        } else {
      url = (ls.hasRequest()
             ? getURL(request)
             : new URL(getServer().getURL(),
           resource.getURLPath()));
        }
    } catch (MalformedURLException ex) {
        getServer().errlog(this, "unable to build full URL.");
        throw new HTTPException("Internal server error");
    }
    String msg = "Invalid requested URL: the directory resource "+
        " you are trying to reach is available only through "+
        " its full URL: <a href=\""+
        url + "\">" + url + "</a>.";
    if ( getRelocateFlag() ) {
        // Emit an error (with reloc if allowed)
        Reply reloc = request.makeReply(HTTP.FOUND);
        reloc.setContent(msg) ;
        reloc.setLocation(url);
        lr.setTarget(null);
        lr.setReply(reloc);
        return true;
    } else {
        Reply error = request.makeReply(HTTP.NOT_FOUND) ;
        error.setContent(msg) ;
        lr.setTarget(null);
        lr.setReply(error);
        return true;
    }
      } else if ( ! ls.isInternal() ) {
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

      return repi;

  if (! checkRequest(req))
      return null;

  Reply  reply  = null;
  Request request = (Request) req;
  String method = request.getMethod () ;
  // Perform the request:
  if ( method.equals("GET") ) {
      reply = get(request) ;
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

    {
  if (resource instanceof ContainerResource) {
      return getDirectoryResource(request);
  } else {
      // we don't manage this kind of resource
      Reply error = request.makeReply(HTTP.NOT_IMPLEMENTED) ;
      error.setContent("Method GET not implemented.") ;
      throw new HTTPException (error) ;
  }
    }
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

      ex.printStackTrace();
      throw new HTTPException("unable to dump root: "+ex.getMessage());
  }
  byte bits[] = bout.toByteArray();
  // Setup the reply:
  Reply reply = request.makeReply(HTTP.OK);
  reply.setStream(new ByteArrayInputStream(bits));
  reply.setContentLength(bits.length);
  reply.setContentType(AdminContext.conftype);
  return reply;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.