Examples of Reply


Examples of org.w3c.jigsaw.http.Reply

     */
    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

Examples of org.w3c.jigsaw.http.Reply

     */
    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

Examples of org.w3c.jigsaw.http.Reply

    ": 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

Examples of org.w3c.jigsaw.http.Reply

    {
  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

Examples of org.w3c.jigsaw.http.Reply

     */
    protected Reply getDirectoryResource(Request request)
  throws ProtocolException, ResourceException
    {
  if (!checkExpect(request)) {
      Reply reply = createDefaultReply(request, HTTP.EXPECTATION_FAILED);
      reply.setContent("The requested expectation could not be"+
           " met by the resource");
      return reply;
  }
  String index = getIndex();
  if ( index != null && index.length() > 0 ) {
      if (index.equals("*forbid*")) {
    Reply rep = request.makeReply(HTTP.FORBIDDEN);
    rep.setContent("<h1>Forbidden</h1>"+
             "The directory resource "+ request.getURL() +
             " cannot be browsed");
    return rep;
     }
  }
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

     * @exception ResourceException If the resource got a fatal error.
     */
    protected Reply headOtherResource(Request request)
  throws ProtocolException, ResourceException
    {
  Reply reply = null;
  reply = getOtherResource(request) ;
  reply.setStream((InputStream) null);
  return reply;
    }
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

  // If we are at an illegal depth, don't include.
  Integer depth = (Integer) variables.get("depth") ;
  int maxDepth = ((Integer)variables.get("maxDepth")).intValue() ;

  if(maxDepth != 0 && depth.intValue()>maxDepth) {
      Reply reply = ssiframe
    .createCommandReply(request,HTTP.OK) ;
      reply.setContent("[recursion depth limit exceeded]") ;
     
      handleSimpleIMS(request,reply) ;
      return reply ;
  }
 
  Request subReq = null ;
  Reply subRep = null ;
 
  try {
      // Prepare an internal request
      subReq =
    prepareRequest(request,
             new URL(ssiframe.getURL(request)
               , targetName)
             .toString(),
             variables,
             depth) ;
     
      // Obtain a reply for it
      subRep =
        (Reply) ssiframe.getFileResource().getServer().perform(subReq) ;
     
      // If it has status NOT_MODIFIED, it means the included
      // ssiframe was also SSI, and we don't calculate anything
      // here.
      // Otherwise, see if we can reply NOT_MODIFIED.
      if(subRep.getStatus() != HTTP.NOT_MODIFIED) {
    long ims = request.getIfModifiedSince() ;
   
    if(ims==-1) {
        Long IMS = (Long)
      request.getState(STATE_IF_MODIFIED_SINCE) ;
        if(IMS != null) ims = IMS.longValue() ;
    }
   
    long lmd = subRep.getLastModified() ;
    lmd -= lmd % 1000 ; // this is annoying
   
    if(ims != -1 && lmd != -1 && ims>=lmd) {
        subRep.setStatus(HTTP.NOT_MODIFIED) ;
        //close the stream
        subRep.openStream().close();
    }
      }
     
      return subRep ;
     
  } catch(MalformedURLException ex) {
      Reply reply = ssiframe
    .createCommandReply(request,HTTP.OK) ;
      reply.setContent("[malformed URL]") ;
      handleSimpleIMS(request,reply) ;
      return reply ;
  } catch(Exception ex) {
      Reply reply = ssiframe
    .createCommandReply(request,HTTP.OK) ;
      reply.setContent("[error including: "+targetName+"]") ;
      handleSimpleIMS(request,reply) ;
      return reply ;
  }
    }
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

      if ( list != null )
    cookie = list.getCookie(pif);
      content = (cookie != null) ? pthen : palt;
  }
  // We are NOT doing notMod hack here (tricky and useless ?)
  Reply reply = ssiframe.createCommandReply(request, HTTP.OK);
  reply.setContent(content);
  return reply;
    }
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

    public ReplyInterface outgoingFilter(RequestInterface req,
           ReplyInterface rep)
  throws ProtocolException
    {
  Request request = (Request) req;
  Reply   reply   = (Reply) rep;
  // Filter valid replies:
  int status = reply.getStatus();
  switch (status/100) {
  case 1:
  case 2:
  case 3:
  case 10:
      return null;
  }
  // Filter replies that are already taken care of:
  if ( request.hasState(ERRED) )
      return null;
  // Hack error replies:
  Request ereq  = (Request) request.getClone();
  Reply   erep  = null;
  try {
      ereq.setState(ERRED, Boolean.TRUE);
      ereq.setURLPath(getErrorResource(status));
      if (request.getMethod().equals(HTTP.HEAD)) {
    ereq.setMethod(HTTP.HEAD);
      } else {
    ereq.setMethod(HTTP.GET);
      }
      // remove conditional statements
      ereq.setIfModifiedSince(-1);
      ereq.setIfUnmodifiedSince(-1);
      ereq.setIfMatch(null);
      ereq.setIfNoneMatch(null);
      if (ereq.getIfRange() != null) {
    ereq.setIfRange(null);
      }
      ereq.setCacheControl(null);
      erep = (Reply) getServer().perform(ereq);
      // Hack back the original reply into the new reply:
      // - Put back the status
      HeaderValue v = null;
      erep.setStatus(reply.getStatus());
      // - Put back the authenticate informations
      v = reply.getHeaderValue(reply.H_WWW_AUTHENTICATE);
      erep.setHeaderValue(reply.H_WWW_AUTHENTICATE, v);
      // - Put back the proxy authenticate informations
      v = reply.getHeaderValue(reply.H_PROXY_AUTHENTICATE);
      erep.setHeaderValue(reply.H_PROXY_AUTHENTICATE, v);
  } catch (Exception ex) {
      return reply;
  }
  return erep;
    }
View Full Code Here

Examples of org.w3c.jigsaw.http.Reply

    public ReplyInterface exceptionFilter(RequestInterface request,
            ProtocolException ex,
            FilterInterface filters[],
            int idx)
    {
  Reply reply = (Reply) ex.getReply();
  if ( reply != null ) {
      try {
    return outgoingFilter(request, reply, filters, idx);
      } catch (ProtocolException exx) {
      }
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.