Search in sources :

Example 26 with Response

use of com.ning.http.client.Response in project openhab1-addons by openhab.

the class PlexConnector method internalSendCommand.

private void internalSendCommand(String machineIdentifier, String url) throws IOException {
    logger.debug("Calling url {}", url);
    BoundRequestBuilder builder = client.prepareGet(url).setHeaders(getDefaultHeaders()).setHeader("X-Plex-Target-Client-Identifier", machineIdentifier);
    builder.execute(new AsyncCompletionHandler<Response>() {

        @Override
        public Response onCompleted(Response response) throws Exception {
            if (response.getStatusCode() != 200) {
                logger.error("Error while sending command to Plex: {}\r\n{}", response.getStatusText(), response.getResponseBody());
            }
            return response;
        }

        @Override
        public void onThrowable(Throwable t) {
            logger.error("Error sending command to Plex", t);
        }
    });
}
Also used : Response(com.ning.http.client.Response) BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) TimeoutException(org.jboss.netty.handler.timeout.TimeoutException) JAXBException(javax.xml.bind.JAXBException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 27 with Response

use of com.ning.http.client.Response in project elasticsearch-suggest-plugin by spinscale.

the class RestSuggestActionTest method getStatistics.

@Override
public FstStats getStatistics() throws Exception {
    List<FstStats.FstIndexShardStats> stats = Lists.newArrayList();
    Response r = httpClient.prepareGet("http://localhost:" + port + "/__suggestStatistics").execute().get();
    assertThat(r.getStatusCode(), is(200));
    System.out.println(r.getResponseBody());
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode rootObj = objectMapper.readTree(r.getResponseBody());
    FstStats fstStats = new FstStats();
    ArrayNode jsonFstStats = (ArrayNode) rootObj.get("fstStats");
    Iterator<JsonNode> nodesIterator = jsonFstStats.iterator();
    while (nodesIterator.hasNext()) {
        JsonNode fstStatsNodeEntry = nodesIterator.next();
        if (fstStatsNodeEntry.isObject()) {
            ShardId shardId = new ShardId(fstStatsNodeEntry.get("index").asText(), fstStatsNodeEntry.get("id").asInt());
            FstStats.FstIndexShardStats fstIndexShardStats = new FstStats.FstIndexShardStats(shardId, null, null, fstStatsNodeEntry.get("sizeInBytes").getLongValue());
            stats.add(fstIndexShardStats);
        }
        fstStats.getStats().addAll(stats);
    }
    return fstStats;
}
Also used : Response(com.ning.http.client.Response) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) FstStats(de.spinscale.elasticsearch.action.suggest.statistics.FstStats) ShardId(org.elasticsearch.index.shard.ShardId) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 28 with Response

use of com.ning.http.client.Response in project elasticsearch-suggest-plugin by spinscale.

the class RestSuggestActionTest method refreshIndexSuggesters.

@Override
public void refreshIndexSuggesters(String index) throws Exception {
    Response r = httpClient.preparePost("http://localhost:" + port + "/" + index + "/product/__suggestRefresh").execute().get();
    assertThat(r.getStatusCode(), is(200));
}
Also used : Response(com.ning.http.client.Response) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)

Example 29 with Response

use of com.ning.http.client.Response in project elasticsearch-suggest-plugin by spinscale.

the class RestSuggestActionTest method refreshAllSuggesters.

@Override
public void refreshAllSuggesters() throws Exception {
    Response r = httpClient.preparePost("http://localhost:" + port + "/__suggestRefresh").execute().get();
    assertThat(r.getStatusCode(), is(200));
}
Also used : Response(com.ning.http.client.Response) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)

Example 30 with Response

use of com.ning.http.client.Response in project elasticsearch-suggest-plugin by spinscale.

the class RestSuggestActionTest method getSuggestions.

@Override
public List<String> getSuggestions(SuggestionQuery suggestionQuery) throws Exception {
    String json = createJSONQuery(suggestionQuery);
    String url = "http://localhost:" + port + "/" + suggestionQuery.index + "/" + suggestionQuery.type + "/__suggest";
    Response r = httpClient.preparePost(url).setBody(json).execute().get();
    assertThat(r.getStatusCode(), is(200));
    assertThatResponseHasNoShardFailures(r);
    return getSuggestionsFromResponse(r.getResponseBody());
}
Also used : Response(com.ning.http.client.Response) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)

Aggregations

Response (com.ning.http.client.Response)33 Test (org.junit.Test)10 IOException (java.io.IOException)9 AsyncHttpClient (com.ning.http.client.AsyncHttpClient)7 Test (org.testng.annotations.Test)7 AsyncHttpClientConfig (com.ning.http.client.AsyncHttpClientConfig)4 Request (com.ning.http.client.Request)4 RequestBuilder (com.ning.http.client.RequestBuilder)4 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)4 HttpMethod (io.netty.handler.codec.http.HttpMethod)4 Map (java.util.Map)4 NodesInfoResponse (org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 CircuitBreaker (com.nike.fastbreak.CircuitBreaker)3 Span (com.nike.wingtips.Span)3 AsyncCompletionHandler (com.ning.http.client.AsyncCompletionHandler)3 NettyAsyncHttpProvider (com.ning.http.client.providers.netty.NettyAsyncHttpProvider)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 JsonObject (javax.json.JsonObject)3 JsonReader (javax.json.JsonReader)3