Search in sources :

Example 86 with URIBuilder

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;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 87 with URIBuilder

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);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 88 with URIBuilder

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);
    }
}
Also used : IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 89 with URIBuilder

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);
    }
}
Also used : PactRunnerTagListExpressionParser.parseTagListExpressions(au.com.dius.pact.provider.junit.sysprops.PactRunnerTagListExpressionParser.parseTagListExpressions) java.util(java.util) Logger(org.slf4j.Logger) Pact(au.com.dius.pact.model.Pact) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) URIBuilder(org.apache.http.client.utils.URIBuilder) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) PactRunnerExpressionParser.parseExpressions(au.com.dius.pact.provider.junit.sysprops.PactRunnerExpressionParser.parseExpressions) StringUtils(org.apache.commons.lang3.StringUtils) Collectors.toList(java.util.stream.Collectors.toList) PactReader(au.com.dius.pact.model.PactReader) PactBrokerClient(au.com.dius.pact.provider.broker.PactBrokerClient) URI(java.net.URI) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) PactBrokerClient(au.com.dius.pact.provider.broker.PactBrokerClient) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 90 with URIBuilder

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);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder)

Aggregations

URIBuilder (org.apache.http.client.utils.URIBuilder)107 URISyntaxException (java.net.URISyntaxException)42 URI (java.net.URI)37 HttpGet (org.apache.http.client.methods.HttpGet)22 IOException (java.io.IOException)21 NameValuePair (org.apache.http.NameValuePair)13 HttpEntity (org.apache.http.HttpEntity)10 NotNull (org.jetbrains.annotations.NotNull)9 Map (java.util.Map)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 HttpResponse (org.apache.http.HttpResponse)7 List (java.util.List)6 HttpClient (org.apache.http.client.HttpClient)5 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)5 Gson (com.google.gson.Gson)4 URL (java.net.URL)4 RequestConfig (org.apache.http.client.config.RequestConfig)4 HttpPost (org.apache.http.client.methods.HttpPost)4