当前位置: 首页>>代码示例>>Java>>正文


Java HttpStatus类代码示例

本文整理汇总了Java中com.linecorp.armeria.common.HttpStatus的典型用法代码示例。如果您正苦于以下问题:Java HttpStatus类的具体用法?Java HttpStatus怎么用?Java HttpStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpStatus类属于com.linecorp.armeria.common包,在下文中一共展示了HttpStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createToken0

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
private CompletionStage<Token> createToken0(Revision revision, Token newToken) {
    return getTokens(revision).thenCompose(entries -> {
        final boolean exist = entries.values().stream().anyMatch(
                token -> token.appId().equals(newToken.appId()));
        if (exist) {
            // TODO(hyangtack) Would send 409 conflict when the following PR is merged.
            // https://github.com/line/armeria/pull/746
            throw HttpStatusException.of(HttpStatus.CONFLICT);
        }

        entries.put(newToken.secret(), newToken);
        final User user = AuthenticationUtil.currentUser();
        final String summary = user.name() + " generates a token: " + newToken.appId();
        return updateTokens(revision, entries, summary).thenApply(unused -> newToken);
    });
}
 
开发者ID:line,项目名称:centraldogma,代码行数:17,代码来源:TokenService.java

示例2: serve

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Override
public HttpResponse serve(Service<HttpRequest, HttpResponse> delegate,
                          ServiceRequestContext ctx,
                          HttpRequest req) throws Exception {
    final String projectName = ctx.pathParam("projectName");
    checkArgument(!isNullOrEmpty(projectName),
                  "No project name is specified");

    final Function<String, ProjectRole> map = ctx.attr(RoleResolvingDecorator.ROLE_MAP).get();
    final ProjectRole projectRole = map != null ? map.apply(projectName) : null;
    final User user = AuthenticationUtil.currentUser(ctx);
    if (!isAllowedRole(user, projectRole)) {
        throw HttpStatusException.of(HttpStatus.UNAUTHORIZED);
    }

    return delegate.serve(ctx, req);
}
 
开发者ID:line,项目名称:centraldogma,代码行数:18,代码来源:ProjectAccessController.java

示例3: convertResponse

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Override
public HttpResponse convertResponse(ServiceRequestContext ctx, Object resObj) throws Exception {
    try {
        final JsonNode jsonNode = Jackson.valueToTree(resObj);
        final String url = jsonNode.get("url").asText();

        // Remove the url field and send it with the LOCATION header.
        ((ObjectNode) jsonNode).remove("url");
        final HttpHeaders headers = HttpHeaders.of(HttpStatus.CREATED)
                                               .add(HttpHeaderNames.LOCATION, url)
                                               .contentType(MediaType.JSON_UTF_8);

        return HttpResponse.of(headers, HttpData.of(Jackson.writeValueAsBytes(jsonNode)));
    } catch (JsonProcessingException e) {
        logger.debug("Failed to convert a response:", e);
        return HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:19,代码来源:CreateApiResponseConverter.java

示例4: convertResponse

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Override
public HttpResponse convertResponse(ServiceRequestContext ctx, Object resObj) throws Exception {
    try {
        final HttpRequest request = RequestContext.current().request();
        if (HttpMethod.DELETE == request.method() ||
            (resObj instanceof Iterable && Iterables.size((Iterable) resObj) == 0)) {
            return HttpResponse.of(HttpStatus.NO_CONTENT);
        }

        final HttpData httpData = HttpData.of(Jackson.writeValueAsBytes(resObj));
        return HttpResponse.of(HttpStatus.OK, MediaType.JSON_UTF_8, httpData);
    } catch (JsonProcessingException e) {
        logger.debug("Failed to convert a response:", e);
        return HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:17,代码来源:HttpApiResponseConverter.java

示例5: handleException

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Override
public HttpResponse handleException(RequestContext ctx, HttpRequest req, Throwable cause) {

    if (cause instanceof IllegalArgumentException) {
        if (cause.getMessage() != null) {
            return newResponseWithErrorMessage(HttpStatus.BAD_REQUEST, cause.getMessage());
        }
        return HttpResponse.of(HttpStatus.BAD_REQUEST);
    }

    if (cause instanceof StorageException) {
        // Use precomputed map if the cause is instance of StorageException to access in a faster way.
        final ExceptionHandlerFunction func = storageExceptionHandlers.get(cause.getClass());
        if (func != null) {
            return func.handleException(ctx, req, cause);
        }
    }

    return ExceptionHandlerFunction.fallthrough();
}
 
开发者ID:line,项目名称:centraldogma,代码行数:21,代码来源:HttpApiExceptionHandler.java

示例6: unremoveRepository

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Test
public void unremoveRepository() {
    createRepository("foo");
    httpClient.delete(REPOS_PREFIX + "/foo").aggregate().join();
    final HttpHeaders reqHeaders = HttpHeaders.of(HttpMethod.PATCH, REPOS_PREFIX + "/foo")
                                              .add(HttpHeaderNames.CONTENT_TYPE,
                                                   "application/json-patch+json");

    final String unremovePatch = "[{\"op\":\"replace\",\"path\":\"/status\",\"value\":\"active\"}]";
    final AggregatedHttpMessage aRes = httpClient.execute(reqHeaders, unremovePatch).aggregate().join();
    final HttpHeaders headers = aRes.headers();
    assertThat(headers.status()).isEqualTo(HttpStatus.OK);
    final String expectedJson =
            '{' +
            "   \"name\": \"foo\"," +
            "   \"creator\": {" +
            "       \"name\": \"System\"," +
            "       \"email\": \"[email protected]\"" +
            "   }," +
            "   \"headRevision\": 1," +
            "   \"url\": \"/api/v1/projects/myPro/repos/foo\"," +
            "   \"createdAt\": \"${json-unit.ignore}\"" +
            '}';
    final String actualJson = aRes.content().toStringUtf8();
    assertThatJson(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:line,项目名称:centraldogma,代码行数:27,代码来源:RepositoryServiceV1Test.java

示例7: unremoveProject

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Test
public void unremoveProject() throws IOException {
    createProject("bar");
    final String projectPath = PROJECTS_PREFIX + "/bar";
    httpClient.delete(projectPath).aggregate().join();

    final HttpHeaders headers = HttpHeaders.of(HttpMethod.PATCH, projectPath)
                                           .contentType(MediaType.JSON_PATCH);

    final String unremovePatch = "[{\"op\":\"replace\",\"path\":\"/status\",\"value\":\"active\"}]";
    final AggregatedHttpMessage aRes = httpClient.execute(headers, unremovePatch).aggregate().join();
    System.err.println(aRes.content().toStringUtf8());
    assertThat(aRes.headers().status()).isEqualTo(HttpStatus.OK);
    final String expectedJson =
            '{' +
            "   \"name\": \"bar\"," +
            "   \"creator\": {" +
            "       \"name\": \"System\"," +
            "       \"email\": \"[email protected]\"" +
            "   }," +
            "   \"url\": \"/api/v1/projects/bar\"," +
            "   \"createdAt\": \"${json-unit.ignore}\"" +
            '}';
    final String actualJson = aRes.content().toStringUtf8();
    assertThatJson(actualJson).isEqualTo(expectedJson);
}
 
开发者ID:line,项目名称:centraldogma,代码行数:27,代码来源:ProjectServiceV1Test.java

示例8: deleteFile

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Test
public void deleteFile() throws IOException {
    addFooJson();
    addBarTxt();

    final String body =
            '{' +
            "   \"path\": \"/foo.json\"," +
            "   \"type\": \"REMOVE\"," +
            "   \"commitMessage\" : {" +
            "       \"summary\" : \"Delete foo.json\"" +
            "   }" +
            '}';
    final HttpHeaders headers = HttpHeaders.of(HttpMethod.POST, CONTENTS_PREFIX)
                                           .contentType(MediaType.JSON);
    final AggregatedHttpMessage res1 = httpClient.execute(headers, body).aggregate().join();
    assertThat(res1.headers().status()).isEqualTo(HttpStatus.NO_CONTENT);

    final AggregatedHttpMessage res2 = httpClient.get(CONTENTS_PREFIX + "/**").aggregate().join();
    // only /a/bar.txt file is left
    assertThat(Jackson.readTree(res2.content().toStringUtf8()).size()).isOne();
}
 
开发者ID:line,项目名称:centraldogma,代码行数:23,代码来源:ContentServiceV1Test.java

示例9: deleteFileInvalidRevision

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Test
public void deleteFileInvalidRevision() {
    addFooJson();
    addBarTxt();
    final String body =
            '{' +
            "   \"path\": \"/foo.json\"," +
            "   \"type\": \"REMOVE\"," +
            "   \"commitMessage\" : {" +
            "       \"summary\" : \"Delete foo.json\"" +
            "   }" +
            '}';
    final HttpHeaders headers = HttpHeaders.of(HttpMethod.POST, CONTENTS_PREFIX + "?revision=2")
                                           .contentType(MediaType.JSON);
    final AggregatedHttpMessage res = httpClient.execute(headers, body).aggregate().join();
    assertThat(res.headers().status()).isEqualTo(HttpStatus.CONFLICT);
}
 
开发者ID:line,项目名称:centraldogma,代码行数:18,代码来源:ContentServiceV1Test.java

示例10: testThriftServiceRegistrationBean

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Test
public void testThriftServiceRegistrationBean() throws Exception {
    HelloService.Iface client = Clients.newClient(newUrl("tbinary+h1c") + "/thrift",
                                                  HelloService.Iface.class);

    assertThat(client.hello("world")).isEqualTo("hello world");

    HttpClient httpClient = HttpClient.of(newUrl("h1c"));
    HttpResponse response = httpClient.get("/internal/docs/specification.json");

    AggregatedHttpMessage msg = response.aggregate().get();
    assertThat(msg.status()).isEqualTo(HttpStatus.OK);
    assertThatJson(msg.content().toStringUtf8()).matches(
            jsonPartMatches("services[0].exampleHttpHeaders[0].x-additional-header",
                            is("headerVal")));
}
 
开发者ID:line,项目名称:armeria,代码行数:17,代码来源:ArmeriaAutoConfigurationTest.java

示例11: statusToTrailers

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
static HttpHeaders statusToTrailers(Status status, boolean headersSent) {
    final HttpHeaders trailers;
    if (headersSent) {
        // Normal trailers.
        trailers = new DefaultHttpHeaders();
    } else {
        // Trailers only response
        trailers = new DefaultHttpHeaders(true, 3, true)
                .status(HttpStatus.OK)
                .set(HttpHeaderNames.CONTENT_TYPE, "application/grpc+proto");
    }
    trailers.add(GrpcHeaderNames.GRPC_STATUS, Integer.toString(status.getCode().value()));
    if (status.getDescription() != null) {
        trailers.add(GrpcHeaderNames.GRPC_MESSAGE,
                     StatusMessageEscaper.escape(status.getDescription()));
    }

    return trailers;
}
 
开发者ID:line,项目名称:armeria,代码行数:20,代码来源:ArmeriaServerCall.java

示例12: testStrings_acceptEncodingGzip_largeFixedContent

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Test(timeout = 10000)
public void testStrings_acceptEncodingGzip_largeFixedContent() throws Exception {
    final HttpHeaders req = HttpHeaders.of(HttpMethod.GET, "/large")
                                       .set(HttpHeaderNames.ACCEPT_ENCODING, "gzip");
    final CompletableFuture<AggregatedHttpMessage> f = client().execute(req).aggregate();

    final AggregatedHttpMessage res = f.get();

    assertThat(res.status(), is(HttpStatus.OK));
    assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING), is("gzip"));
    assertThat(res.headers().get(HttpHeaderNames.VARY), is("accept-encoding"));

    byte[] decoded;
    try (GZIPInputStream unzipper = new GZIPInputStream(new ByteArrayInputStream(res.content().array()))) {
        decoded = ByteStreams.toByteArray(unzipper);
    }
    assertThat(new String(decoded, StandardCharsets.UTF_8), is(Strings.repeat("a", 1024)));
}
 
开发者ID:line,项目名称:armeria,代码行数:19,代码来源:HttpServerTest.java

示例13: missingMethod

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Test
public void missingMethod() throws Exception {
    when(ctx.mappedPath()).thenReturn("/grpc.testing.TestService/FooCall");
    HttpResponse response = grpcService.doPost(
            ctx,
            HttpRequest.of(HttpHeaders.of(HttpMethod.POST, "/grpc.testing.TestService/FooCall")
                                      .set(HttpHeaderNames.CONTENT_TYPE, "application/grpc+proto")));
    assertThat(response.aggregate().get()).isEqualTo(AggregatedHttpMessage.of(
            HttpHeaders.of(HttpStatus.OK)
                       .set(HttpHeaderNames.CONTENT_TYPE, "application/grpc+proto")
                       .set(AsciiString.of("grpc-status"), "12")
                       .set(AsciiString.of("grpc-message"),
                            "Method not found: grpc.testing.TestService/FooCall")
                       .set(HttpHeaderNames.CONTENT_LENGTH, "0"),
            HttpData.of(new byte[] {})));
}
 
开发者ID:line,项目名称:armeria,代码行数:17,代码来源:GrpcServiceTest.java

示例14: write

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Override
public boolean write(HttpObject o) {
    if (o instanceof HttpHeaders) {
        // NB: It's safe to call logBuilder.start() multiple times.
        //     See AbstractMessageLog.start() for more information.
        logBuilder.startResponse();
        final HttpHeaders headers = (HttpHeaders) o;
        final HttpStatus status = headers.status();
        if (status != null && status.codeClass() != HttpStatusClass.INFORMATIONAL) {
            logBuilder.responseHeaders(headers);
        }
    } else if (o instanceof HttpData) {
        logBuilder.increaseResponseLength(((HttpData) o).length());
    }
    return delegate.write(o);
}
 
开发者ID:line,项目名称:armeria,代码行数:17,代码来源:HttpResponseDecoder.java

示例15: testHeaders

import com.linecorp.armeria.common.HttpStatus; //导入依赖的package包/类
@Test(timeout = 10000)
public void testHeaders() throws Exception {
    final HttpHeaders req = HttpHeaders.of(HttpMethod.GET, "/headers");
    final CompletableFuture<AggregatedHttpMessage> f = client().execute(req).aggregate();

    final AggregatedHttpMessage res = f.get();

    assertThat(res.status(), is(HttpStatus.OK));

    // Verify all header names are in lowercase
    for (AsciiString headerName : res.headers().names()) {
        headerName.chars().filter(Character::isAlphabetic)
                  .forEach(c -> assertTrue(Character.isLowerCase(c)));
    }

    assertThat(res.headers().get(AsciiString.of("x-custom-header1")), is("custom1"));
    assertThat(res.headers().get(AsciiString.of("x-custom-header2")), is("custom2"));
    assertThat(res.content().toStringUtf8(), is("headers"));
}
 
开发者ID:line,项目名称:armeria,代码行数:20,代码来源:HttpServerTest.java


注:本文中的com.linecorp.armeria.common.HttpStatus类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。