示例#1
0
  /**
   * Update the permanent redirection list.
   *
   * @param the original request
   * @param the new location
   */
  private static void update_perm_redir_list(RoRequest req, URI new_loc) {
    HTTPConnection con = req.getConnection();
    URI cur_loc = null;
    try {
      cur_loc =
          new URI(
              new URI(con.getProtocol(), con.getHost(), con.getPort(), null), req.getRequestURI());
    } catch (ParseException pe) {
      if (LOG.isTraceEnabled()) {
        LOG.trace("An exception occurred: " + pe.getMessage());
      }
    }

    if (cur_loc != null && !cur_loc.equals(new_loc)) {
      Hashtable perm_redir_list = Util.getList(perm_redir_cntxt_list, con.getContext());
      perm_redir_list.put(cur_loc, new_loc);
    }
  }
示例#2
0
 /**
  * The Location header field must be an absolute URI, but too many broken servers use relative
  * URIs. So, we always resolve relative to the full request URI.
  *
  * @param loc the Location header field
  * @param req the Request to resolve relative URI's relative to
  * @return an absolute URI corresponding to the Location header field
  * @exception ProtocolException if the Location header field is completely unparseable
  */
 private URI resLocHdr(String loc, RoRequest req) throws ProtocolException {
   try {
     URI base =
         new URI(
             req.getConnection().getProtocol(),
             req.getConnection().getHost(),
             req.getConnection().getPort(),
             null);
     base = new URI(base, req.getRequestURI());
     URI res = new URI(base, loc);
     if (res.getHost() == null)
       throw new ProtocolException(
           "Malformed URL in Location header: `" + loc + "' - missing host field");
     return res;
   } catch (ParseException pe) {
     throw new ProtocolException(
         "Malformed URL in Location header: `" + loc + "' - exception was: " + pe.getMessage());
   }
 }