本文整理汇总了Java中org.jboss.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR属性的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseStatus.INTERNAL_SERVER_ERROR属性的具体用法?Java HttpResponseStatus.INTERNAL_SERVER_ERROR怎么用?Java HttpResponseStatus.INTERNAL_SERVER_ERROR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.jboss.netty.handler.codec.http.HttpResponseStatus
的用法示例。
在下文中一共展示了HttpResponseStatus.INTERNAL_SERVER_ERROR属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: failure
@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();
}
}
}
示例3: serve500
private WorksResponse serve500(WorksRequest request, Exception e) {
WorksResponse response = new WorksResponse(HttpResponseStatus.INTERNAL_SERVER_ERROR);
try {
// TODO if dev show message if not dev dont show it
response.html("<h1>500</h1><br>" + e.getMessage());
} catch (Ex500 e1) {
l.error("{}", e1);
}
return response;
}
示例4: exceptionCaught
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
final Channel channel = ctx.getChannel();
if (e instanceof ClosedChannelException || channel == null || !channel.isOpen()) {
log.debug("Not writing any response, channel is already closed.", e.getCause());
return;
}
log.error("Uncaught exception during jersey resource handling", e.getCause());
final HttpRequest request = (HttpRequest) ctx.getAttachment();
final HttpVersion protocolVersion;
if (request != null && request.getProtocolVersion() != null) {
protocolVersion = request.getProtocolVersion();
} else {
protocolVersion = HttpVersion.HTTP_1_0;
}
final DefaultHttpResponse response = new DefaultHttpResponse(protocolVersion, HttpResponseStatus.INTERNAL_SERVER_ERROR);
final ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
new ChannelBufferOutputStream(buffer).writeBytes(e.toString());
response.setContent(buffer);
final ChannelFuture channelFuture = channel.write(response);
if ((protocolVersion == HttpVersion.HTTP_1_0)
|| request == null
|| HttpHeaders.getHeader(request, HttpHeaders.Names.CONNECTION).equalsIgnoreCase("close")) {
channelFuture.addListener(ChannelFutureListener.CLOSE);
}
}
示例5: exceptionCaught
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
logger.error("Exception caugth in channel", e.getCause());
response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
e.getChannel().close();
}