public ContentTypeEngine getContentTypeEngine(String contentType) { return engines.getContentTypeEngine(contentType); }
public String getAcceptType() { if (acceptType == null) { acceptType = httpServletRequest.getHeader(HttpConstants.Header.ACCEPT); // try to specify an AcceptType from an registered ContentType suffix String suffix = StringUtils.getFileExtension(getPath()); if (!StringUtils.isNullOrEmpty(suffix)) { ContentTypeEngine engine = contentTypeEngines.getContentTypeEngine(suffix); if (engine != null) { acceptType = engine.getContentType(); } } } return acceptType; }
ContentTypeEngine engine = contentTypeEngines.getContentTypeEngine(contentType); if (engine == null) { throw new PippoRuntimeException(
ContentTypeEngine engine = contentTypeEngines.getContentTypeEngine(request.getAcceptType()); if (engine != null) { log.debug("Negotiated '{}' from request Accept header", engine.getContentType()); } else if (!StringUtils.isNullOrEmpty(request.getContentType())) { engine = contentTypeEngines.getContentTypeEngine(request.getContentType()); if (engine != null) { log.debug("Negotiated '{}' from request Content-Type header", engine.getContentType());
private void send(Object object, String contentType) { if (StringUtils.isNullOrEmpty(contentType)) { throw new PippoRuntimeException("You must specify a content type!"); } ContentTypeEngine contentTypeEngine = contentTypeEngines.getContentTypeEngine(contentType); if (contentTypeEngine == null) { throw new PippoRuntimeException("You must set a content type engine for '{}'", contentType); } header(HttpConstants.Header.CONTENT_TYPE, contentTypeEngine.getContentType()); send(contentTypeEngine.toString(object)); }
/** * Configures the content-type suffixes * * @param engines * @return acceptable content-type suffixes */ protected Set<String> configureContentTypeSuffixes(ContentTypeEngines engines) { if (null == ClassUtil.getAnnotation(method, ContentTypeBySuffix.class)) { return Collections.emptySet(); } Set<String> suffixes = new TreeSet<>(); for (String suffix : engines.getContentTypeSuffixes()) { String contentType = engines.getContentTypeEngine(suffix).getContentType(); if (declaredProduces.contains(contentType)) { suffixes.add(suffix); } } return suffixes; }
/** * Configures the content-type suffixes * * @param engines * @return acceptable content-type suffixes */ protected Set<String> configureContentTypeSuffixes(ContentTypeEngines engines) { if (null == ClassUtil.getAnnotation(method, ContentTypeBySuffix.class)) { return Collections.emptySet(); } Set<String> suffixes = new TreeSet<>(); for (String suffix : engines.getContentTypeSuffixes()) { String contentType = engines.getContentTypeEngine(suffix).getContentType(); if (declaredProduces.contains(contentType)) { suffixes.add(suffix); } } return suffixes; }
private void logEngines() { if (!settings.getBoolean(SETTING_ENGINES_LOG, true)) { return; } TemplateEngine templateEngine = application.getTemplateEngine(); ContentTypeEngines engines = application.getContentTypeEngines(); List<String> contentTypes = new ArrayList<>(engines.getContentTypes()); Collections.sort(contentTypes); int maxContentTypeLen = 0; int maxTemplateEngineLen = templateEngine == null ? 0 : templateEngine.getClass().getName().length(); for (String contentType : contentTypes) { ContentTypeEngine engine = engines.getContentTypeEngine(contentType); maxContentTypeLen = Math.max(maxContentTypeLen, contentType.length()); maxTemplateEngineLen = Math.max(maxTemplateEngineLen, engine.getClass().getName().length()); } if (templateEngine != null) { log.info("{} => {}", Strings.padEnd("templates", maxContentTypeLen, ' '), templateEngine.getClass().getName()); } for (String contentType : contentTypes) { ContentTypeEngine engine = engines.getContentTypeEngine(contentType); log.info("{} => {}", Strings.padEnd(contentType, maxContentTypeLen, ' '), engine.getClass().getName()); } }
private void logEngines() { if (!settings.getBoolean(SETTING_ENGINES_LOG, true)) { return; } TemplateEngine templateEngine = application.getTemplateEngine(); ContentTypeEngines engines = application.getContentTypeEngines(); List<String> contentTypes = new ArrayList<>(engines.getContentTypes()); Collections.sort(contentTypes); int maxContentTypeLen = 0; int maxTemplateEngineLen = templateEngine == null ? 0 : templateEngine.getClass().getName().length(); for (String contentType : contentTypes) { ContentTypeEngine engine = engines.getContentTypeEngine(contentType); maxContentTypeLen = Math.max(maxContentTypeLen, contentType.length()); maxTemplateEngineLen = Math.max(maxTemplateEngineLen, engine.getClass().getName().length()); } if (templateEngine != null) { log.info("{} => {}", Strings.padEnd("templates", maxContentTypeLen, ' '), templateEngine.getClass().getName()); } for (String contentType : contentTypes) { ContentTypeEngine engine = engines.getContentTypeEngine(contentType); log.info("{} => {}", Strings.padEnd(contentType, maxContentTypeLen, ' '), engine.getClass().getName()); } }
@Override public Object serialize(ObjectMapperSerializationContext context) { ContentTypeEngine contentTypeEngine = contentTypeEngines.getContentTypeEngine(context.getContentType()); if (contentTypeEngine == null) { throw new FathomException("No ContentTypeEngine registered for {}", context.getContentType()); } return contentTypeEngine.toString(context.getObjectToSerialize()); } };
@Override public Object serialize(ObjectMapperSerializationContext context) { ContentTypeEngine contentTypeEngine = contentTypeEngines.getContentTypeEngine(context.getContentType()); if (contentTypeEngine == null) { throw new FathomException("No ContentTypeEngine registered for {}", context.getContentType()); } return contentTypeEngine.toString(context.getObjectToSerialize()); } };
String contentType = engines == null ? "???" : engines.getContentTypeEngine(suffix).getContentType(); sb.append("| ").append(contentType).append(" "); sb.append("| ").append(operationPath).append('.').append(suffix).append(" ");
String contentType = engines == null ? "???" : engines.getContentTypeEngine(suffix).getContentType(); sb.append("| ").append(contentType).append(" "); sb.append("| ").append(operationPath).append('.').append(suffix).append(" ");
@Override public Object deserialize(ObjectMapperDeserializationContext context) { ContentTypeEngine contentTypeEngine = contentTypeEngines.getContentTypeEngine(context.getContentType()); if (contentTypeEngine == null) { throw new FathomException("No ContentTypeEngine registered for {}", context.getContentType()); } return contentTypeEngine.fromString(context.getDataToDeserialize().asString(), context.getType()); }
@GET("/") @Consumes({Consumes.HTML}) @Metered public void get() { getResponse() .bind("myDesserts", engines.getContentTypeEngine(Produces.JSON).toString(dao.myDesserts)) .render("content"); }
@Override public Object deserialize(ObjectMapperDeserializationContext context) { ContentTypeEngine contentTypeEngine = contentTypeEngines.getContentTypeEngine(context.getContentType()); if (contentTypeEngine == null) { throw new FathomException("No ContentTypeEngine registered for {}", context.getContentType()); } return contentTypeEngine.fromString(context.getDataToDeserialize().asString(), context.getType()); }