Package org.w3c.jigsaw.http

Examples of org.w3c.jigsaw.http.Request


     */
    public ReplyInterface outgoingFilter(RequestInterface req,
           ReplyInterface rep)
  throws ProtocolException
    {
  Request request = (Request) req;
  Reply   reply   = (Reply) rep;
  // Anything to compress ?
  if ( ! reply.hasStream() ) {
      return null;
  }
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;
  Reply       extReply = null;
  HttpExtList cman     = request.getHttpCManExtDecl();
  HttpExtList copt     = request.getHttpCOptExtDecl();
  HttpExtList man      = request.getHttpManExtDecl();

  if ((cman != null) || (copt != null)) {
      extReply = applyExtensions(request, cman, copt);
      if (extReply != null)
    return extReply;
      if ((cman != null) && (man == null)) {
    //strip the M-
    String method = request.getMethod();
    if (method.startsWith("M-"))
        request.setMethod(method.substring(2));
      }
  }
  //Send the request, and get the reply
  reply = (Reply) super.perform(ri);
View Full Code Here

  throws ProtocolException
    {
  // Give a chance to our super-class to run its own lookup scheme:
  // do we have to create a resource (PUT) ?
  if ((ls.hasMoreComponents()) && getPutableFlag()) {
      Request request = (Request) ls.getRequest() ;
      if ((request == null) || request.getMethod().equals("PUT")) {
    // We might well want to create a resource:
    String            name = ls.peekNextComponent() ;
    ResourceReference rr   = dresource.lookup(name);
    if ((rr == null) && (dresource.getExtensibleFlag())) {
        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() ) {
    Request request = (Request)ls.getRequest() ;
    request.setState(STATE_CONTENT_LOCATION, "true");
    // return the index file.
    String indexes[] = getIndexes();
    if (indexes != null) {
        for (int i = 0 ; i < indexes.length ; i++) {
      String index = indexes[i];
View Full Code Here

  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) ;
  } else if ( method.equals("HEAD") ) {
      reply = head(request) ;
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);
   
    if (showerr) {
        reply.setContent("An HTTP error occured while getting: "
             + "<p><strong>"+request.getURL()
             + "</strong>"
             + "<p>Details \""+shex.getMessage()+"\"."
             + "<hr>Generated by <i>"
             + getServer().getURL());
    } else {
        reply.setContent("An HTTP error occured while getting the "
             + "requested URI.</p>"
             + "<hr>Generated by <i>"
             + getServer().getURL());
    }
    reply.setContentType(org.w3c.www.mime.MimeType.TEXT_HTML);
      }
  } catch (HttpInvalidValueException iex) {
      // An server-side HTTP-related error happened
      if (debug) {
    System.out.println("Parsing Exception while running"
           +" request:");
    iex.printStackTrace();
      }
      // Make sure the request is accounted:
      if ( ! stated ) {
    synchronized(this) {
        reqcount++;
        reqerred++;
    }
    stated = true;
      }
      reply = request.makeReply(HTTP.BAD_GATEWAY);
      boolean showerr =
    props.getBoolean(httpd.DISPLAY_URL_ON_ERROR_P, false);
     
      if (showerr) {
    reply.setContent("An HTTP error occured while getting: "
         + "<p><strong>"+request.getURL()
         + "</strong>"
         + "<p>Details \""+iex.getMessage()+"\"."
         + "<hr>Generated by <i>"
         + getServer().getURL());
      } else {
    reply.setContent("An HTTP error occured while getting the "
         + "requested URI.</p>"
         + "<hr>Generated by <i>"
         + getServer().getURL());
      }
      reply.setContentType(org.w3c.www.mime.MimeType.TEXT_HTML);
  } catch (HttpException hex) {
      // An HTTP-related error happened
      if (debug) {
    System.out.println("HTTP Exception while running request:");
    hex.printStackTrace();
      }
      // Make sure the request is accounted:
      if ( ! stated ) {
    synchronized(this) {
        reqcount++;
        reqerred++;
    }
    stated = true;
      }
      org.w3c.www.protocol.http.Reply rep = hex.getReply();
      if (rep != null) {
    try {
        reply = dupReply(request, rep);
    } catch (IOException ioex) {
        reply = null;
    }
      }
      if (reply == null) {
    // Send an appropriate error message back:
    String msg = hex.getMessage();
    if (msg.startsWith("Unable to contact target server ")) {
        reply = request.makeReply(HTTP.GATEWAY_TIMEOUT);
    } else {
        reply = request.makeReply(HTTP.BAD_GATEWAY);
    }
    boolean showerr =
        props.getBoolean(httpd.DISPLAY_URL_ON_ERROR_P, false);
   
    if (showerr) {
        reply.setContent("An HTTP error occured while getting: "
             + "<p><strong>"+request.getURL()
             + "</strong>"
             + "<p>Details \""+hex.getMessage()+"\"."
             + "<hr>Generated by <i>"
             + getServer().getURL());
    } else {
        reply.setContent("An HTTP error occured while getting the "
             + "requested URI.</p>"
             + "<hr>Generated by <i>"
             + getServer().getURL());
    }
    reply.setContentType(org.w3c.www.mime.MimeType.TEXT_HTML);
      }
  } catch (Exception ex) {
      // Debug trace (when debuggging):
      if ( debug ) {
    System.out.println("Exception while running request:");
    ex.printStackTrace();
      }
      // Make sure the request is accounted:
      if ( ! stated ) {
    synchronized(this) {
        reqcount++;
        reqerred++;
    }
    stated = true;
      }
      // Send an appropriate error message back:
      reply = request.makeReply(HTTP.GATEWAY_TIMEOUT);
      boolean showerr = props.getBoolean(httpd.DISPLAY_URL_ON_ERROR_P,
                 false);
     
      if (showerr) {
    reply.setContent("An HTTP error occured while getting: "
         + "<p><strong>"+request.getURL()+"</strong>"
         + "<p>Details \""+ex.getMessage()+"\"."
         + "<hr>Generated by <i>"
         + getServer().getURL());
      } else {
    reply.setContent("An HTTP error occured while getting the "
View Full Code Here

     * @exception ResourceException if a server error occurs
     */
    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 {
View Full Code Here

     
      handleSimpleIMS(request,reply) ;
      return reply ;
  }
 
  Request subReq = null ;
  Reply subRep = null ;
 
  try {
      // Prepare an internal request
      subReq =
View Full Code Here

    private Request prepareRequest(Request request,
           String url,
           Dictionary variables,
           Integer depth)
    {
  Request subReq = (Request) request.getClone() ;

  subReq.setURLPath(url) ;
  long ims = request.getIfModifiedSince() ;
  if(ims != -1) {
      subReq.setHeaderValue(Request.H_IF_MODIFIED_SINCE,null) ;
      subReq.setState(STATE_IF_MODIFIED_SINCE,
          new Long(ims)) ;
  }

  subReq.setState(SSIFrame.STATE_VARIABLES,
      variables) ;

  subReq.setState(SSIFrame.STATE_DEPTH,
      new Integer(depth.intValue()+1)) ;
 
 
  return subReq ;
    }
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());
View Full Code Here

     * because an abnormal situation occured.
     */
    public ReplyInterface ingoingFilter(RequestInterface request)
  throws ProtocolException
    {
  Request req = (Request) request;
  if (req.hasPragma("no-cache")) {
      String pragmas[] = req.getPragma();
      if (pragmas.length == 1) {
    req.setPragma(null);
      } else {
    // remove the no-cache
    String newpragmas[] = new String[pragmas.length - 1];
    for (int i=0, j=0; i<pragmas.length; i++) {
        if (pragmas[i].equals("no-cache"))
      continue;
        newpragmas[j++] = pragmas[i];
    }
    req.setPragma(newpragmas);
      }
      req.setMaxAge(0);
  }
  return null;
    }
View Full Code Here

TOP

Related Classes of org.w3c.jigsaw.http.Request

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.