use of org.apache.tapestry5.http.ContentType in project mercury by yellow013.
the class AsyncClientHttpExchangeStreaming method main.
public static void main(final String[] args) throws Exception {
final IOReactorConfig ioReactorConfig = IOReactorConfig.custom().setSoTimeout(Timeout.ofSeconds(5)).build();
final CloseableHttpAsyncClient client = HttpAsyncClients.custom().setIOReactorConfig(ioReactorConfig).build();
client.start();
final HttpHost target = new HttpHost("httpbin.org");
final String[] requestUris = new String[] { "/", "/ip", "/user-agent", "/headers" };
for (final String requestUri : requestUris) {
final BasicHttpRequest request = BasicRequestBuilder.get().setHttpHost(target).setPath(requestUri).build();
System.out.println("Executing request " + request);
final Future<Void> future = client.execute(new BasicRequestProducer(request, null), new AbstractCharResponseConsumer<Void>() {
@Override
protected void start(final HttpResponse response, final ContentType contentType) throws HttpException, IOException {
System.out.println(request + "->" + new StatusLine(response));
}
@Override
protected int capacityIncrement() {
return Integer.MAX_VALUE;
}
@Override
protected void data(final CharBuffer data, final boolean endOfStream) throws IOException {
while (data.hasRemaining()) {
System.out.print(data.get());
}
if (endOfStream) {
System.out.println();
}
}
@Override
protected Void buildResult() throws IOException {
return null;
}
@Override
public void failed(final Exception cause) {
System.out.println(request + "->" + cause);
}
@Override
public void releaseResources() {
}
}, null);
future.get();
}
System.out.println("Shutting down");
client.close(CloseMode.GRACEFUL);
}
use of org.apache.tapestry5.http.ContentType in project httpcomponents-jackson by ok2c.
the class JsonResponseObjectConsumer method createEntityConsumer.
@Override
protected AsyncEntityConsumer<T> createEntityConsumer(HttpResponse response, EntityDetails entityDetails) {
ContentType contentType = ContentType.parseLenient(entityDetails.getContentType());
AsyncEntityConsumer<T> entityConsumer;
if (ContentType.APPLICATION_JSON.isSameMimeType(contentType) && response.getCode() >= HttpStatus.SC_SUCCESS && response.getCode() < HttpStatus.SC_REDIRECTION) {
entityConsumer = consumerSupplier.get();
} else {
entityConsumer = new NoopJsonEntityConsumer<>();
}
return entityConsumer;
}
use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class ResponseRendererImpl method findContentType.
public ContentType findContentType(Object component) {
Component c = (Component) component;
String pageName = c.getComponentResources().getPageName();
Page page = pageCache.get(pageName);
return pageContentAnalyzer.findContentType(page);
}
use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class MarkupWriterFactoryImpl method constructMarkupWriter.
private MarkupWriter constructMarkupWriter(ContentType contentType, boolean partial, boolean HTML5) {
final String mimeType = contentType.getMimeType();
boolean isHTML = mimeType.equalsIgnoreCase("text/html");
MarkupModel model;
if (isHTML)
model = HTML5 ? (partial ? html5PartialModel : html5Model) : (partial ? htmlPartialModel : htmlModel);
else
model = partial ? xmlPartialModel : xmlModel;
return new MarkupWriterImpl(model, contentType.getCharset(), mimeType);
}
use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class MarkupWriterFactoryImpl method newMarkupWriter.
public MarkupWriter newMarkupWriter(Page page) {
boolean isHTML5 = hasHTML5Doctype(page);
ContentType contentType = pageContentTypeAnalyzer.findContentType(page);
return constructMarkupWriter(contentType, false, isHTML5);
}
Aggregations