本文整理匯總了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();
}