當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpResponse.getContent方法代碼示例

本文整理匯總了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);
}
 
開發者ID:jprante,項目名稱:elasticsearch-client-http,代碼行數:27,代碼來源:HttpSearchAction.java

示例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();
}
 
開發者ID:ppdai,項目名稱:rest4j,代碼行數:24,代碼來源:RAPClientCodec.java

示例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;
}
 
開發者ID:jprante,項目名稱:elasticsearch-helper,代碼行數:18,代碼來源:HttpRefreshIndexAction.java

示例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;
}
 
開發者ID:jprante,項目名稱:elasticsearch-helper,代碼行數:17,代碼來源:HttpCreateIndexAction.java

示例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);
}
 
開發者ID:jprante,項目名稱:elasticsearch-helper,代碼行數:27,代碼來源:HttpSearchAction.java

示例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;
}
 
開發者ID:jprante,項目名稱:elasticsearch-helper,代碼行數:19,代碼來源:HttpBulkAction.java

示例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);
	}
}
 
開發者ID:laggc,項目名稱:rtsp_multicast_pfc,代碼行數:28,代碼來源:ClientRTSP.java

示例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);
	}
	
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:40,代碼來源:TSDBJSONService.java

示例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();
}
 
開發者ID:jprante,項目名稱:elasticsearch-client-http,代碼行數:14,代碼來源:HttpRefreshIndexAction.java

示例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);
}
 
開發者ID:jprante,項目名稱:elasticsearch-client-http,代碼行數:13,代碼來源:HttpCreateIndexAction.java

示例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();
}
 
開發者ID:jprante,項目名稱:elasticsearch-client-http,代碼行數:9,代碼來源:HttpIndexAction.java

示例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);
}
 
開發者ID:jprante,項目名稱:elasticsearch-client-http,代碼行數:14,代碼來源:HttpBulkAction.java

示例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();
}
 
開發者ID:jprante,項目名稱:elasticsearch-helper,代碼行數:11,代碼來源:HttpUpdateSettingsAction.java

示例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();
}
 
開發者ID:jprante,項目名稱:elasticsearch-helper,代碼行數:11,代碼來源:HttpClusterUpdateSettingsAction.java

示例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;
}
 
開發者ID:reines,項目名稱:httptunnel,代碼行數:10,代碼來源:HttpTunnelMessageUtils.java


注:本文中的org.jboss.netty.handler.codec.http.HttpResponse.getContent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。