本文整理匯總了Java中org.jboss.netty.handler.codec.http.HttpRequest.setContent方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequest.setContent方法的具體用法?Java HttpRequest.setContent怎麽用?Java HttpRequest.setContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.handler.codec.http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.setContent方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: assemble
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public HttpRequest assemble(Channel channel) {
List<HttpChunk> chunkList = chunkMap.remove(channel);
HttpRequest request = initialRequests.remove(channel);
ChannelBuffer dstBuffer = ChannelBuffers.dynamicBuffer();
request.setContent(dstBuffer);
try {
for (HttpChunk chunk : chunkList) {
dstBuffer.writeBytes(chunk.getContent());
}
} catch (Exception e) {
LOG.warn("Error while assembling HTTP request chunks", e);
}
return request;
}
示例2: newRequest
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
protected HttpRequest newRequest(HttpMethod method, URL url, String path, ChannelBuffer buffer) {
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, method, path);
request.headers().add(HttpHeaders.Names.HOST, url.getHost());
request.headers().add(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
request.headers().add(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
if (buffer != null) {
request.setContent(buffer);
int length = request.getContent().readableBytes();
request.headers().add(HttpHeaders.Names.CONTENT_TYPE, "application/json");
request.headers().add(HttpHeaders.Names.CONTENT_LENGTH, length);
}
return request;
}
示例3: createJsonRequest
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private HttpRequest createJsonRequest(String content) {
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, SLAVE_REQ_PATH);
ChannelBuffer buffer = ChannelBuffers.copiedBuffer(content, UTF_8);
request.setContent(buffer);
request.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
return request;
}
示例4: createJsonRequest
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private HttpRequest createJsonRequest(String content) {
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/genvid/");
ChannelBuffer buffer = ChannelBuffers.copiedBuffer(content, UTF_8);
request.setContent(buffer);
request.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
return request;
}
示例5: createJsonRequest
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private HttpRequest createJsonRequest(String content) {
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
ChannelBuffer buffer = ChannelBuffers.copiedBuffer(content, UTF_8);
request.setContent(buffer);
request.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
return request;
}
示例6: testDecode
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Test
public void testDecode() throws Exception {
PiligrimProtocolDecoder decoder = new PiligrimProtocolDecoder(null);
decoder.setDataManager(new TestDataManager());
HttpRequest msg1 = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/bingps?imei=868204005544720&csq=18&vout=00&vin=4050&dataid=00000000");
int[] buf1 = {0xff,0xf2,0x20,0x0d,0x41,0x10,0x06,0x1a,0x32,0x35,0x4f,0x34,0x22,0x31,0x00,0x62,0x00,0x0a,0x00,0x05,0x17,0x3b,0x00,0x00,0xa1,0x01,0x00,0x03,0x00,0x00,0x5e,0x00,0xff,0xf2,0x20,0x0d,0x41,0x10,0x10,0x09,0x32,0x35,0x4f,0x2b,0x22,0x31,0x00,0x42,0x00,0x0b,0x00,0x0e,0x17,0x3b,0x00,0x00,0x9f,0x01,0x00,0x07,0x00,0x00,0x60,0x00};
msg1.setContent(ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf1)));
verify(decoder.decode(null, null, msg1));
}
示例7: encode
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception
{
RestRequest request = (RestRequest) msg;
HttpMethod nettyMethod = HttpMethod.valueOf(request.getMethod());
URL url = new URL(request.getURI().toString());
String path = url.getFile();
// RFC 2616, section 5.1.2:
// Note that the absolute path cannot be empty; if none is present in the original URI,
// it MUST be given as "/" (the server root).
if (path.isEmpty())
{
path = "/";
}
HttpRequest nettyRequest =
new DefaultHttpRequest(HttpVersion.HTTP_1_1, nettyMethod, path);
nettyRequest.setHeader(HttpHeaders.Names.HOST, url.getAuthority());
for (Map.Entry<String, String> e : request.getHeaders().entrySet())
{
nettyRequest.setHeader(e.getKey(), e.getValue());
}
final ByteString entity = request.getEntity();
ChannelBuffer buf = ChannelBuffers.wrappedBuffer(entity.asByteBuffer());
nettyRequest.setContent(buf);
nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, entity.length());
return nettyRequest;
}
示例8: createSendDataRequest
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public static HttpRequest createSendDataRequest(String host, String cookie, ChannelBuffer data, String userAgent) {
final HttpRequest request = createRequestTemplate(host, cookie, CLIENT_SEND_REQUEST_URI, userAgent);
request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, Long.toString(data.readableBytes()));
request.setContent(data);
return request;
}
示例9: updateMGetRequest
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private RestRequest updateMGetRequest(RestRequest request, String oldIndex, String newIndex) {
BytesReference content = request.content();
String stringContent = content.toUtf8();
String replaced = stringContent.replaceAll("_index\":\"" + oldIndex + "\"", "_index\":\"" + newIndex + "\"");
NettyHttpRequest nettyRequest = (NettyHttpRequest) request;
HttpRequest httpRequest = nettyRequest.request();
BytesReference replacedContent = new BytesArray(replaced);
BigEndianHeapChannelBuffer buffer = new BigEndianHeapChannelBuffer(replacedContent.array());
httpRequest.setContent(buffer);
RestRequest updatedRequest = new NettyHttpRequest(httpRequest, nettyRequest.getChannel());
updatedRequest.copyContextAndHeadersFrom(request);
return updatedRequest;
}
示例10: apply
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public Future<HttpResponse> apply(HttpRequest req) {
// Parse URL parameters
String bannerSize = null;
String opt = null;
QueryStringDecoder decoder = new QueryStringDecoder(req.getUri());
Map <String, List<String>> params = decoder.getParameters();
if (params.containsKey("bsize")) {
bannerSize = params.get("bsize").get(0);
opt = params.get("opt").get(0);
}
// Parse cookie
Cookie cookie = null;
String value = req.getHeader("Cookie");
if (value != null) {
Set<Cookie> cookies = new CookieDecoder().decode(value);
for (Cookie c : cookies) {
if (c.getName().equals(COOKIE_NAME)) {
cookie = c;
}
}
}
String vizid = null;
if (cookie != null) {
vizid = cookie.getValue();
} else {
vizid = UUID.randomUUID().toString();
// TODO Avoid cache access
}
// Get data from redis cache, through RedisServer
Service<HttpRequest, HttpResponse> client = Http.newService(":8002");
HttpRequest helperRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
JSONObject jsonReq = new JSONObject();
jsonReq.put("key", vizid);
jsonReq.put("command", "SMEMBERS");
ChannelBuffer buffer = ChannelBuffers.copiedBuffer(jsonReq.toJSONString(), UTF_8);
helperRequest.setContent(buffer);
helperRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
helperRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
Future<HttpResponse> helperResponse = client.apply(helperRequest);
client.close();
Future<HttpResponse> response = helperResponse.flatMap(new ProcessResponse2(req, vizid,
bannerSize, opt, jsonParser));
System.out.println("[CookieServer] Returning response Future");
return response;
}
示例11: main
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public static void main(String[] args) {
Service<HttpRequest, HttpResponse> service = new Service<HttpRequest, HttpResponse>() {
@Override
public Future<HttpResponse> apply(HttpRequest request) {
String reqContent = request.getContent().toString(CharsetUtil.UTF_8);
System.out.println("[Main] Request received: " + reqContent);
// Parsing JSON request
JSONObject mainReq;
try {
mainReq = (JSONObject) jsonParser.parse(reqContent);
System.out.println("[Main] Param received - pname:" + mainReq.get("pname"));
} catch (ParseException e) {
e.printStackTrace();
}
// Initiate request to Helper
Service<HttpRequest, HttpResponse> client = ClientBuilder
.safeBuild(ClientBuilder.get().codec(Http.get())
.hosts("localhost:9004").hostConnectionLimit(1));
HttpRequest helperRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
ChannelBuffer buffer;
buffer = request.getContent();
//buffer = ChannelBuffers.copiedBuffer("{\"dummy\":1}", CharsetUtil.UTF_8);
helperRequest.setContent(buffer);
helperRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
helperRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
Future<HttpResponse> helperResponse = client.apply(helperRequest);
client.close();
// TODO Understand how Future exceptions are handled. Eg: Connection Error
/* helperResponse.addEventListener(
new FutureEventListener<HttpResponse>() {
public void onSuccess(HttpResponse helperResponse) {
System.out.print("[Main] Received helper response: ");
System.out.println(helperResponse.getContent().toString(CharsetUtil.UTF_8));
}
public void onFailure(Throwable cause) {
System.out.println("[Main] Helper failed with cause: " + cause);
}
}); */
Future <HttpResponse> mainResponse = helperResponse.flatMap(new GetBid());
return mainResponse;
}
};
ServerBuilder.safeBuild(service,
ServerBuilder.get().codec(Http.get()).name("HttpServer")
.bindTo(new InetSocketAddress("localhost", 9001)));
}
示例12: setNoData
import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private static void setNoData(HttpRequest request) {
request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, "0");
request.setContent(null);
}