use of io.servicetalk.http.api.HttpHeaderValues.APPLICATION_JSON in project servicetalk by apple.
the class HttpReporter method encodedSpansReporter.
private static Function<Buffer, Completable> encodedSpansReporter(final HttpClient client, final Codec codec) {
final String path;
final CharSequence contentType;
switch(codec) {
case JSON_V1:
path = V1_PATH;
contentType = APPLICATION_JSON;
break;
case JSON_V2:
path = V2_PATH;
contentType = APPLICATION_JSON;
break;
case THRIFT:
path = V2_PATH;
contentType = THRIFT_CONTENT_TYPE;
break;
case PROTO3:
path = V2_PATH;
contentType = PROTO_CONTENT_TYPE;
break;
default:
throw new IllegalArgumentException("Unknown codec: " + codec);
}
return encodedSpans -> client.request(client.post(path).setHeader(CONTENT_TYPE, contentType).payloadBody(encodedSpans)).beforeOnSuccess(response -> {
HttpResponseStatus status = response.status();
if (status.statusClass() != SUCCESSFUL_2XX) {
LOGGER.info("Unexpected response from the collector. Response headers: {}", response.toString((__, headerValue) -> headerValue));
}
}).ignoreElement().onErrorComplete(cause -> {
LOGGER.error("Failed to send a span, ignoring.", cause);
return true;
});
}
use of io.servicetalk.http.api.HttpHeaderValues.APPLICATION_JSON in project servicetalk by apple.
the class HeaderUtilsTest method checkContentTypeCases.
@Test
void checkContentTypeCases() {
final String invalidContentType = "invalid";
final Predicate<HttpHeaders> jsonContentTypeValidator = headers -> headers.contains(CONTENT_TYPE, APPLICATION_JSON);
checkContentType(headersWithContentType(APPLICATION_JSON), jsonContentTypeValidator);
SerializationException e = assertThrows(SerializationException.class, () -> checkContentType(headersWithContentType(of(invalidContentType)), jsonContentTypeValidator));
assertThat(e.getMessage(), containsString(invalidContentType));
}
Aggregations