当前位置: 首页>>代码示例>>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;未经允许,请勿转载。