Example usage for org.apache.http.client.utils URIBuilder addParameter

List of usage examples for org.apache.http.client.utils URIBuilder addParameter

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIBuilder addParameter.

Prototype

public URIBuilder addParameter(final String param, final String value) 

Source Link

Document

Adds parameter to URI query.

Usage

From source file:com.gsma.mobileconnect.impl.OIDCImpl.java

/**
 * See {@link IOIDC#startAuthentication(DiscoveryResponse, String, String, String, String, Integer, String, String, AuthenticationOptions, IStartAuthenticationCallback)}.
 *//*  w  w  w .j av a 2  s  . c o  m*/
public void startAuthentication(DiscoveryResponse discoveryResult, String redirectURI, String state,
        String nonce, String scope, Integer maxAge, String acrValues, String encryptedMSISDN,
        AuthenticationOptions specifiedOptions, IStartAuthenticationCallback callback)
        throws OIDCException, DiscoveryResponseExpiredException {
    validateAuthenticationParameters(discoveryResult, redirectURI, nonce, callback);
    scope = getScope(scope);
    maxAge = getMaxAge(maxAge);
    acrValues = getAcrValues(acrValues);

    AuthenticationOptions optionsToBeUsed = getOptionsToBeUsed(specifiedOptions);

    ParsedOperatorIdentifiedDiscoveryResult parsedOperatorIdentifiedDiscoveryResult = JsonUtils
            .parseOperatorIdentifiedDiscoveryResult(discoveryResult.getResponseData());
    if (null == parsedOperatorIdentifiedDiscoveryResult) {
        throw new OIDCException("Not a valid discovery result.");
    }

    String authorizationHref = parsedOperatorIdentifiedDiscoveryResult.getAuthorizationHref();
    if (StringUtils.isNullOrEmpty(authorizationHref)) {
        throw new OIDCException("No authorization href");
    }

    URIBuilder builder = getUriBuilder(authorizationHref);

    builder.addParameter(Constants.CLIENT_ID_PARAMETER_NAME,
            parsedOperatorIdentifiedDiscoveryResult.getClientId());
    builder.addParameter(Constants.RESPONSE_TYPE_PARAMETER_NAME, Constants.RESPONSE_TYPE_PARAMETER_VALUE);
    builder.addParameter(Constants.SCOPE_PARAMETER_NAME, scope);
    builder.addParameter(Constants.REDIRECT_URI_PARAMETER_NAME, redirectURI);
    builder.addParameter(Constants.ACR_VALUES_PARAMETER_NAME, acrValues);
    if (!StringUtils.isNullOrEmpty(state)) {
        builder.addParameter(Constants.STATE_PARAMETER_NAME, state);
    }
    builder.addParameter(Constants.NONCE_PARAMETER_NAME, nonce);
    builder.addParameter(Constants.DISPLAY_PARAMETER_NAME, optionsToBeUsed.getDisplay());
    if (!StringUtils.isNullOrEmpty(optionsToBeUsed.getPrompt())) {
        builder.addParameter(Constants.PROMPT_PARAMETER_NAME, optionsToBeUsed.getPrompt());
    }
    builder.addParameter(Constants.MAX_AGE_PARAMETER_NAME, maxAge.toString());
    if (!StringUtils.isNullOrEmpty(optionsToBeUsed.getUiLocales())) {
        builder.addParameter(Constants.UI_LOCALES_PARAMETER_NAME, optionsToBeUsed.getUiLocales());
    }
    if (!StringUtils.isNullOrEmpty(optionsToBeUsed.getClaimsLocales())) {
        builder.addParameter(Constants.CLAIMS_LOCALES_PARAMETER_NAME, optionsToBeUsed.getClaimsLocales());
    }
    if (!StringUtils.isNullOrEmpty(optionsToBeUsed.getIdTokenHint())) {
        builder.addParameter(Constants.ID_TOKEN_HINT_PARAMETER_NAME, optionsToBeUsed.getIdTokenHint());
    }
    if (!StringUtils.isNullOrEmpty(optionsToBeUsed.getLoginHint())) {
        builder.addParameter(Constants.LOGIN_HINT_PARAMETER_NAME, optionsToBeUsed.getLoginHint());
    } else if (!StringUtils.isNullOrEmpty(encryptedMSISDN)) {
        builder.addParameter(Constants.LOGIN_HINT_PARAMETER_NAME,
                Constants.ENCRYPTED_MSISDN_PREFIX + encryptedMSISDN);
    }
    if (!StringUtils.isNullOrEmpty(optionsToBeUsed.getDtbs())) {
        builder.addParameter(Constants.DTBS_PARAMETER_NAME, optionsToBeUsed.getDtbs());
    }

    StartAuthenticationResponse authenticationResponse = new StartAuthenticationResponse();
    authenticationResponse.setUrl(buildUrl(builder));
    authenticationResponse.setScreenMode(optionsToBeUsed.getScreenMode());

    callback.complete(authenticationResponse);
}

From source file:uk.ac.ebi.emma.util.Filter.java

/**
 * Generates a query string for use in an HTTP GET request from this <code>Filter
 * </code> instance. Returns an empty string if this filter instance has no
 * parameters./*from   w w  w  .  j av a 2  s.c o m*/
 * 
 * @return a query string for use in an HTTP GET request.
 */
public String generateQueryString() {
    URIBuilder builder = new URIBuilder();
    if (!allele_key.isEmpty())
        builder.addParameter("allele_key", allele_key);
    if (!alleleMgiReference.isEmpty())
        builder.addParameter("alleleMgiReference", alleleMgiReference);
    if (!alleleName.isEmpty())
        builder.addParameter("alleleName", alleleName);
    if (!alleleSymbol.isEmpty())
        builder.addParameter("alleleSymbol", alleleSymbol);
    if (!background_key.isEmpty())
        builder.addParameter("background_key", background_key);
    if (!backgroundName.isEmpty())
        builder.addParameter("backgroundName", backgroundName);
    if (!backgroundSymbol.isEmpty())
        builder.addParameter("backgroundSymbol", backgroundSymbol);
    if (!backgroundIsCurated.isEmpty())
        builder.addParameter("backgroundisCurated", backgroundIsCurated);
    if (!backgroundIsInbred.isEmpty())
        builder.addParameter("backgroundisInbred", backgroundIsInbred);
    if (!biblio_key.isEmpty())
        builder.addParameter("biblio_key", biblio_key);
    if (!biblioAuthor1.isEmpty())
        builder.addParameter("biblioAuthor1", biblioAuthor1);
    if (!biblioJournal.isEmpty())
        builder.addParameter("biblioJournal", biblioJournal);
    if (!biblioTitle.isEmpty())
        builder.addParameter("biblioTitle", biblioTitle);
    if (!biblioYear.isEmpty())
        builder.addParameter("biblioYear", biblioYear);
    if (!chromosome.isEmpty())
        builder.addParameter("chromosome", chromosome);
    if (!gene_key.isEmpty())
        builder.addParameter("gene_key", gene_key);
    if (!geneMgiReference.isEmpty())
        builder.addParameter("geneMgiReference", geneMgiReference);
    if (!geneName.isEmpty())
        builder.addParameter("geneName", geneName);
    if (!geneSymbol.isEmpty())
        builder.addParameter("geneSymbol", geneSymbol);
    if (!mutation_key.isEmpty())
        builder.addParameter("mutation_key", mutation_key);
    if (!mutationType.isEmpty())
        builder.addParameter("mutationType", mutationType);
    if (!mutationSubtype.isEmpty())
        builder.addParameter("mutationSubtype", mutationSubtype);
    if (!pubmedId.isEmpty())
        builder.addParameter("pubmedId", pubmedId);
    if (!strain_key.isEmpty())
        builder.addParameter("strain_key", strain_key);

    String query = "";
    try {
        query = builder.build().getQuery();
    } catch (URISyntaxException e) {
    }

    return query;
}

From source file:com.kolich.havalo.client.service.HavaloClient.java

public Either<HttpFailure, ObjectList> listObjects(final String... path) {
    // The listing of objects is only successful when the
    // resulting status code is a 200 OK.  Any other status
    // code on the response is failure.
    return new HavaloGsonClosure<ObjectList>(client_, gson_.create(), ObjectList.class, SC_OK) {
        @Override//from w  w  w.  ja va  2s . c  om
        public void before(final HttpRequestBase request) throws Exception {
            final URIBuilder builder = new URIBuilder(request.getURI());
            if (path != null && path.length > 0) {
                builder.addParameter(API_PARAM_STARTSWITH, varargsToPrefixString(path));
            }
            request.setURI(builder.build());
            super.before(request);
        }
    }.get(API_ACTION_REPOSITORY);
}

From source file:io.fabric8.etcd.impl.dsl.SetDataImpl.java

@Override
public HttpUriRequest createRequest(OperationContext context) {
    try {//from  www  .java 2  s. c  o  m
        URIBuilder builder = new URIBuilder(context.getBaseUri()).setPath(Keys.makeKey(key))
                .addParameter("value", value).addParameter("dir", String.valueOf(dir))
                .addParameter("ordered", String.valueOf(ordered))
                .addParameter("prevExists", String.valueOf(prevExists));

        if (ttl >= 0) {
            builder = builder.addParameter("ttl", String.valueOf(ttl));
        }

        if (prevValue != null) {
            builder = builder.addParameter("prevValue", prevValue).addParameter("prevIndex",
                    String.valueOf(prevIndex));

        }

        return new HttpPut(builder.build());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:eu.eubrazilcc.lvl.storage.gravatar.Gravatar.java

public URL jsonProfileUrl() {
    try {/*from   w w w. j av a 2 s .  c  o  m*/
        final URIBuilder uriBuilder = new URIBuilder(
                (secure ? SECURE_URL_BASE : DEFAULT_URL_BASE) + emailHash(email) + ".json").addParameter("d",
                        "404");
        if (isNotBlank(profileCallback)) {
            uriBuilder.addParameter("callback", profileCallback);
        }
        return uriBuilder.build().toURL();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to get Gravatar JSON profile URL", e);
    }
}

From source file:org.apache.james.jmap.methods.integration.cucumber.DownloadStepdefs.java

@When("^\"([^\"]*)\" downloads \"([^\"]*)\" without blobId parameter$")
public void getDownloadWithoutBlobId(String username, String attachmentId) throws Throwable {
    String blobId = blobIdByAttachmentId.get(attachmentId);

    URIBuilder uriBuilder = mainStepdefs.baseUri().setPath("/download/");
    trustForBlobId(blobId, username);/*w  w  w .j  a  v a2  s.c o m*/
    AttachmentAccessTokenKey key = new AttachmentAccessTokenKey(username, blobId);
    uriBuilder.addParameter("access_token", attachmentAccessTokens.get(key).serialize());
    response = Request.Get(uriBuilder.build()).execute().returnResponse();
}

From source file:org.sahli.asciidoc.confluence.publisher.client.http.HttpRequestFactory.java

HttpGet getAttachmentByFileNameRequest(String contentId, String attachmentFileName, String expandOptions) {
    assertMandatoryParameter(isNotBlank(contentId), "contentId");
    assertMandatoryParameter(isNotBlank(attachmentFileName), "attachmentFileName");

    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setPath(this.confluenceRestApiEndpoint + "/content/" + contentId + "/child/attachment");
    uriBuilder.addParameter("filename", attachmentFileName);

    if (isNotBlank(expandOptions)) {
        uriBuilder.addParameter("expand", expandOptions);
    }//w  w w .  j  a v a 2s.  c o m

    HttpGet getAttachmentByFileNameRequest;
    try {
        getAttachmentByFileNameRequest = new HttpGet(uriBuilder.build().toString());
    } catch (URISyntaxException e) {
        throw new RuntimeException("Invalid URL", e);
    }

    return getAttachmentByFileNameRequest;
}

From source file:com.michaeljones.httpclient.apache.ApacheMethodClient.java

@Override
public int PutFile(String url, String filePath, List<Pair<String, String>> queryParams, StringBuilder redirect)
        throws FileNotFoundException {
    try {//  ww  w  . j av  a 2  s . c  o m
        URIBuilder fileUri = new URIBuilder(url);

        if (queryParams != null) {
            // Query params are optional. In the case of a redirect the url will contain
            // all the params.
            for (Pair<String, String> queryParam : queryParams) {
                fileUri.addParameter(queryParam.getFirst(), queryParam.getSecond());
            }
        }

        HttpPut httpPut = new HttpPut(fileUri.build());
        InputStream fileInStream = new FileInputStream(filePath);
        InputStreamEntity chunkedStream = new InputStreamEntity(fileInStream, -1,
                ContentType.APPLICATION_OCTET_STREAM);
        chunkedStream.setChunked(true);

        httpPut.setEntity(chunkedStream);

        CloseableHttpResponse response = clientImpl.execute(httpPut);
        try {
            Header[] hdrs = response.getHeaders("Location");
            if (redirect != null && hdrs.length > 0) {
                String redirectLocation = hdrs[0].getValue();

                redirect.append(redirectLocation);
                LOGGER.debug("Redirect to: " + redirectLocation);
            }

            return response.getStatusLine().getStatusCode();
        } finally {
            // I believe this releases the connection to the client pool, but does not
            // close the connection.
            response.close();
        }
    } catch (IOException | URISyntaxException ex) {
        throw new RuntimeException("Apache method putQuery: " + ex.getMessage());
    }
}

From source file:com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector.java

/**
 * Upload a file given file path//from   w ww  . j a  va  2 s. co m
 * @param filePath
 */
@Override
public void uploadFile(String filePath) {
    try (CloseableHttpClient client = HttpClients.createDefault();) {
        // zip file
        List<File> appFiles = new ArrayList<>();
        appFiles.add(new File(filePath));
        File zipFile = FileUtility.createZipArchiveFromFiles(appFiles);

        HttpHost serverHost = new HttpHost(hubUrl.getHost(), hubUrl.getPort());
        URIBuilder builder = new URIBuilder();
        builder.setPath("/grid/admin/FileServlet/");
        builder.addParameter("output", "app");
        HttpPost httpPost = new HttpPost(builder.build());
        httpPost.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.OCTET_STREAM.toString());
        FileInputStream fileInputStream = new FileInputStream(zipFile);
        InputStreamEntity entity = new InputStreamEntity(fileInputStream);
        httpPost.setEntity(entity);

        CloseableHttpResponse response = client.execute(serverHost, httpPost);
        if (response.getStatusLine().getStatusCode() != 200) {
            throw new SeleniumGridException(
                    "could not upload file: " + response.getStatusLine().getReasonPhrase());
        } else {
            // TODO call remote API
            throw new NotImplementedException("call remote Robot to really upload file");
        }

    } catch (IOException | URISyntaxException e) {
        throw new SeleniumGridException("could not upload file", e);
    }
}