Example usage for io.netty.handler.codec.http HttpResponseStatus SERVICE_UNAVAILABLE

List of usage examples for io.netty.handler.codec.http HttpResponseStatus SERVICE_UNAVAILABLE

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpResponseStatus SERVICE_UNAVAILABLE.

Prototype

HttpResponseStatus SERVICE_UNAVAILABLE

To view the source code for io.netty.handler.codec.http HttpResponseStatus SERVICE_UNAVAILABLE.

Click Source Link

Document

503 Service Unavailable

Usage

From source file:be.ordina.msdashboard.aggregators.index.IndexesAggregatorTest.java

License:Apache License

@Test
@SuppressWarnings("unchecked")
public void failedIndexCallShouldReturnZeroNodes() throws InterruptedException {
    when(discoveryClient.getServices()).thenReturn(Collections.singletonList("service"));
    ServiceInstance instance = Mockito.mock(ServiceInstance.class);
    when(discoveryClient.getInstances("service")).thenReturn(Collections.singletonList(instance));

    when(instance.getServiceId()).thenReturn("service");
    when(instance.getUri()).thenReturn(URI.create("http://localhost:8089/service"));

    HttpClientResponse<ByteBuf> response = Mockito.mock(HttpClientResponse.class);
    when(RxNetty.createHttpGet("http://localhost:8089/service")).thenReturn(Observable.just(response));

    when(response.getStatus()).thenReturn(HttpResponseStatus.SERVICE_UNAVAILABLE);
    when(response.getHeaders()).thenReturn(mock(HttpResponseHeaders.class));
    when(response.getCookies()).thenReturn(Collections.emptyMap());

    TestSubscriber<Node> testSubscriber = new TestSubscriber<>();
    indexesAggregator.aggregateNodes().toBlocking().subscribe(testSubscriber);

    List<Node> nodes = testSubscriber.getOnNextEvents();
    assertThat(nodes).hasSize(0);/*w ww . j  a va  2  s.  c  o m*/
}

From source file:cn.wantedonline.puppy.exception.ProcessTimeoutError.java

License:Apache License

@Override
public HttpResponseStatus getStatus() {
    return HttpResponseStatus.SERVICE_UNAVAILABLE;
}

From source file:com.barchart.netty.server.http.error.ServerTooBusyException.java

License:BSD License

public ServerTooBusyException() {
    super(HttpResponseStatus.SERVICE_UNAVAILABLE);
}

From source file:com.barchart.netty.server.http.error.ServerTooBusyException.java

License:BSD License

public ServerTooBusyException(final String message) {
    super(HttpResponseStatus.SERVICE_UNAVAILABLE, message);
}

From source file:com.barchart.netty.server.http.error.ServerTooBusyException.java

License:BSD License

public ServerTooBusyException(final String message, final Throwable cause) {
    super(HttpResponseStatus.SERVICE_UNAVAILABLE, message, cause);
}

From source file:com.barchart.netty.server.http.error.ServerTooBusyException.java

License:BSD License

public ServerTooBusyException(final Throwable cause) {
    super(HttpResponseStatus.SERVICE_UNAVAILABLE, cause);
}

From source file:com.bloom.zerofs.rest.HealthCheckHandler.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext ctx, Object obj) throws Exception {
    logger.trace("Reading on channel {}", ctx.channel());
    boolean forwardObj = false;
    if (obj instanceof HttpRequest) {
        if (request == null && ((HttpRequest) obj).getUri().equals(healthCheckUri)) {
            nettyMetrics.healthCheckRequestRate.mark();
            startTimeInMs = System.currentTimeMillis();
            logger.trace("Handling health check request while in state " + restServerState.isServiceUp());
            request = (HttpRequest) obj;
            if (restServerState.isServiceUp()) {
                response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK,
                        Unpooled.wrappedBuffer(GOOD));
                HttpHeaders.setKeepAlive(response, HttpHeaders.isKeepAlive(request));
                HttpHeaders.setContentLength(response, GOOD.length);
            } else {
                response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
                        HttpResponseStatus.SERVICE_UNAVAILABLE, Unpooled.wrappedBuffer(BAD));
                HttpHeaders.setKeepAlive(response, false);
                HttpHeaders.setContentLength(response, BAD.length);
            }/*ww w  . j a v a  2s  .  co m*/
            nettyMetrics.healthCheckRequestProcessingTimeInMs
                    .update(System.currentTimeMillis() - startTimeInMs);
        } else {
            // Rest server could be down even if not for health check request. We intentionally don't take any action in this
            // handler for such cases and leave it to the downstream handlers to handle it
            forwardObj = true;
        }
    }
    if (obj instanceof LastHttpContent) {
        if (response != null) {
            // response was created when we received the request with health check uri
            ChannelFuture future = ctx.writeAndFlush(response);
            if (!HttpHeaders.isKeepAlive(response)) {
                future.addListener(ChannelFutureListener.CLOSE);
            }
            request = null;
            response = null;
            nettyMetrics.healthCheckRequestRoundTripTimeInMs.update(System.currentTimeMillis() - startTimeInMs);
        } else {
            // request was not for health check uri
            forwardObj = true;
        }
    } else if (request == null) {
        // http Content which is not LastHttpContent is not intended for this handler
        forwardObj = true;
    }
    if (forwardObj) {
        super.channelRead(ctx, obj);
    } else {
        ReferenceCountUtil.release(obj);
    }
}

From source file:com.ebay.jetstream.http.netty.server.HttpServer.java

License:MIT License

public void processHttpRequest(HttpRequest request, Channel channel) throws Exception {

    String path = URI.create(request.getUri()).getPath();

    ServletHolder sh = null;/*from  w w w.  j av a2  s. com*/

    if (path == null) {
        invalidCounter.increment();
        new HttpErrorRequest(request, channel, HttpResponseStatus.INTERNAL_SERVER_ERROR).run();
        return;
    }

    sh = m_servlets.get(path);

    if (sh == null) {
        String p = path;

        while (p.lastIndexOf("/") > 0) {
            p = p.substring(0, p.lastIndexOf('/'));
            sh = m_servlets.get(p);
            if (sh != null) {
                break;
            }
        }
    }

    if (sh == null) {
        notFoundCounter.increment();
        new HttpErrorRequest(request, channel, HttpResponseStatus.NOT_FOUND).run();
        return;
    }

    HttpServlet servlet = (HttpServlet) sh.getServlet();

    if (servlet != null) {
        if (!processor.processRequest(new HttpWorkRequest(request, channel, servlet, m_serverConfig))) {
            tooBusyCounter.increment();
            new HttpErrorRequest(request, channel, HttpResponseStatus.SERVICE_UNAVAILABLE).run();
        }
    } else {
        notFoundCounter.increment();
        new HttpErrorRequest(request, channel, HttpResponseStatus.NOT_FOUND).run();
    }

}

From source file:com.github.ambry.rest.HealthCheckHandlerTest.java

License:Open Source License

/**
 * Does a test to see that a health check request results in expected response from the health check handler
 * @param httpMethod the {@link HttpMethod} for the request.
 * @param keepAlive true if keep alive has to be set in the request, false otherwise
 * @throws IOException/*from   w ww  .ja  v  a  2s .  c o m*/
 */
private void testHealthCheckRequest(HttpMethod httpMethod, boolean isServiceUp, boolean keepAlive)
        throws IOException {
    EmbeddedChannel channel = createChannel();
    for (int i = 0; i < 2; i++) {
        if (isServiceUp) {
            restServerState.markServiceUp();
        }
        HttpRequest request = RestTestUtils.createRequest(httpMethod, healthCheckUri, null);
        HttpHeaders.setKeepAlive(request, keepAlive);
        FullHttpResponse response = sendRequestAndGetResponse(channel, request);
        HttpResponseStatus httpResponseStatus = (isServiceUp) ? HttpResponseStatus.OK
                : HttpResponseStatus.SERVICE_UNAVAILABLE;
        assertEquals("Unexpected response status", httpResponseStatus, response.getStatus());
        String expectedStr = (isServiceUp) ? goodStr : badStr;
        assertEquals("Unexpected content", expectedStr, RestTestUtils.getContentString(response));
        restServerState.markServiceDown();
        if (keepAlive && isServiceUp) {
            Assert.assertTrue("Channel should not be closed ", channel.isOpen());
        } else {
            Assert.assertFalse("Channel should have been closed by now ", channel.isOpen());
            channel = createChannel();
        }
    }
    channel.close();
}

From source file:com.groupon.vertx.utils.HealthcheckHandler.java

License:Apache License

protected void processHeartBeatResponse(Boolean exists, HttpServerRequest request, long startTime) {
    HttpResponseStatus status;//from  w ww  . ja  v a  2s.  co  m
    final boolean includeBody = !request.method().equals(HttpMethod.HEAD);

    if (exists) {
        status = HttpResponseStatus.OK;
    } else {
        status = HttpResponseStatus.SERVICE_UNAVAILABLE;
    }

    setCommonHttpResponse(request, status);

    String responseBody = status.reasonPhrase();
    if (includeBody) {
        request.response().end(responseBody);
    } else {
        request.response().putHeader(HttpHeaderNames.CONTENT_LENGTH, Integer.toString(responseBody.length()));
        request.response().end();
    }

    long totalTime = System.currentTimeMillis() - startTime;
    LOG.debug("handle", "healthcheckResponse", new String[] { "method", "status", "totalTime" },
            request.method(), status.code(), totalTime);
}