Package org.w3c.jigsaw.http

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


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

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

      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

    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

    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

     * @exception ResourceException If the resource got a fatal error.
     */
    public ReplyInterface perform(RequestInterface req)
  throws ProtocolException, ResourceException
    {
  Reply        reply  = (Reply) performFrames(req);
  if (reply != null)
      return reply;
  Request request = (Request) req;
  httpd    server = (httpd) getServer();
  String     host = request.getHost();
  request.setState(Request.ORIG_URL_STATE, request.getURL());
  request.setState(JigsawRequestDispatcher.REQUEST_URI_P,
       getRequestURI(request));
  request.setState(JigsawRequestDispatcher.QUERY_STRING_P,
       request.getQueryString());
  request.setState(JigsawRequestDispatcher.SERVLET_PATH_P, getURLPath());
  try {
      String target = null;
      if (request.hasQueryString())
    target = getTarget()+"?"+request.getQueryString();
      else
    target = getTarget();

      if (host == null) {
    request.setURL(new URL(server.getURL(), target));
      } else {
    int ic = host.indexOf(':');
    // we will take care of '[' later (ipv6 address)
    if ( ic < 0 ) {
        request.setURL(new URL(server.getURL().getProtocol(),
             host, target));
    } else {
        request.setURL(new URL(server.getURL().getProtocol(),
             host.substring(0, ic),
             Integer.parseInt(
                 host.substring(ic+1)),
             target));
    }
      }
      request.setInternal(true);
  } catch (MalformedURLException ex) {
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
      error.setContent("<html><head><title>Server Error</title>"+
           "</head><body><h1>Server misconfigured</h1>"+
           "<p>The resource <b>"+getIdentifier()+"</b>"+
           "has an invalid target attribute : <p><b>"+
           getTarget()+"</b></body></html>");     
      throw new HTTPException (error);
View Full Code Here

    public Reply execute(SSIFrame ssiframe,
       Request request,
       ArrayDictionary parameters,
       Dictionary variables)
    {
  Reply reply =
      ssiframe.createCommandReply(request,HTTP.OK) ;

  reply.setContent("[SSIFrame: unknown command \""+badCommand+"\"]");
 
  return reply ;
    }
View Full Code Here

    public boolean checkConnection() {
  return getBoolean(ATTR_CONNECTION, false);
    }

    private ReplyInterface modifyHeaders(ReplyInterface rep) {
  Reply reply = (Reply) rep;
  String hname = getHeaderName();
  if ( hname != null ) {
      String hvalue = getHeaderValue();
      if ( hvalue == null ) {
    reply.removeHeader(hname);
      } else {
    reply.setValue(hname, hvalue);
      }
      if ( checkNoCache() )
    reply.addNoCache(hname);
      if ( checkConnection() )
    reply.addConnection(hname);
  }
  return null;
    }
View Full Code Here

    public ReplyInterface exceptionFilter(RequestInterface request,
            ProtocolException ex,
            FilterInterface filters[],
            int i) {
  Reply rep = (Reply) ex.getReply();
  if (rep != null) {
      return modifyHeaders(rep);
  }
  return null;
    }
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.