use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class ContentTypeTest method parse_with_parameters.
@Test
public void parse_with_parameters() throws Exception {
ContentType contentType = new ContentType("text/html;charset=utf-8");
assertEquals(contentType.getBaseType(), "text");
assertEquals(contentType.getSubType(), "html");
assertEquals(contentType.getMimeType(), "text/html");
List<String> parameterNames = contentType.getParameterNames();
assertEquals(parameterNames.size(), 1);
assertEquals(parameterNames.get(0), "charset");
assertEquals(contentType.getCharset(), "utf-8");
assertTrue(contentType.hasParameters());
String nonexistant = contentType.getParameter("nonexistant");
assertTrue(nonexistant == null);
}
use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class ContentTypeTest method simple_equals.
@Test
public void simple_equals() {
ContentType master = new ContentType("text/html");
assertFalse(master.equals(null));
assertFalse(master.equals(this));
assertTrue(master.equals(master));
assertTrue(master.equals(new ContentType("text/html")));
assertFalse(master.equals(new ContentType("foo/bar")));
assertFalse(master.equals(new ContentType("text/plain")));
}
use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class ContentTypeTest method parse_without_parameters.
@Test
public void parse_without_parameters() throws Exception {
ContentType contentType = new ContentType("text/html");
assertEquals(contentType.getBaseType(), "text");
assertEquals(contentType.getSubType(), "html");
assertEquals(contentType.getMimeType(), "text/html");
assertTrue(contentType.getParameterNames().isEmpty());
assertFalse(contentType.hasParameters());
}
use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class TapestryModule method contributeMetaWorker.
/**
* Contributes extractors for {@link Meta}, {@link Secure}, {@link ContentType} and {@link WhitelistAccessOnly} annotations.
*
* @since 5.2.0
*/
@SuppressWarnings("unchecked")
public static void contributeMetaWorker(MappedConfiguration<Class, MetaDataExtractor> configuration) {
configuration.addInstance(Meta.class, MetaAnnotationExtractor.class);
configuration.add(Secure.class, new FixedExtractor(MetaDataConstants.SECURE_PAGE));
configuration.addInstance(ContentType.class, ContentTypeExtractor.class);
configuration.add(WhitelistAccessOnly.class, new FixedExtractor(MetaDataConstants.WHITELIST_ONLY_PAGE));
configuration.addInstance(UnknownActivationContextCheck.class, UnknownActivationContextExtractor.class);
}
use of org.apache.tapestry5.http.ContentType in project httpcomponents-client by apache.
the class AsyncEchoHandler method handleRequest.
@Override
public void handleRequest(final HttpRequest request, final EntityDetails entityDetails, final ResponseChannel responseChannel, final HttpContext context) throws HttpException, IOException {
final String method = request.getMethod();
if (!"GET".equalsIgnoreCase(method) && !"HEAD".equalsIgnoreCase(method) && !"POST".equalsIgnoreCase(method) && !"PUT".equalsIgnoreCase(method)) {
throw new MethodNotSupportedException(method + " not supported by " + getClass().getName());
}
if (entityDetails != null) {
final ContentType contentType = ContentType.parseLenient(entityDetails.getContentType());
entityConsumer.streamStart(entityDetails, new FutureCallback<byte[]>() {
@Override
public void completed(final byte[] content) {
final BasicAsyncEntityProducer entityProducer = new BasicAsyncEntityProducer(content, contentType);
entityProducerRef.set(entityProducer);
try {
responseChannel.sendResponse(new BasicHttpResponse(HttpStatus.SC_OK), entityProducer, context);
} catch (final IOException | HttpException ex) {
failed(ex);
}
}
@Override
public void failed(final Exception ex) {
releaseResources();
}
@Override
public void cancelled() {
releaseResources();
}
});
} else {
responseChannel.sendResponse(new BasicHttpResponse(HttpStatus.SC_OK), null, context);
entityConsumer.releaseResources();
}
}
Aggregations