List of usage examples for io.netty.util AsciiString of
public static AsciiString of(CharSequence string)
From source file:com.linecorp.armeria.server.grpc.GrpcDocServicePluginTest.java
License:Apache License
@Test public void services() throws Exception { ServiceConfig testService = new ServiceConfig(new VirtualHostBuilder().build(), PathMapping.ofPrefix("/test"), new GrpcServiceBuilder().addService(mock(TestServiceImplBase.class)).build()); HttpHeaders testExampleHeaders = HttpHeaders.of(AsciiString.of("test"), "service"); ServiceConfig reconnectService = new ServiceConfig(new VirtualHostBuilder().build(), PathMapping.ofPrefix("/reconnect"), new GrpcServiceBuilder().addService(mock(ReconnectServiceImplBase.class)).build()); HttpHeaders reconnectExampleHeaders = HttpHeaders.of(AsciiString.of("reconnect"), "never"); ServiceSpecification specification = generator .generateSpecification(ImmutableSet.of(testService, reconnectService)); Map<String, ServiceInfo> services = specification.services().stream() .collect(toImmutableMap(ServiceInfo::name, Function.identity())); assertThat(services).containsOnlyKeys(TestServiceGrpc.SERVICE_NAME, ReconnectServiceGrpc.SERVICE_NAME); }
From source file:com.linecorp.armeria.server.grpc.GrpcServiceServerTest.java
License:Apache License
@BeforeClass public static void createLargePayload() { LARGE_PAYLOAD = AsciiString.of(Strings.repeat("a", MAX_MESSAGE_SIZE + 1)); }
From source file:com.linecorp.armeria.server.grpc.GrpcServiceTest.java
License:Apache License
@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(/*from w w w . jav a 2 s. com*/ 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[] {}))); }
From source file:com.linecorp.armeria.server.healthcheck.ManagedHttpHealthCheckServiceTest.java
License:Apache License
@Test public void turnOff() throws Exception { service.serverHealth.setHealthy(true); AggregatedHttpMessage res = service.serve(context, hcTurnOffReq).aggregate().get(); assertThat(res.status()).isEqualTo(HttpStatus.OK); assertThat(res.headers().get(AsciiString.of(HttpHeaders.CONTENT_TYPE))) .isEqualTo(MediaType.PLAIN_TEXT_UTF_8.toString()); assertThat(res.content().toStringUtf8()).isEqualTo("Set unhealthy."); res = service.serve(context, hcReq).aggregate().get(); assertThat(res.status()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE); assertThat(res.headers().get(AsciiString.of(HttpHeaders.CONTENT_TYPE))) .isEqualTo(MediaType.PLAIN_TEXT_UTF_8.toString()); }
From source file:com.linecorp.armeria.server.healthcheck.ManagedHttpHealthCheckServiceTest.java
License:Apache License
@Test public void turnOn() throws Exception { AggregatedHttpMessage res = service.serve(context, hcTurnOnReq).aggregate().get(); assertThat(res.status()).isEqualTo(HttpStatus.OK); assertThat(res.headers().get(AsciiString.of(HttpHeaders.CONTENT_TYPE))) .isEqualTo(MediaType.PLAIN_TEXT_UTF_8.toString()); assertThat(res.content().toStringUtf8()).isEqualTo("Set healthy."); res = service.serve(context, hcReq).aggregate().get(); assertThat(res.status()).isEqualTo(HttpStatus.OK); assertThat(res.headers().get(AsciiString.of(HttpHeaders.CONTENT_TYPE))) .isEqualTo(MediaType.PLAIN_TEXT_UTF_8.toString()); }
From source file:com.linecorp.armeria.server.healthcheck.ManagedHttpHealthCheckServiceTest.java
License:Apache License
@Test public void notSupported() throws Exception { HttpRequestWriter noopRequest = HttpRequest.streaming(HttpMethod.PUT, "/"); noopRequest.write(() -> HttpData.ofAscii("noop")); noopRequest.close();/*from ww w .j av a 2 s . c om*/ AggregatedHttpMessage res = service.serve(context, noopRequest).aggregate().get(); assertThat(res.status()).isEqualTo(HttpStatus.BAD_REQUEST); assertThat(res.headers().get(AsciiString.of(HttpHeaders.CONTENT_TYPE))) .isEqualTo(MediaType.PLAIN_TEXT_UTF_8.toString()); assertThat(res.content().toStringUtf8()).isEqualTo("Not supported."); service.serverHealth.setHealthy(true); noopRequest = HttpRequest.streaming(HttpMethod.PUT, "/"); noopRequest.write(() -> HttpData.ofAscii("noop")); noopRequest.close(); res = service.serve(context, noopRequest).aggregate().get(); assertThat(res.status()).isEqualTo(HttpStatus.BAD_REQUEST); assertThat(res.headers().get(AsciiString.of(HttpHeaders.CONTENT_TYPE))) .isEqualTo(MediaType.PLAIN_TEXT_UTF_8.toString()); assertThat(res.content().toStringUtf8()).isEqualTo("Not supported."); }
From source file:com.linecorp.armeria.server.http.HttpServerCorsTest.java
License:Apache License
@Test public void testCorsPreflight() throws Exception { HttpClient client = Clients.newClient(clientFactory, "none+" + uri("/"), HttpClient.class); AggregatedHttpMessage response = client.execute(HttpHeaders.of(HttpMethod.OPTIONS, "/cors") .set(HttpHeaderNames.ACCEPT, "utf-8").set(HttpHeaderNames.ORIGIN, "http://example.com") .set(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD, "POST")).aggregate().get(); assertEquals(HttpStatus.OK, response.status()); assertEquals("http://example.com", response.headers().get(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN)); assertEquals("Hello CORS", response.headers().get(AsciiString.of("x-preflight-cors"))); }
From source file:com.linecorp.armeria.server.HttpServerTest.java
License:Apache License
@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()).isEqualTo(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))); }/*from w ww . j a v a2s . c om*/ assertThat(res.headers().get(AsciiString.of("x-custom-header1"))).isEqualTo("custom1"); assertThat(res.headers().get(AsciiString.of("x-custom-header2"))).isEqualTo("custom2"); assertThat(res.content().toStringUtf8()).isEqualTo("headers"); }
From source file:com.linecorp.armeria.server.HttpServerTest.java
License:Apache License
@Test(timeout = 10000) public void testTrailers() throws Exception { final HttpHeaders req = HttpHeaders.of(HttpMethod.GET, "/trailers"); final CompletableFuture<AggregatedHttpMessage> f = client().execute(req).aggregate(); final AggregatedHttpMessage res = f.get(); assertThat(res.trailingHeaders().get(AsciiString.of("foo"))).isEqualTo("bar"); }
From source file:com.linecorp.armeria.server.logging.AccessLogFormats.java
License:Apache License
private static AccessLogComponent newAccessLogComponent(char token, @Nullable String variable, @Nullable Condition.Builder condBuilder) { final AccessLogType type = AccessLogType.find(token) .orElseThrow(() -> new IllegalArgumentException("Unexpected token character: '" + token + '\'')); if (type.isVariableRequired()) { checkArgument(variable != null, "Token " + type.token() + " requires a variable."); }//from w w w. j a v a 2 s . co m if (type.isConditionAvailable()) { if (condBuilder != null) { checkArgument(!condBuilder.isEmpty(), "Token " + type.token() + " has an invalid condition."); } } else { checkArgument(condBuilder == null, "Token " + type.token() + " does not support a condition."); } if (TextComponent.isSupported(type)) { assert variable != null; return ofText(variable); } // Do not add quotes when parsing a user-provided custom format. final boolean addQuote = false; final Function<HttpHeaders, Boolean> condition = condBuilder != null ? condBuilder.build() : null; if (CommonComponent.isSupported(type)) { return new CommonComponent(type, addQuote, condition); } if (RequestHeaderComponent.isSupported(type)) { assert variable != null; return new RequestHeaderComponent(AsciiString.of(variable), addQuote, condition); } if (AttributeComponent.isSupported(type)) { assert variable != null; final Function<Object, String> stringifier; final String[] components = variable.split(":"); if (components.length == 2) { stringifier = newStringifier(components[0], components[1]); } else { stringifier = Object::toString; } return new AttributeComponent(components[0], stringifier, addQuote, condition); } // Should not reach here. throw new Error("Unexpected access log type: " + type.name()); }