Search in sources :

Example 1 with Template

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));
    }
}
Also used : ModelProcessorUtil(org.glassfish.jersey.server.model.internal.ModelProcessorUtil) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) MediaType(javax.ws.rs.core.MediaType) Template(org.glassfish.jersey.server.mvc.Template)

Example 2 with Template

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();
}
Also used : Viewable(org.glassfish.jersey.server.mvc.Viewable) Template(org.glassfish.jersey.server.mvc.Template)

Example 3 with Template

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());
}
Also used : CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) Viewable(org.glassfish.jersey.server.mvc.Viewable) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Template(org.glassfish.jersey.server.mvc.Template) ErrorTemplate(org.glassfish.jersey.server.mvc.ErrorTemplate)

Aggregations

Template (org.glassfish.jersey.server.mvc.Template)3 Consumes (javax.ws.rs.Consumes)2 Viewable (org.glassfish.jersey.server.mvc.Viewable)2 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 MediaType (javax.ws.rs.core.MediaType)1 CombinedFeed (org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed)1 ModelProcessorUtil (org.glassfish.jersey.server.model.internal.ModelProcessorUtil)1 ErrorTemplate (org.glassfish.jersey.server.mvc.ErrorTemplate)1