Java Code Examples for org.apache.commons.httpclient.util.URIUtil#encodeQuery()

The following examples show how to use org.apache.commons.httpclient.util.URIUtil#encodeQuery() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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);
    }
}