Example usage for io.netty.handler.codec.http HttpStatusClass SUCCESS

List of usage examples for io.netty.handler.codec.http HttpStatusClass SUCCESS

Introduction

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

Prototype

HttpStatusClass SUCCESS

To view the source code for io.netty.handler.codec.http HttpStatusClass SUCCESS.

Click Source Link

Document

The success class (2xx)

Usage

From source file:com.linecorp.armeria.server.ServerTest.java

License:Apache License

@Test
public void testRequestTimeoutInvocation() throws Exception {
    try (CloseableHttpClient hc = HttpClients.createMinimal()) {
        final HttpPost req = new HttpPost(uri("/timeout"));
        req.setEntity(new StringEntity("Hello, world!", StandardCharsets.UTF_8));

        try (CloseableHttpResponse res = hc.execute(req)) {
            assertThat(HttpStatusClass.valueOf(res.getStatusLine().getStatusCode()),
                    is(not(HttpStatusClass.SUCCESS)));
        }//from ww w  .  j av a 2  s.  co  m
    }
}

From source file:com.linecorp.armeria.server.ServerTest.java

License:Apache License

@Test
public void testDynamicRequestTimeoutInvocation() throws Exception {
    try (CloseableHttpClient hc = HttpClients.createMinimal()) {
        final HttpPost req = new HttpPost(uri("/timeout-not"));
        req.setEntity(new StringEntity("Hello, world!", StandardCharsets.UTF_8));

        try (CloseableHttpResponse res = hc.execute(req)) {
            assertThat(HttpStatusClass.valueOf(res.getStatusLine().getStatusCode()),
                    is(HttpStatusClass.SUCCESS));
        }/* w  w  w.  ja  v a 2s. co m*/
    }
}

From source file:org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl.java

License:Apache License

@VisibleForTesting
@SuppressWarnings("unchecked")
protected <T> Handler<RestResponse> syncHandler(CountDownLatch countDownLatch, Class<T> cls, Holder<T> holder) {
    return restResponse -> {
        RequestContext requestContext = restResponse.getRequestContext();
        HttpClientResponse response = restResponse.getResponse();
        if (response == null) {
            // ?SC
            if (requestContext.getRetryTimes() <= ipPortManager.getMaxRetryTimes()) {
                retry(requestContext, syncHandler(countDownLatch, cls, holder));
            } else {
                countDownLatch.countDown();
            }//from   w ww .j a  va2 s . com
            return;
        }
        holder.setStatusCode(response.statusCode());
        response.bodyHandler(bodyBuffer -> {
            if (cls.getName().equals(HttpClientResponse.class.getName())) {
                holder.value = (T) response;
                countDownLatch.countDown();
                return;
            }
            if (cls.equals(String.class)) {
                holder.setValue((T) bodyBuffer.toString());
                countDownLatch.countDown();
                return;
            }

            // no need to support 304 in this place
            if (!HttpStatusClass.SUCCESS.equals(HttpStatusClass.valueOf(response.statusCode()))) {
                LOGGER.warn("get response for {} failed, {}:{}, {}", cls.getName(), response.statusCode(),
                        response.statusMessage(), bodyBuffer.toString());
                countDownLatch.countDown();
                return;
            }

            try {
                holder.value = JsonUtils.readValue(bodyBuffer.getBytes(), cls);
            } catch (Exception e) {
                holder.setStatusCode(0).setThrowable(e);
                LOGGER.warn("read value failed and response message is {}", bodyBuffer.toString());
            }
            countDownLatch.countDown();
        });
    };
}