use of io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR in project servicetalk by apple.
the class HttpSerializerErrorTest method serializationMapThrowsPropagatesToClient.
@ParameterizedTest
@MethodSource("executors")
void serializationMapThrowsPropagatesToClient(HttpTestExecutionStrategy serverStrategy) throws Exception {
serverExecutionStrategy = serverStrategy.executorSupplier.get();
TypeReference<Map<String, Object>> mapType = new TypeReference<Map<String, Object>>() {
};
HttpStreamingSerializerDeserializer<Map<String, Object>> streamingSerializer = jsonStreamingSerializer(JACKSON.streamingSerializerDeserializer(mapType));
HttpSerializerDeserializer<Map<String, Object>> serializer = HttpSerializers.jsonSerializer(JACKSON.serializerDeserializer(mapType));
try (ServerContext srv = HttpServers.forAddress(localAddress(0)).executionStrategy(serverExecutionStrategy).listenAndAwait((ctx, request, responseFactory) -> responseFactory.ok().toStreamingResponse().payloadBody(request.toStreamingRequest().payloadBody(streamingSerializer).map(result -> {
throw DELIBERATE_EXCEPTION;
}), streamingSerializer).toResponse());
BlockingHttpClient clt = HttpClients.forSingleAddress(serverHostAndPort(srv)).buildBlocking()) {
HttpResponse resp = clt.request(clt.post("/foo").payloadBody(emptyMap(), serializer));
assertEquals(INTERNAL_SERVER_ERROR, resp.status());
}
}
use of io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR in project servicetalk by apple.
the class HttpSerializationErrorTest method serializationMapThrowsPropagatesToClient.
@ParameterizedTest
@MethodSource("executors")
void serializationMapThrowsPropagatesToClient(HttpTestExecutionStrategy serverStrategy) throws Exception {
serverExecutionStrategy = serverStrategy.executorSupplier.get();
TypeReference<Map<String, Object>> mapType = new TypeReference<Map<String, Object>>() {
};
HttpSerializerDeserializer<Map<String, Object>> httpSerializer = jsonSerializer(JACKSON.serializerDeserializer(mapType));
HttpStreamingSerializerDeserializer<Map<String, Object>> httpStreamingSerializer = jsonStreamingSerializer(JACKSON.streamingSerializerDeserializer(mapType));
try (ServerContext srv = HttpServers.forAddress(localAddress(0)).executionStrategy(serverExecutionStrategy).listenAndAwait((ctx, request, responseFactory) -> responseFactory.ok().toStreamingResponse().payloadBody(request.toStreamingRequest().payloadBody(httpStreamingSerializer).map(result -> {
throw DELIBERATE_EXCEPTION;
}), httpStreamingSerializer).toResponse());
BlockingHttpClient clt = HttpClients.forSingleAddress(serverHostAndPort(srv)).buildBlocking()) {
HttpResponse resp = clt.request(clt.post("/foo").payloadBody(emptyMap(), httpSerializer));
assertEquals(INTERNAL_SERVER_ERROR, resp.status());
}
}
use of io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR in project servicetalk by apple.
the class TracingHttpServiceFilterTest method tracerThrowsReturnsErrorResponse.
@Test
void tracerThrowsReturnsErrorResponse() throws Exception {
when(mockTracer.buildSpan(any())).thenThrow(DELIBERATE_EXCEPTION);
try (ServerContext context = HttpServers.forAddress(localAddress(0)).appendServiceFilter(new TracingHttpServiceFilter(mockTracer, "testServer")).listenStreamingAndAwait(((ctx, request, responseFactory) -> succeeded(responseFactory.forbidden())))) {
try (HttpClient client = forSingleAddress(serverHostAndPort(context)).build()) {
HttpRequest request = client.get("/");
HttpResponse response = client.request(request).toFuture().get();
assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
}
}
}
Aggregations