Example usage for org.apache.http.client.fluent Request Get

List of usage examples for org.apache.http.client.fluent Request Get

Introduction

In this page you can find the example usage for org.apache.http.client.fluent Request Get.

Prototype

public static Request Get(final String uri) 

Source Link

Usage

From source file:com.qwazr.search.index.IndexSingleClient.java

@Override
public LinkedHashMap<String, FieldDefinition> getFields(String schema_name, String index_name) {
    UBuilder uriBuilder = new UBuilder("/indexes/", schema_name, "/", index_name, "/fields");
    Request request = Request.Get(uriBuilder.build());
    return commonServiceRequest(request, null, null, FieldDefinition.MapStringFieldTypeRef, 200);
}

From source file:com.qwazr.cluster.client.ClusterSingleClient.java

@Override
public String getActiveNodeRandomByService(String service_name, String group) {
    try {/*from  w w w.j a  v  a 2s .c  o m*/
        UBuilder uriBuilder = new UBuilder("/cluster/services/" + service_name + "/active/random")
                .setParameter("group", group);
        Request request = Request.Get(uriBuilder.build());
        HttpResponse response = execute(request, null, null);
        HttpUtils.checkStatusCodes(response, 200);
        return IOUtils.toString(HttpUtils.checkIsEntity(response, ContentType.TEXT_PLAIN).getContent());
    } catch (IOException e) {
        throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.amazonaws.sample.entitlement.authorization.FacebookOAuth2AuthorizationHandler.java

/**
 * Verify acccess_token via the Facebook graph API.
 * @param accessToken/*w  w w .  j a v  a2  s .  c  o  m*/
 * @return null because we do not get enough information from the graph API request for an Identity
 * @throws AuthorizationException
 */
@Override
Identity verifyAccessToken(String accessToken) throws AuthorizationException {
    try {
        ResponseContent r = Request.Get(
                "https://graph.facebook.com/app?" + "access_token=" + URLEncoder.encode(accessToken, "UTF-8")
        // + "&"
        // + "appsecret_proof=" + URLEncoder.encode(hmacOAuth2Token, "UTF-8")
        ).execute().handleResponse(new AllStatusesContentResponseHandler());

        int statusCode = r.getStatusCode();

        Map<String, Object> m = new ObjectMapper().readValue(r.getContent("{}"), new TypeReference<Object>() {
        });

        if (statusCode == HttpStatus.SC_OK) {
            // For Facebook compare the "id" field against the client id (app id for facebook)
            if (!this.getOauthClientId().equals(m.get("id"))) {
                // the access token is valid but it does not belong to us
                throw new OAuthBadTokenException("access token is invalid", AUTHORIZATION_TYPE);
            }
            // The response does not contain enough information to create an Identity object so null is returned.
            return null;
        }
        if (statusCode == HttpStatus.SC_BAD_REQUEST) {
            throw new OAuthBadRequestException(buildErrorMessageFromResponse(m, statusCode),
                    AUTHORIZATION_TYPE);
        }
        if (statusCode >= 500) {
            throw new RuntimeException(PROVIDER_NAME + " encountered an error. Status code: " + statusCode);
        }

        throw new RuntimeException(
                "Unanticipated response from " + PROVIDER_NAME + ". Status code: " + statusCode);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.cognifide.aet.common.TestSuiteRunner.java

private SuiteStatusResult getSuiteStatus(String statusUrl) throws IOException {
    return Request.Get(statusUrl).connectTimeout(timeout).socketTimeout(timeout).execute()
            .handleResponse(suiteStatusResponseHandler);
}

From source file:org.talend.components.dataprep.connection.DataPrepConnectionHandler.java

private String fetchDataSetId() throws IOException {
    if (dataSetName == null || authorisationHeader == null) {
        return null;
    }/*from w ww  . java2s .  c o m*/

    String result = null;

    URI uri = null;
    URL localUrl = new URL(url);
    try {
        uri = new URI(localUrl.getProtocol(), null, localUrl.getHost(), localUrl.getPort(), "/api/datasets",
                "name=" + dataSetName, null);
    } catch (URISyntaxException e) {
        throw new ComponentException(e);
    }

    Request request = Request.Get(uri);
    request.addHeader(authorisationHeader);
    HttpResponse response = request.execute().returnResponse();
    String content = extractResponseInformationAndConsumeResponse(response);

    if (returnStatusCode(response) != HttpServletResponse.SC_OK) {
        throw new IOException(content);
    }

    if (content != null && !"".equals(content)) {
        Object object = JsonReader.jsonToJava(content);
        if (object != null && object instanceof Object[]) {
            Object[] array = (Object[]) object;
            if (array.length > 0) {
                @SuppressWarnings("rawtypes")
                JsonObject jo = (JsonObject) array[0];
                result = (String) jo.get("id");
            }
        }
    }

    return result;
}

From source file:com.ibm.streamsx.rest.StreamsConnection.java

/**
 * Gets a response to an HTTP call/*from w w w.  j  a v  a  2 s . com*/
 * 
 * @param inputString
 *            REST call to make
 * @return response from the inputString
 * @throws IOException
 */
String getResponseString(String inputString) throws IOException {
    String sReturn = "";
    Request request = Request.Get(inputString).addHeader(AUTH.WWW_AUTH_RESP, apiKey).useExpectContinue();

    Response response = executor.execute(request);
    HttpResponse hResponse = response.returnResponse();
    int rcResponse = hResponse.getStatusLine().getStatusCode();

    if (HttpStatus.SC_OK == rcResponse) {
        sReturn = EntityUtils.toString(hResponse.getEntity());
    } else if (HttpStatus.SC_NOT_FOUND == rcResponse) {
        // with a 404 message, we are likely to have a message from Streams
        // but if not, provide a better message
        sReturn = EntityUtils.toString(hResponse.getEntity());
        if ((sReturn != null) && (!sReturn.equals(""))) {
            throw RESTException.create(rcResponse, sReturn);
        } else {
            String httpError = "HttpStatus is " + rcResponse + " for url " + inputString;
            throw new RESTException(rcResponse, httpError);
        }
    } else {
        // all other errors...
        String httpError = "HttpStatus is " + rcResponse + " for url " + inputString;
        throw new RESTException(rcResponse, httpError);
    }
    traceLog.finest("Request: " + inputString);
    traceLog.finest(rcResponse + ": " + sReturn);
    return sReturn;
}

From source file:de.elomagic.carafile.client.CaraCloud.java

public Set<CloudFileData> list(final Path remotePath) throws IOException {
    LOG.debug("List remote folder \"" + remotePath + "\" file at " + client.getRegistryURI());

    URI uri = CaraFileUtils.buildURI(client.getRegistryURI(), "cloud", "list", remotePath.toString());
    HttpResponse response = client.executeRequest(Request.Get(uri)).returnResponse();

    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        throw new IOException("HTTP responce code " + response.getStatusLine().getStatusCode() + " "
                + response.getStatusLine().getReasonPhrase());
    }//from w  w  w.  java 2s  .  c om

    Charset charset = ContentType.getOrDefault(response.getEntity()).getCharset();

    Set<CloudFileData> set = JsonUtil.read(new InputStreamReader(response.getEntity().getContent(), charset),
            Set.class);

    LOG.debug("Folder contains " + set.size() + " item(s)");

    return set;
}

From source file:eu.esdihumboldt.hale.io.geoserver.rest.AbstractResourceManager.java

/**
 * @see eu.esdihumboldt.hale.io.geoserver.rest.ResourceManager#exists()
 *//* w w  w. j a va  2 s  . c  o  m*/
@Override
public boolean exists() {
    checkResourceSet();

    try {
        return executor.execute(Request.Get(getResourceURL())).handleResponse(new ResponseHandler<Boolean>() {

            /**
             * @see org.apache.http.client.ResponseHandler#handleResponse(org.apache.http.HttpResponse)
             */
            @Override
            public Boolean handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
                int statusCode = response.getStatusLine().getStatusCode();
                String reason = response.getStatusLine().getReasonPhrase();

                switch (statusCode) {
                case 200:
                    return true;
                case 404:
                    return false;
                default:
                    throw new HttpResponseException(statusCode, reason);
                }
            }

        });
    } catch (Exception e) {
        throw new ResourceException(e);
    }
}

From source file:com.jkoolcloud.tnt4j.streams.inputs.HttpStreamTest.java

@Test
public void httpHtmlGetTest() throws Exception {
    HttpResponse response = Request.Get(makeURI()).execute().returnResponse();
    assertNotNull(response);
}