Package com.ning.http.client

Examples of com.ning.http.client.Response


        BoundRequestBuilder reqBuilder = path.deleteRequest(_httpClient);

        try {
            Future<Response> futurama = _httpClient.executeRequest(reqBuilder.build());
            // First, see if we can get the answer without time out...
            Response resp;
            try {
                resp = futurama.get(timeout, TimeUnit.MILLISECONDS);
            } catch (TimeoutException e) {
                return CallFailure.timeout(_server, startTime, System.currentTimeMillis());
            }
            // and if so, is it successful?
            int statusCode = resp.getStatusCode();
            // one thing first: handle standard headers, if any?
            handleHeaders(_server, resp, startTime);

            // call ok?
            if (!IOUtil.isHTTPSuccess(statusCode)) {
View Full Code Here


        InputStream in = null;
        try {
            Future<Response> futurama = _httpClient.executeRequest(reqBuilder.build());
            // First, see if we can get the answer without time out...
            Response resp;
            try {
                resp = futurama.get(timeout, TimeUnit.MILLISECONDS);
            } catch (TimeoutException e) {
                return failed(CallFailure.timeout(_server, startTime, System.currentTimeMillis()));
            }
            // and if so, is it successful?
            int statusCode = resp.getStatusCode();
            // one thing first: handle standard headers, if any?
            handleHeaders(_server, resp, startTime);

            // call ok?
            if (!IOUtil.isHTTPSuccess(statusCode)) {
                // if not, why not? Any well-known problems? (besides timeout that was handled earlier)

                // then the default fallback
                String msg = getExcerpt(resp, config.getMaxExcerptLength());
                return failed(CallFailure.general(_server, statusCode, startTime, System.currentTimeMillis(), msg));
            }
            ContentType contentType = findContentType(resp, ContentType.JSON);
            in = resp.getResponseBodyAsStream();
            return new AHCEntryListResult<T>(_server, converter.convert(contentType, in));
        } catch (Exception e) {
            if (in != null) {
                try {
                    in.close();
View Full Code Here

        BoundRequestBuilder reqBuilder = path.putRequest(_httpClient);
        reqBuilder = reqBuilder.setBody(gen);
        ListenableFuture<Response> futurama = _httpClient.executeRequest(reqBuilder.build());

        // First, see if we can get the answer without time out...
        Response resp;
        try {
            resp = futurama.get(timeout, TimeUnit.MILLISECONDS);
        } catch (TimeoutException e) {
            return CallFailure.timeout(_server, startTime, System.currentTimeMillis());
        }

        // and if so, is it successful?
        int statusCode = resp.getStatusCode();

        // one more thing: handle standard headers, if any?
        handleHeaders(_server, resp, startTime);

        if (IOUtil.isHTTPSuccess(statusCode)) {
View Full Code Here

                    return listenableFuture.isDone();
                }

                @Override
                public ClientResponse get() throws InterruptedException, ExecutionException {
                    final Response response = listenableFuture.get();
                    if(response != null)
                        return client.getClientResponse(response);
                    else
                        return null;
                }

                @Override
                public ClientResponse get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
                    final Response response = listenableFuture.get(l, timeUnit);
                    if(response != null)
                        return client.getClientResponse(response);
                    else return null;
                }
            };
View Full Code Here

        server.stop();
    }

    @Test
    public void testGetMetrics() throws InterruptedException, ExecutionException, IOException {
        Response response = get(getMetricsPath());

        assertEquals(200, response.getStatusCode());

        JsonNode expected = objectReader.readValue(this.getClass().getResourceAsStream("metricsResponse.json"));
        JsonNode actual = objectReader.readValue(response.getResponseBodyAsBytes());

        assertEquals(expected, actual);
    }
View Full Code Here

        assertEquals(expected, actual);
    }

    @Test
    public void testGetPing() throws IOException, ExecutionException, InterruptedException {
        Response response = get(getPingPath());

        assertEquals(200, response.getStatusCode());
        assertEquals("pong\n", response.getResponseBody());
    }
View Full Code Here

        assertEquals("pong\n", response.getResponseBody());
    }

    @Test
    public void testGetThreads() throws InterruptedException, ExecutionException, IOException {
        Response response = get(getThreadsPath());

        assertEquals(200, response.getStatusCode());

        // the sort of thing that a list of threads should contain
        assertThat(response.getResponseBody(), containsString("RUNNABLE"));
    }
View Full Code Here

        assertThat(response.getResponseBody(), containsString("RUNNABLE"));
    }

    @Test
    public void testGetHealthCheck() throws InterruptedException, ExecutionException, IOException {
        Response response = get(getHealthCheckPath());

        assertEquals(200, response.getStatusCode());

        // the sort of thing that a list of threads should contain
        JsonNode expected = objectReader.readValue(this.getClass().getResourceAsStream("healthChecksResponse.json"));
        JsonNode actual = objectReader.readValue(response.getResponseBodyAsBytes());

        assertEquals(expected, actual);
    }
View Full Code Here

     * @return a list of all the currencies the system knows how to handle
     */
    public List<CurrencyDto> findAll() {
        try {
            String uri = BASE + "/findAll";
            Response r = prepareGet(uri).execute().get();
            validateResponse(r);
            return json.readValue(r.getResponseBody("UTF-8"), new TypeReference<List<CurrencyDto>>(){});
        } catch (Exception e) {
            throw wrapException(e);
        }
    }
View Full Code Here

            String uri = BASE + "/groups?lang=" + lang;
            if ( flags != null && !flags.isEmpty() ) {
              String flagsCsv = StringUtils.setToCommaSeparated(flags);
              uri += "&flags=" + flagsCsv;
            }
            Response r = prepareGet(uri).execute().get();
            validateResponse(r);
            return json.readValue(r.getResponseBody("UTF-8"), new TypeReference<List<TagGroupDto>>(){});
        } catch (Exception e) {
            throw wrapException(e);
        }
    }
View Full Code Here

TOP

Related Classes of com.ning.http.client.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.