org.apache.commons.httpclient.util.URIUtil Java Examples

The following examples show how to use org.apache.commons.httpclient.util.URIUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockStorageInterface.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: MockStorageInterface.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: HttpUtils.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example #4
Source File: MockStorageInterface.java    From big-c with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: MockStorageInterface.java    From big-c with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: URLFileName.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #7
Source File: AccessTokenRequest.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #8
Source File: TokenRequest.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #9
Source File: TrackingUrlCreatorBitlyImpl.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@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();
	}
}
 
Example #10
Source File: TrackingUrlCreatorBitlyImpl.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@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();
	}
}
 
Example #11
Source File: HttpEncodingTools.java    From elasticsearch-hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #12
Source File: HttpEncodingTools.java    From elasticsearch-hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #13
Source File: HarStorage.java    From at.info-knowledge-base with MIT License 5 votes vote down vote up
public String getHarDetailsURL(final String harName) {
    try {
        return URIUtil.encodeQuery(targetURL + "/details?label=" + harName);
    } catch (URIException e) {
        return null;
    }
}
 
Example #14
Source File: DataModelRequest.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #15
Source File: UpdateDataModelRequest.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #16
Source File: MockStorageInterface.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
  }
}
 
Example #17
Source File: RefreshTokenRequest.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
private String buildQueryString() {
    final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);

    try {
        urlBuilder.append("?grant_type=refresh_token");
        urlBuilder.append("&code=");
        urlBuilder.append(refreshToken);
        urlBuilder.append("&client_id=");
        urlBuilder.append(appKey);
        return URIUtil.encodeQuery(urlBuilder.toString());
    } catch (final Exception e) {
        throw new EcobeeException(e);
    }
}
 
Example #18
Source File: ThermostatRequest.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
private String buildQueryString() {
    final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);

    try {
        urlBuilder.append("?json=");
        urlBuilder.append(JSON.writeValueAsString(this));
        return URIUtil.encodeQuery(urlBuilder.toString());
    } catch (final Exception e) {
        throw new EcobeeException(e);
    }
}
 
Example #19
Source File: UpdateThermostatRequest.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
private String buildQueryString() {
    final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);

    try {
        urlBuilder.append("?json=true&token=");
        urlBuilder.append(this.accessToken);
        return URIUtil.encodeQuery(urlBuilder.toString());
    } catch (final Exception e) {
        throw new EcobeeException(e);
    }
}
 
Example #20
Source File: ThermostatSummaryRequest.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
private String buildQueryString() {
    final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);

    try {
        urlBuilder.append("?json=");
        urlBuilder.append(JSON.writeValueAsString(this));
        return URIUtil.encodeQuery(urlBuilder.toString());
    } catch (final Exception e) {
        throw new EcobeeException(e);
    }
}
 
Example #21
Source File: AuthorizeRequest.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
private String buildQueryString() {
    final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);

    try {
        urlBuilder.append("?response_type=ecobeePin");
        urlBuilder.append("&client_id=");
        urlBuilder.append(appKey);
        urlBuilder.append("&scope=");
        urlBuilder.append(scope);
        return URIUtil.encodeQuery(urlBuilder.toString());
    } catch (final Exception e) {
        throw new EcobeeException(e);
    }
}
 
Example #22
Source File: HttpRequestHandler.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
private String getEncodedUrl(String url) {
    try {
        return URIUtil.encodeQuery(URIUtil.decode(url));
    } catch (URIException ue) {
        LOGGER.warn("URIException on " + url);
        return url;
    }
}
 
Example #23
Source File: RestUtilities.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
	}
}
 
Example #24
Source File: ServletUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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!
  }
}
 
Example #25
Source File: ServletUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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!
  }
}
 
Example #26
Source File: ServletUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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!
  }
}
 
Example #27
Source File: MockStorageInterface.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
  }
}
 
Example #28
Source File: ServletUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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!
  }
}
 
Example #29
Source File: ServletUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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!
  }
}
 
Example #30
Source File: ServletUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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!
  }
}