use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus in project cdap by caskdata.
the class NettyRouterPipelineTest method testHttpPipelining.
@Test
public void testHttpPipelining() throws Exception {
final BlockingQueue<HttpResponseStatus> responseStatuses = new LinkedBlockingQueue<>();
EventLoopGroup eventGroup = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap().channel(NioSocketChannel.class).group(eventGroup).handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("codec", new HttpClientCodec());
pipeline.addLast("aggregator", new HttpObjectAggregator(1048576));
pipeline.addLast("handler", new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof HttpResponse) {
responseStatuses.add(((HttpResponse) msg).status());
}
ReferenceCountUtil.release(msg);
}
});
}
});
// Create a connection and make five consecutive HTTP call without waiting for the first to respond
Channel channel = bootstrap.connect(HOSTNAME, ROUTER.getServiceMap().get(GATEWAY_NAME)).sync().channel();
for (int i = 0; i < 5; i++) {
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/v1/sleep?sleepMillis=3000");
request.headers().set(HttpHeaderNames.HOST, HOSTNAME);
channel.writeAndFlush(request);
}
// Should get the first response as normal one
HttpResponseStatus status = responseStatuses.poll(5, TimeUnit.SECONDS);
Assert.assertEquals(HttpResponseStatus.OK, status);
// The rest four should be failure responses
for (int i = 0; i < 4; i++) {
Assert.assertEquals(HttpResponseStatus.NOT_IMPLEMENTED, responseStatuses.poll(1, TimeUnit.SECONDS));
}
eventGroup.shutdownGracefully();
channel.close();
Assert.assertTrue(responseStatuses.isEmpty());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus in project knotx by Cognifide.
the class ResponseProviderKnotProxyImpl method processError.
@Override
protected KnotContext processError(KnotContext knotContext, Throwable error) {
HttpResponseStatus statusCode;
if (error instanceof NoSuchElementException) {
statusCode = HttpResponseStatus.NOT_FOUND;
} else {
statusCode = HttpResponseStatus.INTERNAL_SERVER_ERROR;
}
knotContext.getClientResponse().setStatusCode(statusCode.code());
return knotContext;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus in project knotx by Cognifide.
the class FragmentSplitterKnotProxyImpl method processError.
@Override
protected KnotContext processError(KnotContext knotContext, Throwable error) {
HttpResponseStatus statusCode;
if (error instanceof NoSuchElementException) {
statusCode = HttpResponseStatus.NOT_FOUND;
} else {
statusCode = HttpResponseStatus.INTERNAL_SERVER_ERROR;
}
knotContext.getClientResponse().setStatusCode(statusCode.code());
return knotContext;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus in project xipki by xipki.
the class HealthCheckServlet method service0.
private FullHttpResponse service0(FullHttpRequest request, ServletURI servletUri, SSLSession sslSession) {
HttpVersion version = request.protocolVersion();
HttpMethod method = request.method();
if (method != HttpMethod.GET) {
return createErrorResponse(version, HttpResponseStatus.METHOD_NOT_ALLOWED);
}
try {
if (server == null) {
LOG.error("server in servlet not configured");
return createErrorResponse(version, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
ResponderAndPath responderAndPath = server.getResponderForPath(servletUri.getPath());
if (responderAndPath == null) {
return createErrorResponse(version, HttpResponseStatus.NOT_FOUND);
}
HealthCheckResult healthResult = server.healthCheck(responderAndPath.getResponder());
HttpResponseStatus status = healthResult.isHealthy() ? HttpResponseStatus.OK : HttpResponseStatus.INTERNAL_SERVER_ERROR;
byte[] respBytes = healthResult.toJsonMessage(true).getBytes();
return createResponse(version, status, HealthCheckServlet.CT_RESPONSE, respBytes);
} catch (Throwable th) {
if (th instanceof EOFException) {
LogUtil.warn(LOG, th, "connection reset by peer");
} else {
LOG.error("Throwable thrown, this should not happen", th);
}
return createErrorResponse(version, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus in project reactor-netty by reactor.
the class HttpServerTests method doTestIssue309.
private void doTestIssue309(String path, Consumer<? super HttpServerOptions.Builder> ops) {
NettyContext server = HttpServer.create(ops).newHandler((req, res) -> res.sendString(Mono.just("Should not be reached"))).block();
Mono<HttpResponseStatus> status = HttpClient.create(server.address().getPort()).get(path, req -> req.failOnClientError(false)).flatMap(res -> {
res.dispose();
HttpResponseStatus code = res.status();
return Mono.just(code);
});
StepVerifier.create(status).expectNextMatches(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE::equals).expectComplete().verify();
server.dispose();
}
Aggregations