Package org.w3c.jigsaw.http

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


    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

        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

      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

    {
  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

      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

     */
    protected Reply createFileReply(Request request)
  throws ProtocolException, ResourceException
    {
  File file = fresource.getFile() ;
  Reply reply = null;
  // Check for a range request:
  HttpRange ranges[] = request.getRange();
  if ((ranges != null) && (ranges.length == 1)) {
      Reply rangereply = handleRangeRequest(request, ranges[0]);
      if ( rangereply != null )
    return rangereply;
  }
  // Default to full reply:
  reply = createDefaultReply(request, HTTP.OK) ;
  try {
      reply.setStream(new FileInputStream(file));
  } catch (IOException ex) {
      Reply error = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
      error.setContent("Error while accessing filesystem");
      return error;
  }
  return reply ;
    }
View Full Code Here

     */
    public ReplyInterface perform(RequestInterface req)
  throws ProtocolException, ResourceException
    {
  Request request = (Request) req;
  Reply   reply   = null;
  auth.authenticate(request);
  //ingoing filters
  for (int i = 0 ; i < filters.length ; i++) {
      reply = (Reply) filters[i].ingoingFilter(req);
      if (reply != null)
    return reply;
  }
  // Maybe that's one of the methods we handle straight ?
  String mth = request.getMethod();
  if ( mth.equals("LOAD-ROOT") ) {
      reply = remoteLoadRoot(request);
  } else {
      // Ok, that's targeted toward a specific target resource:
      try {
    reply = (Reply)broker.perform(request);
      } catch (org.w3c.tools.resources.ProtocolException ex) {
    throw new HTTPException(ex);
      }
  }
  //outgoing filters
  for (int i = filters.length-1 ; i > -1 ; i--) {
      Reply rep = (Reply) filters[i].outgoingFilter(req, reply);
      if (rep != null)
    return rep;
  }
  return reply;
    }
View Full Code Here

    ": deleted, removing the FileResource.";
      getServer().errlog(fresource, msg);
      try {
    fresource.delete();
      } catch (MultipleLockException ex) {
    Reply error = request.makeReply(HTTP.GONE) ;
    error.setContentMD5(null); // FIXME must compute it!
    error.setContent ("<h1>Document Gone</h1>"+
          "<p>The document "+
          request.getURL()+
          " is indexed but no longer available.</p>"+
          "<p>"+ex.getMessage()+"</p>");
    throw new HTTPException (error) ;
      }
  }
  // Emit an error back:
  Reply error = request.makeReply(HTTP.GONE) ;
  error.setContentMD5(null);
  error.setContent ("<h1>Document Gone</h1>"+
        "<p>The document "+
        request.getURL()+
        " is indexed but no longer available.</p>");
  return error;
    }
View Full Code Here

    {
  if (fresource == null)
      throw new ResourceException("this frame is not attached to a "+
          "FileResource. ("+
          resource.getIdentifier()+")");
  Reply reply = null;
  if (!checkExpect(request)) {
      reply = createDefaultReply(request, HTTP.EXPECTATION_FAILED);
      reply.setContent("The requested expectation could not be"+
           " met by the resource");
      return reply;
  }
  File file = fresource.getFile() ;
  fresource.checkContent();
  updateCachedHeaders();
  // Check validators:
  int cim = checkIfMatch(request);
  if ((cim == COND_FAILED) || (cim == COND_WEAK)) {
      reply = request.makeReply(HTTP.PRECONDITION_FAILED);
      reply.setContent("Pre-conditions failed.");
      reply.setContentMD5(null);
      return reply;
  }
  if ( checkIfUnmodifiedSince(request) == COND_FAILED ) {
      reply = request.makeReply(HTTP.PRECONDITION_FAILED);
      reply.setContent("Pre-conditions failed.");
      reply.setContentMD5(null);
      return reply;
  }
  if (checkValidators(request) == COND_FAILED) {
      reply = createDefaultReply(request, HTTP.NOT_MODIFIED);
      return reply;
  }
  // Does this file really exists, if so send it back
  if ( file.exists() ) {
      reply = createFileReply(request);
      if (request.hasState(STATE_CONTENT_LOCATION))
    reply.setContentLocation(getURL(request).toExternalForm());
      return reply;
  } else {
      return deleteMe(request);
  }
    }
View Full Code Here

TOP

Related Classes of org.w3c.jigsaw.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.