Java Code Examples for org.jboss.netty.handler.codec.http.HttpResponse#getContent()
The following examples show how to use
org.jboss.netty.handler.codec.http.HttpResponse#getContent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpRefreshIndexAction.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
@Override protected RefreshResponse createResponse(HttpInvocationContext<RefreshRequest,RefreshResponse> httpInvocationContext) { if (httpInvocationContext == null) { throw new IllegalStateException("no http context"); } HttpResponse httpResponse = httpInvocationContext.getHttpResponse(); try { BytesReference ref = new ChannelBufferBytesReference(httpResponse.getContent()); Map<String,Object> map = JsonXContent.jsonXContent.createParser(ref).map(); logger.info("{}", map); // RefreshResponse(int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) { return new RefreshResponse(); } catch (IOException e) { // } return null; }
Example 2
Source File: HttpCreateIndexAction.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
@Override protected CreateIndexResponse createResponse(HttpInvocationContext<CreateIndexRequest,CreateIndexResponse> httpInvocationContext) { if (httpInvocationContext == null) { throw new IllegalStateException("no http context"); } HttpResponse httpResponse = httpInvocationContext.getHttpResponse(); try { BytesReference ref = new ChannelBufferBytesReference(httpResponse.getContent()); Map<String,Object> map = JsonXContent.jsonXContent.createParser(ref).map(); boolean acknowledged = map.containsKey("acknowledged") ? (Boolean)map.get("acknowledged") : false; return new CreateIndexResponse(acknowledged); } catch (IOException e) { // } return null; }
Example 3
Source File: HttpSearchAction.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") protected SearchResponse createResponse(HttpInvocationContext<SearchRequest,SearchResponse> httpInvocationContext) throws IOException { if (httpInvocationContext == null) { throw new IllegalStateException("no http context"); } HttpResponse httpResponse = httpInvocationContext.getHttpResponse(); logger.info("{}", httpResponse.getContent().toString(CharsetUtil.UTF_8)); BytesReference ref = new ChannelBufferBytesReference(httpResponse.getContent()); Map<String,Object> map = JsonXContent.jsonXContent.createParser(ref).map(); logger.info("{}", map); InternalSearchResponse internalSearchResponse = parseInternalSearchResponse(map); String scrollId = (String)map.get(SCROLL_ID); int totalShards = 0; int successfulShards = 0; if (map.containsKey(SHARDS)) { Map<String,?> shards = (Map<String,?>)map.get(SHARDS); totalShards = shards.containsKey(TOTAL) ? (Integer)shards.get(TOTAL) : -1; successfulShards = shards.containsKey(SUCCESSFUL) ? (Integer)shards.get(SUCCESSFUL) : -1; } int tookInMillis = map.containsKey(TOOK) ? (Integer)map.get(TOOK) : -1; ShardSearchFailure[] shardFailures = parseShardFailures(map); return new SearchResponse(internalSearchResponse, scrollId, totalShards, successfulShards, tookInMillis, shardFailures); }
Example 4
Source File: HttpBulkAction.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") protected BulkResponse createResponse(HttpInvocationContext<BulkRequest,BulkResponse> httpInvocationContext) { if (httpInvocationContext == null) { throw new IllegalStateException("no http context"); } HttpResponse httpResponse = httpInvocationContext.getHttpResponse(); try { BytesReference ref = new ChannelBufferBytesReference(httpResponse.getContent()); Map<String,Object> map = JsonXContent.jsonXContent.createParser(ref).map(); long tookInMillis = map.containsKey("took") ? (Integer)map.get("took") : -1L; BulkItemResponse[] responses = parseItems((List<Map<String,?>>)map.get("items")); return new BulkResponse(responses, tookInMillis); } catch (IOException e) { // } return null; }
Example 5
Source File: FileClientHandler.java From netty-file-parent with Apache License 2.0 | 5 votes |
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (!this.readingChunks) { HttpResponse response = (HttpResponse) e.getMessage(); LOGGER.info("STATUS: " + response.getStatus()); if ((response.getStatus().getCode() == 200) && (response.isChunked())) { this.readingChunks = true; } else { ChannelBuffer content = response.getContent(); if (content.readable()) this.responseContent.append(content .toString(CharsetUtil.UTF_8)); } } else { HttpChunk chunk = (HttpChunk) e.getMessage(); if (chunk.isLast()) { this.readingChunks = false; this.responseContent.append(chunk.getContent().toString( CharsetUtil.UTF_8)); String json = this.responseContent.toString(); this.result = ((Result) JSONUtil.parseObject(json,Result.class)); } else { this.responseContent.append(chunk.getContent().toString( CharsetUtil.UTF_8)); } } }
Example 6
Source File: HttpUpdateSettingsAction.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override protected UpdateSettingsResponse createResponse(HttpInvocationContext<UpdateSettingsRequest,UpdateSettingsResponse> httpInvocationContext) throws IOException { if (httpInvocationContext == null) { throw new IllegalStateException("no http context"); } HttpResponse httpResponse = httpInvocationContext.getHttpResponse(); BytesReference ref = new ChannelBufferBytesReference(httpResponse.getContent()); Map<String,Object> map = JsonXContent.jsonXContent.createParser(ref).map(); return new UpdateSettingsResponse(); }
Example 7
Source File: HttpClusterUpdateSettingsAction.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override protected ClusterUpdateSettingsResponse createResponse(HttpInvocationContext<ClusterUpdateSettingsRequest,ClusterUpdateSettingsResponse> httpInvocationContext) throws IOException { if (httpInvocationContext == null) { throw new IllegalStateException("no http context"); } HttpResponse httpResponse = httpInvocationContext.getHttpResponse(); BytesReference ref = new ChannelBufferBytesReference(httpResponse.getContent()); Map<String,Object> map = JsonXContent.jsonXContent.createParser(ref).map(); return new ClusterUpdateSettingsResponse(); }