类org.apache.commons.httpclient.util.URIUtil源码实例Demo

下面列出了怎么用org.apache.commons.httpclient.util.URIUtil的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hadoop   文件: MockStorageInterface.java
@Override
public CloudBlobContainerWrapper getContainerReference(String name)
    throws URISyntaxException, StorageException {
  String fullUri;
  try {
    fullUri = baseUriString + "/" + URIUtil.encodePath(name);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  MockCloudBlobContainerWrapper container = new MockCloudBlobContainerWrapper(
      fullUri, name);
  // Check if we have a pre-existing container with that name, and prime
  // the wrapper with that knowledge if it's found.
  for (PreExistingContainer existing : preExistingContainers) {
    if (fullUri.equalsIgnoreCase(existing.containerUri)) {
      // We have a pre-existing container. Mark the wrapper as created and
      // make sure we use the metadata for it.
      container.created = true;
      backingStore.setContainerMetadata(existing.containerMetadata);
      break;
    }
  }
  return container;
}
 
源代码2 项目: hadoop   文件: MockStorageInterface.java
private String fullUriString(String relativePath, boolean withTrailingSlash) {
  String fullUri;

  String baseUri = this.baseUri;
  if (!baseUri.endsWith("/")) {
    baseUri += "/";
  }
  if (withTrailingSlash && !relativePath.equals("")
      && !relativePath.endsWith("/")) {
    relativePath += "/";
  }

  try {
    fullUri = baseUri + URIUtil.encodePath(relativePath);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  return fullUri;
}
 
源代码3 项目: big-c   文件: MockStorageInterface.java
@Override
public CloudBlobContainerWrapper getContainerReference(String name)
    throws URISyntaxException, StorageException {
  String fullUri;
  try {
    fullUri = baseUriString + "/" + URIUtil.encodePath(name);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  MockCloudBlobContainerWrapper container = new MockCloudBlobContainerWrapper(
      fullUri, name);
  // Check if we have a pre-existing container with that name, and prime
  // the wrapper with that knowledge if it's found.
  for (PreExistingContainer existing : preExistingContainers) {
    if (fullUri.equalsIgnoreCase(existing.containerUri)) {
      // We have a pre-existing container. Mark the wrapper as created and
      // make sure we use the metadata for it.
      container.created = true;
      backingStore.setContainerMetadata(existing.containerMetadata);
      break;
    }
  }
  return container;
}
 
源代码4 项目: big-c   文件: MockStorageInterface.java
private String fullUriString(String relativePath, boolean withTrailingSlash) {
  String fullUri;

  String baseUri = this.baseUri;
  if (!baseUri.endsWith("/")) {
    baseUri += "/";
  }
  if (withTrailingSlash && !relativePath.equals("")
      && !relativePath.endsWith("/")) {
    relativePath += "/";
  }

  try {
    fullUri = baseUri + URIUtil.encodePath(relativePath);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  return fullUri;
}
 
源代码5 项目: incubator-gobblin   文件: HttpUtils.java
/**
 * Convert D2 URL template into a string used for throttling limiter
 *
 * Valid:
 *    d2://host/${resource-id}
 *
 * Invalid:
 *    d2://host${resource-id}, because we cannot differentiate the host
 */
public static String createR2ClientLimiterKey(Config config) {

  String urlTemplate = config.getString(HttpConstants.URL_TEMPLATE);
  try {
    String escaped = URIUtil.encodeQuery(urlTemplate);
    URI uri = new URI(escaped);
    if (uri.getHost() == null)
      throw new RuntimeException("Cannot get host part from uri" + urlTemplate);

    String key = uri.getScheme() + "/" + uri.getHost();
    if (uri.getPort() > 0) {
      key = key + "/" + uri.getPort();
    }
    log.info("Get limiter key [" + key + "]");
    return key;
  } catch (Exception e) {
    throw new RuntimeException("Cannot create R2 limiter key", e);
  }
}
 
源代码6 项目: commons-vfs   文件: URLFileName.java
/**
 * Gets the path encoded suitable for url like file system e.g. (http, webdav).
 *
 * @param charset the charset used for the path encoding
 * @return The encoded path.
 * @throws URIException If an error occurs encoding the URI.
 * @throws FileSystemException If some other error occurs.
 */
public String getPathQueryEncoded(final String charset) throws URIException, FileSystemException {
    if (getQueryString() == null) {
        if (charset != null) {
            return URIUtil.encodePath(getPathDecoded(), charset);
        }
        return URIUtil.encodePath(getPathDecoded());
    }

    final StringBuilder sb = new StringBuilder(BUFFER_SIZE);
    if (charset != null) {
        sb.append(URIUtil.encodePath(getPathDecoded(), charset));
    } else {
        sb.append(URIUtil.encodePath(getPathDecoded()));
    }
    sb.append("?");
    sb.append(getQueryString());
    return sb.toString();
}
 
源代码7 项目: openhab1-addons   文件: AccessTokenRequest.java
private String buildQueryString() {
    final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);

    try {
        urlBuilder.append("?code=");
        urlBuilder.append(this.pinCode);
        urlBuilder.append("&client_id=");
        urlBuilder.append(this.clientId);
        urlBuilder.append("&client_secret=");
        urlBuilder.append(this.clientSecret);
        urlBuilder.append("&grant_type=authorization_code");
        return URIUtil.encodeQuery(urlBuilder.toString());
    } catch (final Exception e) {
        throw new NestException(e);
    }
}
 
源代码8 项目: Knowage-Server   文件: RestUtilities.java
@SuppressWarnings("unchecked")
public static List<NameValuePair> getAddressPairs(String address) {
	try {
		String query = URIUtil.getQuery(address);
		List<NameValuePair> params = new ParameterParser().parse(query, '&');
		List<NameValuePair> res = new ArrayList<NameValuePair>();
		for (NameValuePair nvp : params) {
			res.add(new NameValuePair(URIUtil.decode(nvp.getName(), DEFAULT_CHARSET), URIUtil.decode(nvp.getValue(), DEFAULT_CHARSET)));
		}
		return res;
	} catch (URIException e) {
		throw new SpagoBIRuntimeException(e);
	}
}
 
源代码9 项目: hadoop   文件: MockStorageInterface.java
/**
 * Utility function used to convert a given URI to a decoded string
 * representation sent to the backing store. URIs coming as input
 * to this class will be encoded by the URI class, and we want
 * the underlying storage to store keys in their original UTF-8 form.
 */
private static String convertUriToDecodedString(URI uri) {
  try {
    String result = URIUtil.decode(uri.toString());
    return result;
  } catch (URIException e) {
    throw new AssertionError("Failed to decode URI: " + uri.toString());
  }
}
 
源代码10 项目: hadoop   文件: ServletUtil.java
/**
 * Escape and encode a string regarded as within the query component of an URI.
 * @param value the value to encode
 * @return encoded query, null if the default charset is not supported
 */
public static String encodeQueryValue(final String value) {
  try {
    return URIUtil.encodeWithinQuery(value, "UTF-8");
  } catch (URIException e) {
    throw new AssertionError("JVM does not support UTF-8"); // should never happen!
  }
}
 
源代码11 项目: hadoop   文件: ServletUtil.java
/**
 * Escape and encode a string regarded as the path component of an URI.
 * @param path the path component to encode
 * @return encoded path, null if UTF-8 is not supported
 */
public static String encodePath(final String path) {
  try {
    return URIUtil.encodePath(path, "UTF-8");
  } catch (URIException e) {
    throw new AssertionError("JVM does not support UTF-8"); // should never happen!
  }
}
 
源代码12 项目: hadoop   文件: ServletUtil.java
/**
 * Parse and decode the path component from the given request.
 * @param request Http request to parse
 * @param servletName the name of servlet that precedes the path
 * @return decoded path component, null if UTF-8 is not supported
 */
public static String getDecodedPath(final HttpServletRequest request, String servletName) {
  try {
    return URIUtil.decode(getRawPath(request, servletName), "UTF-8");
  } catch (URIException e) {
    throw new AssertionError("JVM does not support UTF-8"); // should never happen!
  }
}
 
源代码13 项目: big-c   文件: MockStorageInterface.java
/**
 * Utility function used to convert a given URI to a decoded string
 * representation sent to the backing store. URIs coming as input
 * to this class will be encoded by the URI class, and we want
 * the underlying storage to store keys in their original UTF-8 form.
 */
private static String convertUriToDecodedString(URI uri) {
  try {
    String result = URIUtil.decode(uri.toString());
    return result;
  } catch (URIException e) {
    throw new AssertionError("Failed to decode URI: " + uri.toString());
  }
}
 
源代码14 项目: big-c   文件: ServletUtil.java
/**
 * Escape and encode a string regarded as within the query component of an URI.
 * @param value the value to encode
 * @return encoded query, null if the default charset is not supported
 */
public static String encodeQueryValue(final String value) {
  try {
    return URIUtil.encodeWithinQuery(value, "UTF-8");
  } catch (URIException e) {
    throw new AssertionError("JVM does not support UTF-8"); // should never happen!
  }
}
 
源代码15 项目: big-c   文件: ServletUtil.java
/**
 * Escape and encode a string regarded as the path component of an URI.
 * @param path the path component to encode
 * @return encoded path, null if UTF-8 is not supported
 */
public static String encodePath(final String path) {
  try {
    return URIUtil.encodePath(path, "UTF-8");
  } catch (URIException e) {
    throw new AssertionError("JVM does not support UTF-8"); // should never happen!
  }
}
 
源代码16 项目: big-c   文件: ServletUtil.java
/**
 * Parse and decode the path component from the given request.
 * @param request Http request to parse
 * @param servletName the name of servlet that precedes the path
 * @return decoded path component, null if UTF-8 is not supported
 */
public static String getDecodedPath(final HttpServletRequest request, String servletName) {
  try {
    return URIUtil.decode(getRawPath(request, servletName), "UTF-8");
  } catch (URIException e) {
    throw new AssertionError("JVM does not support UTF-8"); // should never happen!
  }
}
 
源代码17 项目: brooklin   文件: KafkaDestination.java
/**
 * Construct a KafkaDestination by parsing URI to extract the relevant fields
 * @param uri Kafka destination URI
 * @return KafkaDestination created by parsing the URI string
 */
public static KafkaDestination parse(String uri) {
  Validate.isTrue(uri.startsWith(SCHEME_KAFKA) || uri.startsWith(SCHEME_SECURE_KAFKA),
      "Invalid scheme in URI: " + uri);

  try {
    // Decode URI in case it's escaped
    uri = URIUtil.decode(uri);
  } catch (Exception e) {
    throw new DatastreamRuntimeException("Failed to decode Kafka destination URI: " + uri, e);
  }

  URI u = URI.create(uri);
  String scheme = u.getScheme();
  String zkAddress = u.getAuthority();
  String path = u.getPath();
  String topicName;
  int lastSlash = path.lastIndexOf("/");
  if (lastSlash > 0) {
    // intermediate paths are part of ZK address
    zkAddress += path.substring(0, lastSlash);
    topicName = path.substring(lastSlash + 1);
  } else {
    topicName = path.substring(1);
  }
  for (String hostInfo : zkAddress.split(",")) {
    long portNum = URI.create(SCHEME_KAFKA + "://" + hostInfo).getPort();
    Validate.isTrue(portNum != -1, "Missing port number in URI: " + uri);
  }

  Validate.notBlank(zkAddress, "Missing zkAddress in URI: " + uri);
  Validate.notBlank(topicName, "Missing topic name in URI: " + uri);
  boolean isSecure = scheme.equals(SCHEME_SECURE_KAFKA);
  return new KafkaDestination(zkAddress, topicName, isSecure);
}
 
源代码18 项目: brooklin   文件: TestKafkaDestination.java
@Test
public void testEscapedUri() throws Exception {
  String uri = "kafka://localhost%3A12913%2Fkafka-datastream/testtopic_test";
  KafkaDestination destination = KafkaDestination.parse(uri);
  Assert.assertEquals(destination.getZkAddress(), "localhost:12913/kafka-datastream");
  Assert.assertEquals(destination.getTopicName(), "testtopic_test");

  uri = URIUtil.encodeWithinAuthority("kafka://localhost:12913/kafka-datastream/testtopic_test");
  destination = KafkaDestination.parse(uri);
  Assert.assertEquals(destination.getZkAddress(), "localhost:12913/kafka-datastream");
  Assert.assertEquals(destination.getTopicName(), "testtopic_test");
}
 
源代码19 项目: knopflerfish.org   文件: HttpsURL.java
/**
 * Construct a HTTPS URL from given components.
 *
 * Note: The <code>userinfo</code> format is normally
 * <code>&lt;username&gt;:&lt;password&gt;</code> where
 * username and password must both be URL escaped.
 *  
 * @param userinfo the userinfo string whose parts are URL escaped
 * @param host the host string
 * @param port the port number
 * @param path the path string
 * @param query the query string
 * @param fragment the fragment string
 * @throws URIException If {@link #checkValid()} fails
 * @see #getDefaultProtocolCharset
 */
public HttpsURL(String userinfo, String host, int port, String path,
        String query, String fragment) throws URIException {

    // validate and contruct the URI character sequence
    StringBuffer buff = new StringBuffer();
    if (userinfo != null || host != null || port != -1) {
        _scheme = DEFAULT_SCHEME; // in order to verify the own protocol
        buff.append(_default_scheme);
        buff.append("://");
        if (userinfo != null) {
            buff.append(userinfo);
            buff.append('@');
        }
        if (host != null) {
            buff.append(URIUtil.encode(host, URI.allowed_host));
            if (port != -1 || port != DEFAULT_PORT) {
                buff.append(':');
                buff.append(port);
            }
        }
    }
    if (path != null) {  // accept empty path
        if (scheme != null && !path.startsWith("/")) {
            throw new URIException(URIException.PARSING,
                    "abs_path requested");
        }
        buff.append(URIUtil.encode(path, URI.allowed_abs_path));
    }
    if (query != null) {
        buff.append('?');
        buff.append(URIUtil.encode(query, URI.allowed_query));
    }
    if (fragment != null) {
        buff.append('#');
        buff.append(URIUtil.encode(fragment, URI.allowed_fragment));
    }
    parseUriReference(buff.toString(), true);
    checkValid();
}
 
源代码20 项目: knopflerfish.org   文件: HttpURL.java
/**
 * Construct a HTTP URL from given components.
 *
 * Note: The <code>userinfo</code> format is normally
 * <code>&lt;username&gt;:&lt;password&gt;</code> where
 * username and password must both be URL escaped.
 *  
 * @param userinfo the userinfo string whose parts are URL escaped
 * @param host the host string
 * @param port the port number
 * @param path the path string
 * @param query the query string
 * @param fragment the fragment string
 * @throws URIException If {@link #checkValid()} fails
 * @see #getDefaultProtocolCharset
 */
public HttpURL(String userinfo, String host, int port, String path,
        String query, String fragment) throws URIException {

    // validate and contruct the URI character sequence
    StringBuffer buff = new StringBuffer();
    if (userinfo != null || host != null || port != -1) {
        _scheme = DEFAULT_SCHEME; // in order to verify the own protocol
        buff.append(_default_scheme);
        buff.append("://");
        if (userinfo != null) {
            buff.append(userinfo);
            buff.append('@');
        }
        if (host != null) {
            buff.append(URIUtil.encode(host, URI.allowed_host));
            if (port != -1 || port != DEFAULT_PORT) {
                buff.append(':');
                buff.append(port);
            }
        }
    }
    if (path != null) {  // accept empty path
        if (scheme != null && !path.startsWith("/")) {
            throw new URIException(URIException.PARSING,
                    "abs_path requested");
        }
        buff.append(URIUtil.encode(path, URI.allowed_abs_path));
    }
    if (query != null) {
        buff.append('?');
        buff.append(URIUtil.encode(query, URI.allowed_query));
    }
    if (fragment != null) {
        buff.append('#');
        buff.append(URIUtil.encode(fragment, URI.allowed_fragment));
    }
    parseUriReference(buff.toString(), true);
    checkValid();
}
 
源代码21 项目: knopflerfish.org   文件: HttpURL.java
protected static String toUserinfo(String user, String password) throws URIException {
    if (user == null) return null;
    StringBuffer usrinfo = new StringBuffer(20); //sufficient for real world
    usrinfo.append(URIUtil.encode(user, URI.allowed_within_userinfo));
    if (password == null) return usrinfo.toString();
    usrinfo.append(':');
    usrinfo.append(URIUtil.encode(password, URI.allowed_within_userinfo));
    return usrinfo.toString();
}
 
源代码22 项目: Asqatasun   文件: HttpRequestHandler.java
private String getEncodedUrl(String url) {
    try {
        return URIUtil.encodeQuery(URIUtil.decode(url));
    } catch (URIException ue) {
        LOGGER.warn("URIException on " + url);
        return url;
    }
}
 
源代码23 项目: website   文件: TrackingUrlCreatorBitlyImpl.java
@Override
public String execute(Licence licence) {
	String trackingUrl = licence.getProduct().getUrl();
	if (StringUtils.isBlank(trackingUrl)) {
		trackingUrl = defaultUrl();
	}
	if (StringUtils.contains(trackingUrl, "?")) {
		trackingUrl = trackingUrl + "&";
	} else {
		trackingUrl = trackingUrl + "?";
	}
	trackingUrl = trackingUrl + additionalUrlMetadata(licence);
	try {
		trackingUrl = URIUtil.encodeQuery(trackingUrl);
	} catch (URIException e1) {
	}
	String callToAction = licence.getProduct().getUrlCallToAction();
	if (StringUtils.isBlank(callToAction)) {
		callToAction = defaultCallToAction();
	}
	try {
		Url url = as(username, apiKey).call(shorten(trackingUrl));
		return callToAction + url.getShortUrl();
	} catch (Exception e) {
		logger.error("Unable to bit.ly tracking url for licence " + licence.getId() , e);
		return defaultTrackingUrl();
	}
}
 
源代码24 项目: website   文件: TrackingUrlCreatorBitlyImpl.java
@Override
public String execute(Product product) {
	String trackingUrl = product.getUrl();
	if (StringUtils.isBlank(trackingUrl)) {
		trackingUrl = defaultUrl();
	}
	if (StringUtils.contains(trackingUrl, "?")) {
		trackingUrl = trackingUrl + "&";
	} else {
		trackingUrl = trackingUrl + "?";
	}
	trackingUrl = trackingUrl + additionalUrlMetadata(product);
	try {
		trackingUrl = URIUtil.encodeQuery(trackingUrl);
	} catch (URIException e1) {
	}
	String callToAction = product.getUrlCallToAction();
	if (StringUtils.isBlank(callToAction)) {
		callToAction = defaultCallToAction();
	}
	try {
		Url url = as(username, apiKey).call(shorten(trackingUrl));
		return callToAction + url.getShortUrl();
	} catch (Exception e) {
		logger.error("Unable to bit.ly tracking url for product " + product.getId() , e);
		return defaultTrackingUrl();
	}
}
 
源代码25 项目: elasticsearch-hadoop   文件: HttpEncodingTools.java
/**
 * Splits the given string on the first '?' then encodes the first half as a path (ignoring slashes and colons)
 * and the second half as a query segment (ignoring questionmarks, equals signs, etc...).
 *
 * @deprecated Prefer to use {@link HttpEncodingTools#encode(String)} instead for encoding specific
 * pieces of the URI. This method does not escape certain reserved characters, like '/', ':', '=', and '?'.
 * As such, this is not safe to use on URIs that may contain these reserved characters in the wrong places.
 */
@Deprecated
public static String encodeUri(String uri) {
    try {
        return URIUtil.encodePathQuery(uri);
    } catch (URIException ex) {
        throw new EsHadoopIllegalArgumentException("Cannot escape uri [" + uri + "]", ex);
    }
}
 
源代码26 项目: elasticsearch-hadoop   文件: HttpEncodingTools.java
/**
 * Encodes characters in the string except for those allowed in an absolute path.
 *
 * @deprecated Prefer to use {@link HttpEncodingTools#encode(String)} instead for encoding specific
 * pieces of the URI. This method does not escape certain reserved characters, like '/' and ':'.
 * As such, this is not safe to use on paths that may contain these reserved characters in the wrong places.
 */
@Deprecated
public static String encodePath(String path) {
    try {
        return URIUtil.encodePath(path, "UTF-8");
    } catch (URIException ex) {
        throw new EsHadoopIllegalArgumentException("Cannot encode path segment [" + path + "]", ex);
    }
}
 
源代码27 项目: at.info-knowledge-base   文件: HarStorage.java
public String getHarDetailsURL(final String harName) {
    try {
        return URIUtil.encodeQuery(targetURL + "/details?label=" + harName);
    } catch (URIException e) {
        return null;
    }
}
 
源代码28 项目: openhab1-addons   文件: DataModelRequest.java
private String buildQueryString() {
    final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);

    try {
        urlBuilder.append("?auth=");
        urlBuilder.append(this.accessToken);
        return URIUtil.encodeQuery(urlBuilder.toString());
    } catch (final Exception e) {
        throw new NestException(e);
    }
}
 
源代码29 项目: openhab1-addons   文件: UpdateDataModelRequest.java
private String buildQueryString() {
    final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);

    try {
        urlBuilder.append("?auth=");
        urlBuilder.append(this.accessToken);
        return URIUtil.encodeQuery(urlBuilder.toString());
    } catch (final Exception e) {
        throw new NestException(e);
    }
}
 
源代码30 项目: openhab1-addons   文件: TokenRequest.java
private String buildQueryString() {
    final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);

    try {
        urlBuilder.append("?grant_type=ecobeePin");
        urlBuilder.append("&code=");
        urlBuilder.append(authToken);
        urlBuilder.append("&client_id=");
        urlBuilder.append(appKey);
        return URIUtil.encodeQuery(urlBuilder.toString());
    } catch (final Exception e) {
        throw new EcobeeException(e);
    }
}
 
 类方法
 同包方法