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

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

Introduction

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

Prototype

public static HttpStatusClass valueOf(CharSequence code) 

Source Link

Document

Returns the class of the specified HTTP status code.

Usage

From source file:com.ibasco.agql.core.AbstractWebResponse.java

License:Open Source License

public HttpStatusClass getStatus() {
    return HttpStatusClass.valueOf(this.response.getStatusCode());
}

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 www .  ja  v a2  s  .  c om*/
    }
}

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  2 s  .  com
    }
}

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();
            }//w ww  . j  a  va2 s.  c o  m
            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();
        });
    };
}