當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpResponseStatus.INTERNAL_SERVER_ERROR屬性代碼示例

本文整理匯總了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);
  }
}
 
開發者ID:yandex,項目名稱:opentsdb-flume,代碼行數:24,代碼來源:LegacyHttpSource.java

示例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();
        }
    }
}
 
開發者ID:graylog-labs,項目名稱:jersey-netty,代碼行數:16,代碼來源:NettyContainer.java

示例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;
}
 
開發者ID:mirasworks,項目名稱:works,代碼行數:10,代碼來源:Dispatcher.java

示例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);
    }
}
 
開發者ID:graylog-labs,項目名稱:jersey-netty,代碼行數:29,代碼來源:NettyContainer.java

示例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();
}
 
開發者ID:yandex,項目名稱:opentsdb-flume,代碼行數:6,代碼來源:LegacyHttpSource.java


注:本文中的org.jboss.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。