本文整理汇总了Java中org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1属性的典型用法代码示例。如果您正苦于以下问题:Java HttpVersion.HTTP_1_1属性的具体用法?Java HttpVersion.HTTP_1_1怎么用?Java HttpVersion.HTTP_1_1使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.jboss.netty.handler.codec.http.HttpVersion
的用法示例。
在下文中一共展示了HttpVersion.HTTP_1_1属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
HttpRequest request = (HttpRequest) msg;
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
DeviceSession deviceSession = getDeviceSession(
channel, remoteAddress, decoder.getParameters().get("UserName").get(0));
if (deviceSession == null) {
return null;
}
Parser parser = new Parser(PATTERN, decoder.getParameters().get("LOC").get(0));
if (!parser.matches()) {
return null;
}
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setValid(true);
position.setLatitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
if (channel != null) {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
return position;
}
示例2: messageReceived
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
try {
final HttpRequest req = (HttpRequest) e.getMessage();
if (req.getMethod().equals(HttpMethod.POST)) {
doPost(ctx, e, req);
} else if (req.getMethod().equals(HttpMethod.GET)) {
doGet(ctx, e, req);
} else {
writeResponseAndClose(e, new DefaultHttpResponse(
HttpVersion.HTTP_1_1,
HttpResponseStatus.BAD_REQUEST));
}
} catch (Exception ex) {
if (logger.isDebugEnabled())
logger.debug("Failed to process message", ex);
HttpResponse response = new DefaultHttpResponse(
HttpVersion.HTTP_1_1,
HttpResponseStatus.INTERNAL_SERVER_ERROR);
response.setContent(
ChannelBuffers.copiedBuffer(ex.getMessage().getBytes()));
writeResponseAndClose(e, response);
}
}
示例3: doPost
private void doPost(ChannelHandlerContext ctx, MessageEvent e, HttpRequest req)
throws IOException {
final QueryStringDecoder decoded = new QueryStringDecoder(req.getUri());
if (!decoded.getPath().equalsIgnoreCase("/write")) {
writeResponseAndClose(e,
new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND));
return;
}
try {
metricParser.parse(req);
} catch (IllegalArgumentException iae) {
logger.warn("Metric parser failed: " + iae.getMessage());
}
HttpResponse response = new DefaultHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setContent(ChannelBuffers.copiedBuffer(
("Seen events").getBytes()
));
writeResponseAndClose(e, response);
}
示例4: channelConnected
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
HttpRequest request =
new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.toString());
request.addHeader(Names.ACCEPT, "text/event-stream");
if (headers != null) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
request.addHeader(entry.getKey(), entry.getValue());
}
}
request.addHeader(Names.HOST, uri.getHost());
request.addHeader(Names.ORIGIN, uri.getScheme() + "://" + uri.getHost());
request.addHeader(Names.CACHE_CONTROL, "no-cache");
if (lastEventId != null) {
request.addHeader("Last-Event-ID", lastEventId);
}
e.getChannel().write(request);
channel = e.getChannel();
}
示例5: encode
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception
{
RestResponse response = (RestResponse) msg;
HttpResponse nettyResponse =
new DefaultHttpResponse(HttpVersion.HTTP_1_1,
HttpResponseStatus.valueOf(response.getStatus()));
for (Map.Entry<String, String> e : response.getHeaders().entrySet())
{
nettyResponse.setHeader(e.getKey(), e.getValue());
}
final ByteString entity = response.getEntity();
ChannelBuffer buf = ChannelBuffers.wrappedBuffer(entity.asByteBuffer());
nettyResponse.setContent(buf);
nettyResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, entity.length());
return nettyResponse;
}
示例6: writeResponse
private void writeResponse(MessageEvent e) {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
ChannelBuffer content = ChannelBuffers.dynamicBuffer();
Writer writer = new OutputStreamWriter(new ChannelBufferOutputStream(content), CharsetUtil.UTF_8);
reportAdapter.toJson(report.get(), writer);
try {
writer.close();
} catch (IOException e1) {
LOG.error("error writing resource report", e1);
}
response.setContent(content);
ChannelFuture future = e.getChannel().write(response);
future.addListener(ChannelFutureListener.CLOSE);
}
示例7: messageReceived
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
throws Exception {
HttpRequest request = (HttpRequest) e.getMessage();
String uri = request.getUri();
System.out.println("uri:" + uri);
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
ChannelBuffer buffer = new DynamicChannelBuffer(2048);
buffer.writeBytes("hello!! 你好".getBytes("UTF-8"));
response.setContent(buffer);
response.setHeader("Content-Type", "text/html; charset=UTF-8");
response.setHeader("Content-Length", response.getContent().writerIndex());
Channel ch = e.getChannel();
// Write the initial line and the header.
ch.write(response);
ch.disconnect();
ch.close();
}
示例8: sendResponse
private void sendResponse(Channel channel, HttpResponseStatus status) {
if (channel != null) {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, 0);
channel.write(response);
}
}
示例9: sendResponse
private void sendResponse(Channel channel, String message) {
if (channel != null) {
HttpResponse response = new DefaultHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setContent(ChannelBuffers.copiedBuffer(
ByteOrder.BIG_ENDIAN, message, StandardCharsets.US_ASCII));
channel.write(response);
}
}
示例10: sendResponse
private void sendResponse(Channel channel, short packetId, short packetCount) {
HttpResponse response = new DefaultHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
ChannelBuffer begin = ChannelBuffers.copiedBuffer("#ACK#", StandardCharsets.US_ASCII);
ChannelBuffer end = ChannelBuffers.directBuffer(3);
end.writeByte(packetId);
end.writeByte(packetCount);
end.writeByte(0);
response.setContent(ChannelBuffers.wrappedBuffer(begin, end));
channel.write(response);
}
示例11: channelConnected
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
final String query = "/q?" + this.query.tsdbQueryParams();
logger.debug("Sending query " + query);
final DefaultHttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
query);
e.getChannel().write(req);
}
示例12: stats
/**
* WebSocket invoker for OpenTSDB HTTP <a href="http://opentsdb.net/docs/build/html/api_http/stats.html">api/stats</a> API call
* @param request The JSONRequest
*/
@JSONRequestHandler(name="stats", description="Collects TSDB wide stats and returns them in JSON format to the caller")
public void stats(JSONRequest request) {
try {
HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/stats?json=true");
invoke(false, httpRequest, request.response(ResponseType.RESP));
} catch (Exception ex) {
log.error("Failed to invoke stats", ex);
request.error("Failed to invoke stats", ex).send();
}
}
示例13: file
/**
* WebSocket invoker for OpenTSDB HTTP <a href="http://opentsdb.net/docs/build/html/api_http/s.html">/s</a> static file retrieval API call
* @param request The JSONRequest
*/
@JSONRequestHandler(name="s", description="Retrieves a static file")
public void file(JSONRequest request) {
try {
String fileName = request.getArgument("s").replace("\"", "");
HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ("/s/" + fileName));
invokeForFile(httpRequest, request.response(ResponseType.RESP));
} catch (Exception ex) {
log.error("Failed to invoke s/file", ex);
request.error("Failed to invoke s/file", ex).send();
}
}
示例14: dropcaches
/**
* WebSocket invoker for OpenTSDB HTTP <a href="http://opentsdb.net/docs/build/html/api_http/version.html">/s</a> OpenTSDB version info API call
* @param request The JSONRequest
*/
@JSONRequestHandler(name="dropcaches", description="Drops all OpenTSDB server caches")
public void dropcaches(JSONRequest request) {
try {
HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/dropcaches?json=true");
invoke(true, httpRequest, request.response(ResponseType.RESP));
} catch (Exception ex) {
log.error("Failed to invoke dropcaches", ex);
request.error("Failed to invoke dropcaches", ex).send();
}
}
示例15: logs
/**
* WebSocket invoker for OpenTSDB HTTP <a href="http://opentsdb.net/docs/build/html/api_http/logs.html">/s</a> logs API call
* @param request The JSONRequest
*/
@JSONRequestHandler(name="logs", description="Returns JSONized OpenTSDB log file entries")
public void logs(JSONRequest request) {
try {
HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/logs?json=true");
invoke(true, httpRequest, request.response(ResponseType.RESP));
} catch (Exception ex) {
log.error("Failed to invoke logs", ex);
request.error("Failed to invoke logs", ex).send();
}
}