本文整理匯總了Java中org.jboss.netty.handler.codec.http.HttpResponse.getContent方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponse.getContent方法的具體用法?Java HttpResponse.getContent怎麽用?Java HttpResponse.getContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.handler.codec.http.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.getContent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
protected SearchResponse createResponse(HttpContext<SearchRequest, SearchResponse> httpContext) throws IOException {
if (httpContext == null) {
throw new IllegalStateException("no http context");
}
HttpResponse httpResponse = httpContext.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 = null;
return new SearchResponse(internalSearchResponse, scrollId, totalShards, successfulShards, tookInMillis, shardFailures);
}
示例2: decode
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception
{
HttpResponse nettyResponse = (HttpResponse) msg;
RestResponseBuilder builder = new RestResponseBuilder();
HttpResponseStatus status = nettyResponse.getStatus();
builder.setStatus(status.getCode());
for (Map.Entry<String, String> e : nettyResponse.getHeaders())
{
builder.unsafeAddHeaderValue(e.getKey(), e.getValue());
}
ChannelBuffer buf = nettyResponse.getContent();
byte[] array = new byte[buf.readableBytes()];
buf.readBytes(array);
builder.setEntity(array);
return builder.build();
}
示例3: createResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@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;
}
示例4: createResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@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;
}
示例5: createResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@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);
}
示例6: createResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@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;
}
示例7: describeResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
/**
* Se ejecutará cuando se reciba un response despues de enviar un DESCRIBE
* Comprobará que todo es correcto, y si es así enviará una petición de SETUP
* @param response
*/
public void describeResponse(HttpResponse response) {
try {
checkCseq(response);
ChannelBuffer content = response.getContent();
checkSDP(response);
parseSDP(content);
//Ahora enviamos el setup del primer stream y lo sacamos de la lista
if(!streamsSetup.isEmpty()) {
String stream = streamsSetup.get(0);
streamsSetup.remove(0);
sendSetup(getMedia() + "/" + stream);
}
} catch (Exception e) {
createNotify("ERROR DESCRIBE RESPONSE: " + e.getMessage(),false);
}
}
示例8: invoke
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
/**
* Handles a prepared WebSocket API invocation
* @param asMap true if the JSON reponse is a map, false if it is an array
* @param request The prepared HTTP request so we can piggy-back on the existing RpcHandler services.
* @param response The JSONResponse to write back to
* @throws IOException thrown on IO errors
*/
protected void invoke(boolean asMap, HttpRequest request, JSONResponse response) throws IOException {
try {
JsonGenerator generator = response.writeHeader(asMap);
InvocationChannel ichannel = new InvocationChannel();
HttpQuery query = new HttpQuery(tsdb, request, ichannel);
String baseRoute = query.getQueryBaseRoute();
rpcHandler.messageReceived(null, new UpstreamMessageEvent(ichannel, request, null));
HttpResponse resp = (HttpResponse)ichannel.getWrites().get(0);
ChannelBuffer content = resp.getContent();
ChannelBufferInputStream cbis = new ChannelBufferInputStream(content);
ObjectReader reader = jsonMapper.reader();
JsonNode contentNode = reader.readTree(cbis);
cbis.close();
if(asMap) {
ObjectNode on = (ObjectNode)contentNode;
Iterator<Map.Entry<String, JsonNode>> nodeIter = on.fields();
while(nodeIter.hasNext()) {
Map.Entry<String, JsonNode> node = nodeIter.next();
generator.writeObjectField(node.getKey(), node.getValue());
}
} else {
ArrayNode an = (ArrayNode)contentNode;
for(int i = 0; i < an.size(); i++) {
generator.writeObject(an.get(i));
}
}
response.closeGenerator();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例9: createResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@Override
protected RefreshResponse createResponse(HttpContext<RefreshRequest, RefreshResponse> httpContext) throws IOException {
if (httpContext == null) {
throw new IllegalStateException("no http context");
}
HttpResponse httpResponse = httpContext.getHttpResponse();
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();
}
示例10: createResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@Override
protected CreateIndexResponse createResponse(HttpContext<CreateIndexRequest, CreateIndexResponse> httpContext)
throws IOException {
if (httpContext == null) {
throw new IllegalStateException("no http context");
}
HttpResponse httpResponse = httpContext.getHttpResponse();
BytesReference ref = new ChannelBufferBytesReference(httpResponse.getContent());
Map<String, Object> map = JsonXContent.jsonXContent.createParser(ref).map();
boolean acknowledged = map.containsKey("acknowledged") && (Boolean) map.get("acknowledged");
return new CreateIndexResponse(acknowledged);
}
示例11: createResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@Override
protected IndexResponse createResponse(HttpContext<IndexRequest, IndexResponse> httpContext) throws IOException {
HttpResponse httpResponse = httpContext.getHttpResponse();
BytesReference ref = new ChannelBufferBytesReference(httpResponse.getContent());
Map<String, Object> map = JsonXContent.jsonXContent.createParser(ref).map();
logger.info("{}", map);
return new IndexResponse();
}
示例12: createResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
protected BulkResponse createResponse(HttpContext<BulkRequest, BulkResponse> httpContext) throws IOException {
if (httpContext == null) {
throw new IllegalStateException("no http context");
}
HttpResponse httpResponse = httpContext.getHttpResponse();
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);
}
示例13: createResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@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();
}
示例14: createResponse
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@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();
}
示例15: hasContents
import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
public static boolean hasContents(HttpResponse response, byte[] expectedContents) {
if (response.getContent() != null && HttpHeaders.getContentLength(response, 0) == expectedContents.length && response.getContent().readableBytes() == expectedContents.length) {
final byte[] compareBytes = new byte[expectedContents.length];
response.getContent().readBytes(compareBytes);
return Arrays.equals(expectedContents, compareBytes);
}
return false;
}