use of org.apache.tapestry5.http.ContentType in project httpcomponents-jackson by ok2c.
the class JsonStreamConsumer method consumeMessage.
final void consumeMessage(H messageHead, EntityDetails entityDetails, FutureCallback<T> resultCallback) throws HttpException, IOException {
if (messageConsumer != null) {
messageConsumer.accept(messageHead);
}
if (entityDetails == null) {
if (resultCallback != null) {
resultCallback.completed(null);
}
return;
}
ContentType contentType = ContentType.parseLenient(entityDetails.getContentType());
if (ContentType.APPLICATION_JSON.isSameMimeType(contentType)) {
AsyncEntityConsumer<T> entityConsumer = entityConsumerSupplier.get();
entityConsumerRef.set(entityConsumer);
} else {
entityConsumerRef.set(new NoopJsonEntityConsumer<>());
}
entityConsumerRef.get().streamStart(entityDetails, resultCallback);
}
use of org.apache.tapestry5.http.ContentType in project httpcomponents-jackson by ok2c.
the class JsonRequestObjectConsumer method createEntityConsumer.
@Override
protected AsyncEntityConsumer<T> createEntityConsumer(HttpRequest request, EntityDetails entityDetails) {
ContentType contentType = ContentType.parseLenient(entityDetails.getContentType());
AsyncEntityConsumer<T> entityConsumer;
if (ContentType.APPLICATION_JSON.isSameMimeType(contentType)) {
entityConsumer = consumerSupplier.get();
} else {
entityConsumer = new NoopJsonEntityConsumer<>();
}
return entityConsumer;
}
use of org.apache.tapestry5.http.ContentType in project Artemis by mbizhani.
the class HttpRequest method send.
public void send(Consumer<HttpResponse> responseConsumer) {
ALog.info("RQ: {} - {}{}", request.getMethod(), getUri(), builder.toString());
final HttpClientContext context = HttpClientContext.create();
final long start = System.currentTimeMillis();
try (final CloseableHttpResponse rs = httpClient.execute(request, context)) {
final long duration = System.currentTimeMillis() - start;
final int code = rs.getCode();
final String contentType = rs.getEntity().getContentType();
final String body = getBody(rs);
final String cookiesPart;
final Map<String, String> cookiesMap;
if (context.getCookieStore().getCookies().size() > 0) {
final String cookies = context.getCookieStore().getCookies().stream().map(cookie -> String.format("%s=%s", cookie.getName(), cookie.getValue())).collect(Collectors.joining(","));
cookiesPart = String.format("\n\tCookies: %s", cookies);
cookiesMap = context.getCookieStore().getCookies().stream().collect(Collectors.toMap(Cookie::getName, Cookie::getValue));
} else {
cookiesMap = Collections.emptyMap();
cookiesPart = "";
}
ContextHandler.get().setCookies(cookiesMap);
if (!body.isEmpty()) {
ALog.info("RS: {} ({}) - {} [{} ms]\n\tContentType: {}{}\n\t{}", request.getMethod(), code, request.getRequestUri(), duration, contentType, cookiesPart, body);
} else {
ALog.info("RS: {} ({}) - {} [{} ms]\n\t{} - (EMPTY BODY){}", request.getMethod(), code, request.getRequestUri(), duration, contentType != null && !contentType.trim().isEmpty() ? "ContentType: " + contentType : "(No ContentType)", cookiesPart);
}
StatisticsContext.add(rqGlobalId, request.getMethod(), request.getRequestUri(), code, duration);
responseConsumer.accept(new HttpResponse(code, contentType, body, cookiesMap));
} catch (HttpHostConnectException e) {
throw new TestFailedException(rqId, String.format("Unknown Host (%s)", getUri()));
} catch (IOException e) {
throw new TestFailedException(rqId, String.format("%s (%s)", e.getMessage(), getUri()));
}
}
Aggregations