本文整理汇总了Java中org.jboss.netty.handler.codec.http.HttpResponseStatus.OK属性的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseStatus.OK属性的具体用法?Java HttpResponseStatus.OK怎么用?Java HttpResponseStatus.OK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.jboss.netty.handler.codec.http.HttpResponseStatus
的用法示例。
在下文中一共展示了HttpResponseStatus.OK属性的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: 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);
}
示例3: 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);
}
示例4: 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();
}
示例5: 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);
}
}
示例6: 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);
}
示例7: myTransformer
/**
* We can use both a netty http request and response type for transformation
*/
public static HttpResponse myTransformer(HttpRequest request) {
String in = request.getContent().toString(Charset.forName("UTF-8"));
String reply = "Bye " + in;
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setContent(ChannelBuffers.copiedBuffer(reply.getBytes()));
response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, reply.length());
return response;
}
示例8: createJsonResponse
private HttpResponse createJsonResponse(String content) {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
ChannelBuffer buffer = ChannelBuffers.copiedBuffer(content, UTF_8);
response.setContent(buffer);
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
return response;
}
示例9: main
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("[Helper] Request received: " + reqContent);
// Parsing JSON request
JSONObject jreq;
try {
jreq = (JSONObject) jsonParser.parse(reqContent);
System.out.println("[Main] Param received - pname:" + jreq.get("pname"));
} catch (ParseException e) {
e.printStackTrace();
}
HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
res.setContent(ChannelBuffers.copiedBuffer("{\"v_id\":100, \"price\":0.2}", CharsetUtil.UTF_8));
res.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=UTF-8");
return Future.<HttpResponse> value(res);
}
};
ServerBuilder.safeBuild(service,
ServerBuilder.get().codec(Http.get()).name("HttpServer")
.bindTo(new InetSocketAddress("localhost", 9004)));
}
示例10: apply
public Future<HttpResponse> apply(HttpResponse res) {
String resContent = res.getContent().toString(CharsetUtil.UTF_8);
System.out.println("[Main] Received helper response: " + resContent);
System.out.println("[Main] Sending response to main client");
HttpResponse finalRes = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
finalRes.setContent(ChannelBuffers.copiedBuffer("{\"bid\":" + resContent + "}", CharsetUtil.UTF_8));
finalRes.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
return Future.<HttpResponse> value(finalRes);
}
示例11: 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, Charset.defaultCharset()));
channel.write(response);
}
}
示例12: 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#", Charset.defaultCharset());
ChannelBuffer end = ChannelBuffers.directBuffer(3);
end.writeByte(packetId);
end.writeByte(packetCount);
end.writeByte(0);
response.setContent(ChannelBuffers.wrappedBuffer(begin, end));
channel.write(response);
}
示例13: writeResponse
private void writeResponse(MessageEvent e) throws Exception {
HttpResponse response =
new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setContent(ChannelBuffers.copiedBuffer("Hello world", CharsetUtil.UTF_8));
addHeader(response, HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=UTF-8");
ChannelFuture future = e.getChannel().write(response);
future.addListener(ChannelFutureListener.CLOSE);
}
示例14: messageReceived
public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e)
throws Exception {
// common http request
HttpRequest req = (HttpRequest)e.getMessage();
NettyHttpRequest nhr = new NettyHttpRequest(req);
String path = nhr.path();
Handler handler = handlers.getHandler(path);
DefaultHttpResponse resp = new DefaultHttpResponse(req.getProtocolVersion(), HttpResponseStatus.OK);
if (handler == null){
Set<String> handlerPaths = this.handlers.getHandlerPaths();
// handlerPaths.remove(DataAllocateHandler.PATH);
// handlerPaths.remove(JobMessageFromSlaveHandler.PATH);
JSONArray ja = new JSONArray();
ja.addAll(handlerPaths);
HttpResponseUtil.setResponse(resp, "request path :" + path,
Strings.keyValuesToJson("code",404, "available_path", ja),
HttpResponseStatus.NOT_FOUND);
}else{
handler.handle(nhr, resp);
}
resp.setHeader(HttpHeaders.Names.CONTENT_TYPE, Strings.CONTENT_TYPE);
resp.setHeader("Content-Length", resp.getContent().readableBytes());
boolean close = !HttpHeaders.isKeepAlive(req);
resp.setHeader(HttpHeaders.Names.CONNECTION,
close ? HttpHeaders.Values.CLOSE
: HttpHeaders.Values.KEEP_ALIVE);
ChannelFuture cf = e.getChannel().write(resp);
if (close)
cf.addListener(ChannelFutureListener.CLOSE);
writeAccessLog(e.getChannel(), req, resp);
}
示例15: service
@Override
protected void service(ResourceProvider provider, Channel channel, HttpRequest request) throws IOException {
String path = request.getUri();
ByteBuffer buf = provider.get(path);
ChannelBuffer wrapped;
HttpResponseStatus status = HttpResponseStatus.OK;
String mime = getMimeType(request.getUri());
if (buf == null) {
status = HttpResponseStatus.NOT_FOUND;
wrapped = createErrorPage(status, "The page you requested could not be found.");
mime = "text/html";
} else {
wrapped = ChannelBuffers.wrappedBuffer(buf);
}
HttpResponse response = new DefaultHttpResponse(request.getProtocolVersion(), status);
response.setHeader("Date", new Date());
response.setHeader("Server", SERVER_IDENTIFIER);
response.setHeader("Content-type", mime + ", charset=" + CHARACTER_SET.name());
response.setHeader("Cache-control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", new Date(0));
response.setHeader("Connection", "close");
response.setHeader("Content-length", wrapped.readableBytes());
response.setChunked(false);
response.setContent(wrapped);
channel.write(response).addListener(ChannelFutureListener.CLOSE);
}