use of org.glassfish.jersey.server.mvc.Template in project jersey by jersey.
the class TemplateModelProcessor method createEnhancingMethods.
/**
* Creates enhancing methods for given resource.
*
* @param resourceClass resource class for which enhancing methods should be created.
* @param resourceInstance resource instance for which enhancing methods should be created. May be {@code null}.
* @param newMethods list to store new methods into.
*/
private void createEnhancingMethods(final Class<?> resourceClass, final Object resourceInstance, final List<ModelProcessorUtil.Method> newMethods) {
final Template template = resourceClass.getAnnotation(Template.class);
if (template != null) {
final Class<?> annotatedResourceClass = ModelHelper.getAnnotatedResourceClass(resourceClass);
final List<MediaType> produces = MediaTypes.createQualitySourceMediaTypes(annotatedResourceClass.getAnnotation(Produces.class));
final List<MediaType> consumes = MediaTypes.createFrom(annotatedResourceClass.getAnnotation(Consumes.class));
final TemplateInflectorImpl inflector = new TemplateInflectorImpl(template.name(), resourceClass, resourceInstance);
newMethods.add(new ModelProcessorUtil.Method(HttpMethod.GET, consumes, produces, inflector));
newMethods.add(new ModelProcessorUtil.Method(IMPLICIT_VIEW_PATH_PARAMETER_TEMPLATE, HttpMethod.GET, consumes, produces, inflector));
}
}
use of org.glassfish.jersey.server.mvc.Template in project jersey by jersey.
the class TemplateMethodInterceptor method aroundWriteTo.
@Override
public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
final Template template = TemplateHelper.getTemplateAnnotation(context.getAnnotations());
final Object entity = context.getEntity();
if (template != null && !(entity instanceof Viewable)) {
context.setType(Viewable.class);
context.setEntity(new Viewable(template.name(), entity));
}
context.proceed();
}
use of org.glassfish.jersey.server.mvc.Template in project jersey by jersey.
the class CombinedFeedController method create.
@POST
@Template(name = "/index.ftl")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Viewable create(@Valid @BeanParam FeedRequestBean request) {
String[] urlArray = createUrls(request.getUrls()).stream().toArray(String[]::new);
CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(null, urlArray).title(request.getTitle()).description(request.getDescription()).refreshPeriod(request.getRefreshPeriod()).build();
feedService.save(feed);
return new Viewable("/index.ftl", getModel());
}
Aggregations