本文整理汇总了Java中org.jboss.netty.handler.codec.http.HttpVersion类的典型用法代码示例。如果您正苦于以下问题:Java HttpVersion类的具体用法?Java HttpVersion怎么用?Java HttpVersion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpVersion类属于org.jboss.netty.handler.codec.http包,在下文中一共展示了HttpVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
@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
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
@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
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
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: createRouteBuilder
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("netty-http:http://0.0.0.0:{{port}}/foo")
.to("mock:input")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setContent(ChannelBuffers.copiedBuffer("Bye World".getBytes()));
response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 9);
exchange.getOut().setBody(response);
}
});
}
};
}
示例5: channelConnected
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
@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();
}
示例6: encode
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
@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;
}
示例7: writeResponse
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
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);
}
示例8: messageReceived
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
@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();
}
示例9: failure
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
@Override
public void failure(Throwable error) {
log.error("Uncaught exception in transport layer. This is likely a bug, closing channel.", error);
if (channel.isOpen()) {
if (channel.isWritable()) {
final DefaultHttpResponse internalServerResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_0, HttpResponseStatus.INTERNAL_SERVER_ERROR);
try {
internalServerResponse.setContent(ChannelBuffers.wrappedBuffer(("Uncaught exception!\n"
+ error.getMessage()).getBytes("UTF-8")));
} catch (UnsupportedEncodingException ignored) {}
channel.write(internalServerResponse).addListener(ChannelFutureListener.CLOSE);
} else {
channel.close();
}
}
}
示例10: invalidRequestSent
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
public void invalidRequestSent(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
Channel channel = ctx.getChannel();
if (channel == null || !channel.isOpen()) {
log.debug("Not writing any response, channel is already closed.", e.getCause());
return;
}
final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_0, HttpResponseStatus.BAD_REQUEST);
response.headers().add(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
response.headers().add(HttpHeaders.Names.CONNECTION, "close");
final ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
new ChannelBufferOutputStream(buffer).writeBytes("Your client has sent a malformed or illegal request.\n");
response.setContent(buffer);
final ChannelFuture channelFuture = channel.write(response);
channelFuture.addListener(ChannelFutureListener.CLOSE);
}
示例11: sendResponse
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
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);
}
}
示例12: sendResponse
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
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);
}
}
示例13: sendResponse
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
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);
}
示例14: testClone
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
@Test
public void testClone() throws CloneNotSupportedException {
long st = System.nanoTime();
TestAction action = new TestAction();
ActionRequest req = new ActionRequest("", new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.POST, "aaa"));
ActionResponse res = new ActionResponse(null);
action.init(Type.xml, req, res, null);
for (int i = 0; i < count; i++) {
TestAction a2= (TestAction) action.clone();
}
printTime("Test Clone", st);
}
示例15: channelConnected
import org.jboss.netty.handler.codec.http.HttpVersion; //导入依赖的package包/类
@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);
}