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

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

Introduction

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

Prototype

public URI build() throws URISyntaxException 

Source Link

Document

Builds a URI instance.

Usage

From source file:com.kurtraschke.wmata.gtfsrealtime.services.WMATAAPIService.java

public Routes downloadRouteList() throws WMATAAPIException {
    try {/*from   w w w  . j  a va  2s .  c  o  m*/
        URIBuilder b = new URIBuilder("http://api.wmata.com/Bus.svc/json/JRoutes");
        b.addParameter(API_KEY_PARAM_NAME, _apiKey);

        return mapUrl(b.build(), true, Routes.class, _jsonMapper);
    } catch (Exception e) {
        throw new WMATAAPIException(e);
    }
}

From source file:net.datacrow.onlinesearch.bol.BolClient.java

/**
 * Gets the product./*  ww  w  .  j  ava 2  s.c o m*/
 * @param id The product id (required).
 */
public String getProduct(String ID) throws IOException, URISyntaxException {
    URIBuilder builder = new URIBuilder();
    builder.setScheme("https");
    builder.setHost("openapi.bol.com");
    builder.setPath("/openapi/services/rest/catalog/v3/products/" + ID);
    URI uri = builder.build();

    HttpGet httpGet = new HttpGet(uri);

    HttpOAuthHelper au = new HttpOAuthHelper("application/xml");
    au.handleRequest(httpGet, accessKeyId, secretAccessKey);

    HttpResponse httpResponse = httpClient.execute(httpGet);
    String xml = getXML(httpResponse);
    httpClient.getConnectionManager().shutdown();
    return xml;
}

From source file:org.eclipse.packagedrone.testing.server.channel.UploadApiV3Test.java

@Test
public void upload2Archive() throws URISyntaxException, IOException {
    final ChannelTester tester = ChannelTester.create(getWebContext(), "uploadapi2b");
    tester.assignDeployGroup("m1");
    final String deployKey = tester.getDeployKeys().iterator().next();

    final File file1 = getAbsolutePath(CommonResources.BUNDLE_1_RESOURCE);
    final File file2 = getAbsolutePath(CommonResources.BUNDLE_2_RESOURCE);

    final Path tmp = Paths.get("upload-1.zip");

    try (TransferArchiveWriter writer = new TransferArchiveWriter(Files.newOutputStream(tmp))) {
        final Map<MetaKey, String> properties = new HashMap<>();
        properties.put(new MetaKey("foo", "bar"), "baz");
        properties.put(new MetaKey("foo", "bar2"), "baz2");

        writer.createEntry(file1.getName(), properties, ContentProvider.file(file1));
        writer.createEntry(file2.getName(), properties, ContentProvider.file(file2));
    }//  w w w  .j  a va 2  s  .  co m

    final URIBuilder b = new URIBuilder(resolve("/api/v3/upload/archive/channel/%s", tester.getId()));
    b.setUserInfo("deploy", deployKey);

    System.out.println("Request: " + b.build());

    try (final CloseableHttpResponse response = upload(b, tmp.toFile())) {
        final String result = CharStreams
                .toString(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8));
        System.out.println("Result: " + response.getStatusLine());
        System.out.println(result);
        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    }

    final Set<String> arts = tester.getAllArtifactIds();

    Assert.assertEquals(2, arts.size());
}

From source file:com.kurtraschke.wmata.gtfsrealtime.services.WMATAAPIService.java

public BusPositions downloadBusPositions() throws WMATAAPIException {
    try {//ww w  . j av a  2  s .c om
        URIBuilder b = new URIBuilder("http://api.wmata.com/Bus.svc/json/JBusPositions");
        b.addParameter(API_KEY_PARAM_NAME, _apiKey);

        return mapUrl(b.build(), false, BusPositions.class, _jsonMapper);
    } catch (Exception e) {
        throw new WMATAAPIException(e);
    }
}

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

@Test
public void parseAuthenticationResponse_withSuccessUrl_shouldParseSuccess()
        throws OIDCException, URISyntaxException {
    // GIVEN//from   ww  w .j av a2 s.c  o  m
    IOIDC oidc = Factory.getOIDC(null);
    CaptureParsedAuthorizationResponse captureParsedAuthorizationResponse = new CaptureParsedAuthorizationResponse();

    URIBuilder builder = new URIBuilder("");
    builder.addParameter("code", CODE_STRING);
    builder.addParameter("state", STATE_STRING);

    // WHEN
    oidc.parseAuthenticationResponse(builder.build().toString(), captureParsedAuthorizationResponse);

    // THEN
    ParsedAuthorizationResponse parsedAuthorizationResponse = captureParsedAuthorizationResponse
            .getParsedAuthorizationResponse();
    assertNull(parsedAuthorizationResponse.get_error());
    assertNull(parsedAuthorizationResponse.get_error_description());
    assertNull(parsedAuthorizationResponse.get_error_uri());
    assertEquals(CODE_STRING, parsedAuthorizationResponse.get_code());
    assertEquals(STATE_STRING, parsedAuthorizationResponse.get_state());
}

From source file:com.ibm.subway.NewYorkSubway.java

public StationList getTrainList(String stationId, Locale locale, boolean translate) throws Exception {
    logger.debug("Station {}", stationId);
    StationList returnedList = new StationList();
    WatsonTranslate watson = new WatsonTranslate(locale);

    try {/*  w  w  w.  j  a  v a 2s .c  o  m*/
        if (stationId != null) {
            RequestConfig config = RequestConfig.custom().setSocketTimeout(10 * 1000)
                    .setConnectTimeout(10 * 1000).build();
            CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(config).build();

            URIBuilder builder = new URIBuilder();
            builder.setScheme("http").setHost(url).setPath("/by-id/" + stationId);
            URI uri = builder.build();
            HttpGet httpGet = new HttpGet(uri);
            httpGet.setHeader("Content-Type", "text/plain");

            HttpResponse httpResponse = httpclient.execute(httpGet);

            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                BufferedReader rd = new BufferedReader(
                        new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));

                // Read all the trains from the list
                ObjectMapper mapper = new ObjectMapper();
                returnedList = mapper.readValue(rd, StationList.class);

                // Set the direction of the trains
                ArrayList<Station> stations = returnedList.getStationList();
                for (Station station : stations) {
                    String northString = "North";
                    String southString = "South";

                    if (translate) {
                        northString = watson.translate(northString);
                        southString = watson.translate(southString);
                    }

                    ArrayList<Train> north = station.getNorthTrains();
                    for (Train train : north) {
                        train.setDirection(northString);
                    }
                    ArrayList<Train> south = station.getSouthTrains();
                    for (Train train : south) {
                        train.setDirection(southString);
                    }
                }
            } else {
                logger.error("could not get list from MTA http code {}",
                        httpResponse.getStatusLine().getStatusCode());
            }
        }
    } catch (Exception e) {
        logger.error("could not get list from MTA {}", e.getMessage());
        throw e;
    }

    return returnedList;
}

From source file:org.mitre.openid.connect.client.service.impl.SignedAuthRequestUrlBuilder.java

@Override
public String buildAuthRequestUrl(ServerConfiguration serverConfig, RegisteredClient clientConfig,
        String redirectUri, String nonce, String state, Map<String, String> options, String loginHint) {

    // create our signed JWT for the request object
    JWTClaimsSet.Builder claims = new JWTClaimsSet.Builder();

    //set parameters to JwtClaims
    claims.claim("response_type", "code");
    claims.claim("client_id", clientConfig.getClientId());
    claims.claim("scope", Joiner.on(" ").join(clientConfig.getScope()));

    // build our redirect URI
    claims.claim("redirect_uri", redirectUri);

    // this comes back in the id token
    claims.claim("nonce", nonce);

    // this comes back in the auth request return
    claims.claim("state", state);

    // Optional parameters
    for (Entry<String, String> option : options.entrySet()) {
        claims.claim(option.getKey(), option.getValue());
    }//ww w . j  ava  2 s  .  c om

    // if there's a login hint, send it
    if (!Strings.isNullOrEmpty(loginHint)) {
        claims.claim("login_hint", loginHint);
    }

    JWSAlgorithm alg = clientConfig.getRequestObjectSigningAlg();
    if (alg == null) {
        alg = signingAndValidationService.getDefaultSigningAlgorithm();
    }

    SignedJWT jwt = new SignedJWT(new JWSHeader(alg), claims.build());

    signingAndValidationService.signJwt(jwt, alg);

    try {
        URIBuilder uriBuilder = new URIBuilder(serverConfig.getAuthorizationEndpointUri());
        uriBuilder.addParameter("request", jwt.serialize());

        // build out the URI
        return uriBuilder.build().toString();
    } catch (URISyntaxException e) {
        throw new AuthenticationServiceException("Malformed Authorization Endpoint Uri", e);
    }
}

From source file:com.ibm.idreambooks.DreamBooks.java

public BookReviewList getReviewList() {
    BookReviewList bookReviewList = new BookReviewList();

    try {//from  w w  w. j a v  a 2 s. c  o  m
        if (bookName != null && url != null && apiKey != null) {
            RequestConfig config = RequestConfig.custom().setSocketTimeout(10 * 1000)
                    .setConnectTimeout(10 * 1000).build();
            CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(config).build();
            URIBuilder builder = new URIBuilder();
            builder.setScheme("http").setHost(url).setPath("/api/books/reviews.json")
                    .setParameter("key", apiKey).setParameter("q", bookName);
            URI uri = builder.build();
            HttpGet httpGet = new HttpGet(uri);

            httpGet.setHeader("Content-Type", "text/plain");
            HttpResponse httpResponse = httpclient.execute(httpGet);

            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                BufferedReader rd = new BufferedReader(
                        new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));

                // Read all the books from the best seller list
                ObjectMapper mapper = new ObjectMapper();
                bookReviewList = mapper.readValue(rd, BookReviewList.class);
                logger.debug("iDreamBooks reviews {}", bookReviewList.toString());
            } else {
                logger.error("could not get reviews from iDreamBooks http code {}",
                        httpResponse.getStatusLine().getStatusCode());
            }
        }

    } catch (Exception e) {
        logger.error("could not get reviews from iDreamBooks {}", e.getMessage());
    }

    return bookReviewList;
}

From source file:com.epam.ngb.cli.manager.command.handler.http.GeneAddingHandler.java

@Override
public int runCommand() {
    try {/*from w  w w. j  a va  2s  . co m*/
        String url = serverParameters.getServerUrl() + getRequestUrl();
        URIBuilder builder = new URIBuilder(String.format(url, referenceId));
        if (geneFileId != null) {
            builder.addParameter("geneFileId", String.valueOf(geneFileId));
        }
        HttpPut put = new HttpPut(builder.build());
        setDefaultHeader(put);
        if (isSecure()) {
            addAuthorizationToRequest(put);
        }
        String result = RequestManager.executeRequest(put);
        checkAndPrintRegistrationResult(result, printJson, printTable);
    } catch (URISyntaxException e) {
        throw new ApplicationException(e.getMessage(), e);
    }
    return 0;
}