use of org.apache.http.client.utils.URIBuilder in project cloudstack by apache.
the class UriUtils method getUpdateUri.
public static String getUpdateUri(String url, boolean encrypt) {
String updatedPath = null;
try {
String query = URIUtil.getQuery(url);
URIBuilder builder = new URIBuilder(url);
builder.removeQuery();
StringBuilder updatedQuery = new StringBuilder();
List<NameValuePair> queryParams = getUserDetails(query);
ListIterator<NameValuePair> iterator = queryParams.listIterator();
while (iterator.hasNext()) {
NameValuePair param = iterator.next();
String value = null;
if ("password".equalsIgnoreCase(param.getName()) && param.getValue() != null) {
value = encrypt ? DBEncryptionUtil.encrypt(param.getValue()) : DBEncryptionUtil.decrypt(param.getValue());
} else {
value = param.getValue();
}
if (updatedQuery.length() == 0) {
updatedQuery.append(param.getName()).append('=').append(value);
} else {
updatedQuery.append('&').append(param.getName()).append('=').append(value);
}
}
String schemeAndHost = "";
URI newUri = builder.build();
if (newUri.getScheme() != null) {
schemeAndHost = newUri.getScheme() + "://" + newUri.getHost();
}
updatedPath = schemeAndHost + newUri.getPath() + "?" + updatedQuery;
} catch (URISyntaxException e) {
throw new CloudRuntimeException("Couldn't generate an updated uri. " + e.getMessage());
}
return updatedPath;
}
use of org.apache.http.client.utils.URIBuilder in project oxAuth by GluuFederation.
the class ToopherAPI method post.
private JSONObject post(String endpoint, List<NameValuePair> params) throws Exception {
URI uri = new URIBuilder().setScheme(URI_SCHEME).setHost(URI_HOST).setPath(URI_BASE + endpoint).build();
HttpPost post = new HttpPost(uri);
if (params != null && params.size() > 0) {
post.setEntity(new UrlEncodedFormEntity(params));
}
consumer.sign(post);
return httpClient.execute(post, jsonHandler);
}
use of org.apache.http.client.utils.URIBuilder in project jabref by JabRef.
the class ErrorConsoleViewModel method reportIssue.
/**
* Opens a new issue on GitHub and copies log to clipboard.
*/
public void reportIssue() {
try {
String issueTitle = "Automatic Bug Report - " + dateFormat.format(date);
// system info
String systemInfo = String.format("JabRef %s%n%s %s %s %nJava %s", buildInfo.getVersion(), BuildInfo.OS, BuildInfo.OS_VERSION, BuildInfo.OS_ARCH, BuildInfo.JAVA_VERSION);
// steps to reproduce
String howToReproduce = "Steps to reproduce:\n\n1. ...\n2. ...\n3. ...";
// log messages
String issueDetails = "<details>\n" + "<summary>" + "Detail information:" + "</summary>\n\n```\n" + getLogMessagesAsString(allMessagesData) + "\n```\n\n</details>";
clipBoardManager.setClipboardContents(issueDetails);
// bug report body
String issueBody = systemInfo + "\n\n" + howToReproduce + "\n\n" + "Paste your log details here.";
dialogService.notify(Localization.lang("Issue on GitHub successfully reported."));
dialogService.showInformationDialogAndWait(Localization.lang("Issue report successful"), Localization.lang("Your issue was reported in your browser.") + "\n" + Localization.lang("The log and exception information was copied to your clipboard.") + " " + Localization.lang("Please paste this information (with Ctrl+V) in the issue description.") + "\n" + Localization.lang("Please also add all steps to reproduce this issue, if possible."));
URIBuilder uriBuilder = new URIBuilder().setScheme("https").setHost("github.com").setPath("/JabRef/jabref/issues/new").setParameter("title", issueTitle).setParameter("body", issueBody);
JabRefDesktop.openBrowser(uriBuilder.build().toString());
} catch (IOException | URISyntaxException e) {
LOGGER.error(e);
}
}
use of org.apache.http.client.utils.URIBuilder in project pact-jvm by DiUS.
the class PactBrokerLoader method loadPactsForProvider.
private List<Pact> loadPactsForProvider(final String providerName, final String tag) throws IOException {
LOGGER.debug("Loading pacts from pact broker for provider " + providerName + " and tag " + tag);
URIBuilder uriBuilder = new URIBuilder().setScheme(parseExpressions(pactBrokerProtocol)).setHost(parseExpressions(pactBrokerHost)).setPort(Integer.parseInt(parseExpressions(pactBrokerPort)));
try {
List<ConsumerInfo> consumers;
PactBrokerClient pactBrokerClient = newPactBrokerClient(uriBuilder.build());
if (StringUtils.isEmpty(tag)) {
consumers = pactBrokerClient.fetchConsumers(providerName);
} else {
consumers = pactBrokerClient.fetchConsumersWithTag(providerName, tag);
}
if (failIfNoPactsFound && consumers.isEmpty()) {
throw new NoPactsFoundException("No consumer pacts were found for provider '" + providerName + "' and tag '" + tag + "'. (URL " + pactBrokerClient.getUrlForProvider(providerName, tag) + ")");
}
return consumers.stream().map(consumer -> this.loadPact(consumer, pactBrokerClient.getOptions())).collect(toList());
} catch (URISyntaxException e) {
throw new IOException("Was not able load pacts from broker as the broker URL was invalid", e);
}
}
use of org.apache.http.client.utils.URIBuilder in project hadoop by apache.
the class RemoteSASKeyGenerationResponse method getContainerSASUri.
@Override
public URI getContainerSASUri(String storageAccount, String container) throws SASKeyGenerationException {
try {
LOG.debug("Generating Container SAS Key for Container {} " + "inside Storage Account {} ", container, storageAccount);
URIBuilder uriBuilder = new URIBuilder(credServiceUrl);
uriBuilder.setPath("/" + CONTAINER_SAS_OP);
uriBuilder.addParameter(STORAGE_ACCOUNT_QUERY_PARAM_NAME, storageAccount);
uriBuilder.addParameter(CONTAINER_QUERY_PARAM_NAME, container);
uriBuilder.addParameter(SAS_EXPIRY_QUERY_PARAM_NAME, "" + getSasKeyExpiryPeriod());
uriBuilder.addParameter(DELEGATION_TOKEN_QUERY_PARAM_NAME, this.delegationToken);
RemoteSASKeyGenerationResponse sasKeyResponse = makeRemoteRequest(uriBuilder.build());
if (sasKeyResponse == null) {
throw new SASKeyGenerationException("RemoteSASKeyGenerationResponse" + " object null from remote call");
} else if (sasKeyResponse.getResponseCode() == REMOTE_CALL_SUCCESS_CODE) {
return new URI(sasKeyResponse.getSasKey());
} else {
throw new SASKeyGenerationException("Remote Service encountered error" + " in SAS Key generation : " + sasKeyResponse.getResponseMessage());
}
} catch (URISyntaxException uriSyntaxEx) {
throw new SASKeyGenerationException("Encountered URISyntaxException " + "while building the HttpGetRequest to remote cred service", uriSyntaxEx);
}
}
Aggregations