Package org.w3c.jigsaw.http

Examples of org.w3c.jigsaw.http.Request


     */
    public boolean lookupOther(LookupState ls, LookupResult lr)
  throws org.w3c.tools.resources.ProtocolException
    {
  // Get the full URL from the request:
  Request request = (Request) ls.getRequest();
  URL     requrl  = ((request != null)
         ? request.getURL()
         : null);
  boolean host_equiv = false;

  // loop check
  if (request != null) {
      String vias[] = request.getVia();
      if ((url != null)
    && (requrl.getPort() == url.getPort())
    && (vias != null && vias.length > 5)) { 
    // maybe a loop, let's try to sort it out with an expensive
    // checking on IPs
    String hostaddr;
   
    ObservableProperties props = getServer().getProperties();
    hostaddr = props.getString(SocketClientFactory.BINDADDR_P,
             default_hostaddr);
    if (requrl != null) {
        InetAddress targhost;
        String reqhostaddr;
       
        try {
      targhost = InetAddress.getByName(requrl.getHost());
      reqhostaddr = targhost.getHostAddress();
      host_equiv =  reqhostaddr.equals(hostaddr);
        } catch (UnknownHostException uhex) {};
    }
      }
  }
  if (((url != null)
       && (requrl != null)
       && ((requrl.getPort() == url.getPort()) ||
     (requrl.getPort() * url.getPort() == -80))
       && ( host_equiv ||
      (requrl.getHost().equalsIgnoreCase(url.getHost()))))
       || (ls.isInternal())) {
      // Call super.lookup:
      super.lookupOther(ls, lr);
      if ( ls.hasMoreComponents() ) {
    ResourceReference root = getLocalRootResource();
    if ( root == null ) {
        lr.setTarget(this.getResource().getResourceReference());
        return true;
    }
    try {
        // because the root eats the lookup state components
        // we have to return true.
        // Should not be continued by the caller.
        FramedResource res = (FramedResource)root.lock();
        boolean done = res.lookup(ls, lr);
        if (! done)
      lr.setTarget(null);
        return true;
    } catch (InvalidResourceException ex) {
        // should never happen with the root resource
        ex.printStackTrace();
    } finally {
        root.unlock();
    }
    return true; // should never be reached
      } else {
    request.setState(STATE_CONTENT_LOCATION, "true");
    // return the index file.
    String index = getIndex();
    if ( index != null && index.length() > 0) {
        ResourceReference root = getLocalRootResource();
        try {
      DirectoryResource dir =
          (DirectoryResource)root.lock();
      ResourceReference rr = dir.lookup(index);
      if (rr != null) {
          try {
        FramedResource rindex =
            (FramedResource) rr.lock();
        return rindex.lookup(ls,lr);
          } catch (InvalidResourceException ex) {
          } finally {
        rr.unlock();
          }
      }
        } catch (InvalidResourceException ex) {
      root.unlock();
        }
    }
    lr.setTarget(drr);
    return true;
      }
  } else {
      // Always invoke super lookup, after notification that its a proxy
      request.setProxy(true);
      super.lookupOther(ls, lr);
      if ( requrl.getProtocol().equals("ftp") ) {
//    if (ftphandler != null)
//        lr.setTarget(ftphandler);
//    else
View Full Code Here


    {
  // Internal lookup:
  if ( ls.isInternal() )
      return super.lookup(ls, lr);

  Request request = (Request) ls.getRequest();
  URL     requrl  = request.getURL() ;

  if ((url != null)
      && ((requrl.getPort() == url.getPort()) ||
    (requrl.getPort() * url.getPort() == -80))
      && (requrl.getHost().equalsIgnoreCase(url.getHost()))) {
      return super.lookup(ls, lr);
  } else {
      String vias[] = request.getVia();
      if ((url != null)
    && (requrl.getPort() == url.getPort())
    && (vias != null && vias.length > 5)) {
    // maybe a loop, let's try to sort it out with an expensive
    // checking on IPs
    String hostaddr = null;
    ObservableProperties props = getServer().getProperties();
    hostaddr = props.getString(SocketClientFactory.BINDADDR_P,
             default_hostaddr);
    if (requrl != null) {
        InetAddress targhost;
        String reqhostaddr;
       
        try {
      targhost = InetAddress.getByName(requrl.getHost());
      reqhostaddr = targhost.getHostAddress();
      if (reqhostaddr.equals(hostaddr))
          return super.lookup(ls, lr);
        } catch (Exception ex) {
      // can't get it, let the proxy bark!
        }
    }
      }
      // not internal, so set it as a proxied call for lookup
      request.setProxy(true);
  }
  return super.lookup(ls, lr);
    }
View Full Code Here

    public ReplyInterface outgoingFilter(RequestInterface req,
           ReplyInterface rep)
  throws ProtocolException
    {
  Reply   reply   = (Reply) rep;
  Request request = (Request) req;
  if ( ! reply.hasState(DONT_LOG) )
      log(request, reply);
  return null;
    }
View Full Code Here

     * @param request The incomming request.
     * @return Always <strong>null</strong>.
     */

    public ReplyInterface ingoingFilter(RequestInterface req) {
  Request request = (Request) req;
  if ( getOnOffFlag() )
      request.dump(System.out);
  return null;
    }
View Full Code Here

      // let's add the username there
      String username = principal.getName();
      if (username != null) {
    try {
        HTTPPrincipal htp = (HTTPPrincipal)principal;
        Request request = htp.getRequest();
        if (username != null) {
      request.setState(AuthFilter.STATE_AUTHUSER, username);
        }
    } catch (Exception ex) {
        // was not an HTTPPrincipal
    }
      }
View Full Code Here

    public ReplyInterface outgoingFilter (RequestInterface req,
            ReplyInterface rep)
  throws HTTPException
    {
  Request request = (Request) req;
  Reply reply = (Reply) rep;

  HttpBag pics = isPICSQuery (request) ;
  if ( pics == null )
      return reply ;
  // Get the requested services:
  HttpBag params    = pics.getBag("params") ;
  HttpBag services  = params.getBag("services") ;
  URL url       = request.getURL();
  int format    = LabelBureauInterface.FMT_MINIMAL ;
  // Get any format parameter:
  if ( params.hasItem ("minimal") ) {
      format = LabelBureauInterface.FMT_MINIMAL ;
  } else if ( params.hasItem ("short") ) {
      format = LabelBureauInterface.FMT_SHORT ;
  } else if ( params.hasItem ("full") ) {
      format = LabelBureauInterface.FMT_FULL ;
  } else if ( params.hasItem ("signed") ) {
      format = LabelBureauInterface.FMT_SIGNED ;
  } else {
      Reply error = request.makeReply(HTTP.BAD_REQUEST) ;
      error.setContent ("Invalid label format: "+format) ;
      throw new HTTPException (error) ;
  }
  // Get labels for each service, building out the ret hashtable
  StringBuffer sb = new StringBuffer(128) ;
View Full Code Here

     */

    public ReplyInterface outgoingFilter(RequestInterface request,
           ReplyInterface reply)
    {
  Request req = (Request) request;
  Reply rep = (Reply) reply;
  if ( getPrivateCachability() ) {
      rep.setMustRevalidate(true);
  } else if ( getSharedCachability() ) {
      rep.setProxyRevalidate(true);
  } else if ( getPublicCachability() ) {
      rep.setPublic(true);
  }
  if (req.hasState(AuthFilter.STATE_AUTHCONTEXT)) {
      DigestAuthContext dac;
      dac =(DigestAuthContext)req.getState(AuthFilter.STATE_AUTHCONTEXT);
      if (dac.stale) {
    rep.addAuthenticationInfo("nextnonce", nonce);
      }
  }
  return null;
View Full Code Here

  throws ProtocolException
    {
  String methods[] = getMethods();
 
  if (ls.hasRequest() && (methods != null)) {
      Request request = (Request) ls.getRequest();
      String reqmeth = request.getMethod();
      boolean affected = false;
      for (int i=0; i< methods.length; i++) {
    if (reqmeth.equals(methods[i])) {
        affected = true;
        break;
    }
      }
      if (!affected) {
    return super.lookupResource(ls, lr);
      }
  }
  // Perform our super-class lookup strategy:
  if ( super.lookupOther(ls, lr) ) {
      return true;
        } else if ( ! checkHandlePathInfo() ) {
            return false;
        }
  // Compute PATH INFO, store it as a piece of state in
  // the request:
  StringBuffer pathinfo = new StringBuffer();
  while ( ls.hasMoreComponents() ) {
      pathinfo.append('/');
      pathinfo.append(ls.getNextComponent());
  }
  if (ls.hasRequest() ) {
      Request request = (Request) ls.getRequest();
      String reqfile = request.getURL().getFile();
      if (reqfile.endsWith("/")) {
    pathinfo.append('/');
      }
      request.setState(PATH_INFO, pathinfo.toString());
  }
  lr.setTarget(resource.getResourceReference());
  return true;
    }
View Full Code Here

     * otherwise, send a NOT_AVAILABLE and fills the right Retry-After header
     * @return a Reply if blocked, null otherwise
     */

    public synchronized ReplyInterface ingoingFilter(RequestInterface req) {
  Request request = (Request) req;
  Reply   reply   = null;
  int n_year, n_month, n_week, n_day, n_time;
  int a, b, n;
  Calendar cal = Calendar.getInstance();

  n_year  = cal.get(Calendar.YEAR);
  n_month = cal.get(Calendar.MONTH);
  n_week  = cal.get(Calendar.DAY_OF_WEEK);
  n_day   = cal.get(Calendar.DAY_OF_MONTH);
  n_time  = cal.get(Calendar.HOUR_OF_DAY) * 3600 +
      cal.get(Calendar.MINUTE) * 60 +
      cal.get(Calendar.SECOND);
 
  if (getDayRepeat()) { // check it if it is repeated every day
      if ((n_time < a_time) || (n_time > b_time)) {
    reply = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
    if (n_time < a_time)
        reply.setRetryAfter(a_time - n_time);
    else
        reply.setRetryAfter(84600 + n_time - a_time);
      }
  } else if (getWeekRepeat()) { // check it if it is repeated every week
      a = a_time + a_week * 86400;
      b = b_time + b_week * 86400;
      n = n_time + n_week * 86400;
      if ((n < a) || (n > b)) {
    reply = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
    if (n < a)
        reply.setRetryAfter(a - n);
    else
        reply.setRetryAfter(84600*7 + n - a);
      }
  } else if (getMonthRepeat()) { // check it if it's repeated every month
      a = a_time + a_day * 86400;
      b = b_time + b_day * 86400;
      n = n_time + n_day * 86400;
      if ((n < a) || (n > b)) {
    reply = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
    if (n < a)
        reply.setRetryAfter(a - n);
    else {
        cal.setTime(new Date(getLong(ATTR_DATE_START, -1)));
        cal.set(Calendar.YEAR, n_year);
        cal.set(Calendar.MONTH, n_month);
        cal.roll(Calendar.MONTH, true);
        reply.setRetryAfter(cal.getTime().getTime());
    }
      }
  } else if (getYearRepeat()) { // check it if it's repeated every year
      Calendar c_a = Calendar.getInstance();
      Calendar c_b = Calendar.getInstance();
      c_a.setTime(new Date(getLong(ATTR_DATE_START, -1)));
      c_b.setTime(new Date(getLong(ATTR_DATE_END, -1)));
      c_a.set(Calendar.YEAR, n_year);
      c_b.set(Calendar.YEAR, n_year);
      if (cal.before(c_a)) {
    reply = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
    reply.setRetryAfter(c_a.getTime().getTime());
      } else if (cal.after(c_b)) {
    c_a.roll(Calendar.YEAR, true);
    reply = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
    reply.setRetryAfter(c_a.getTime().getTime());
      }
  } else { /* no repeat */
      Calendar c_a = Calendar.getInstance();
      Calendar c_b = Calendar.getInstance();
      c_a.setTime(new Date(getLong(ATTR_DATE_START, -1)));
      c_b.setTime(new Date(getLong(ATTR_DATE_END, -1)));
      if (cal.before(c_a)) {
    reply = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
    reply.setRetryAfter(c_a.getTime().getTime());
      } else if (cal.after(c_b)) {
    reply = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
      }
  }
  if (reply != null) {
      HtmlGenerator g = new HtmlGenerator("Service Unavailable");
      g.append("You may retry after the delay or the date given");
View Full Code Here

  throws ProtocolException
    {
  String methods[] = getMethods();
 
  if (ls.hasRequest() && (methods != null)) {
      Request request = (Request) ls.getRequest();
      String reqmeth = request.getMethod();
      boolean affected = false;
      for (int i=0; i< methods.length; i++) {
    if (reqmeth.equals(methods[i])) {
        affected = true;
        break;
    }
      }
      if (!affected) {
    return super.lookupResource(ls, lr);
      }
  }
  // Perform our super-class lookup strategy:
  if ( super.lookupOther(ls, lr) ) {
      return true;
  }
  // Compute PATH INFO, store it as a piece of state in the request:
  StringBuffer pathinfo = new StringBuffer();
  while ( ls.hasMoreComponents() ) {
      pathinfo.append('/');
      pathinfo.append(ls.getNextComponent());
  }
  if (ls.hasRequest() ) {
      Request request = (Request) ls.getRequest();
      String reqfile = request.getURL().getFile();
      if (reqfile.endsWith("/")) {
    pathinfo.append('/');
      }
      request.setState(PATH_INFO, pathinfo.toString());
  }
  lr.setTarget(resource.getResourceReference());
  return true;
    }
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.