users@jersey.java.net

[Jersey] Where to put code that should be called at deployment time?

From: Edward Burns <edward.burns_at_oracle.com>
Date: Fri, 3 Jan 2014 12:39:40 -0800

Hello Jersey Users,

I'm trying to hack upon the jersey-mvc-jsp module and produce a
jersey-mvc-facelets module. My intent is to make it possible to return
a Viewable that references a Facelets page so that users can take
advantage of Facelets just as they would JSP, Freemarker, or Mustache.

I'm having trouble with auto bootstrapping, however.

The existing usage contract for pulling in a specific incarnation of the
jersey-mvc-* feature seems to be to say:

register([TemplateTechnology]MvcFeature.class);

from your application class that extends ResourceConfig, where
[TemplateTechnology] is Jsp, Freemarker, or Mustache. I'm trying to add
Facelets to that set.

Given that usage contract alone, I'd like to know how to make it so code
specific to Facelets is executed at deployment time.

I tried modifying my javax.ws.rs.core.Feature implementation to attempt
to add an ApplicationEventListener implementation, but find that it is
not called.

@ConstrainedTo(RuntimeType.SERVER)
public final class FaceletsMvcFeature implements Feature {

    @Override
    public boolean configure(final FeatureContext context) {
        if (!context.getConfiguration().isRegistered(MvcFeature.class)) {
            context.register(MvcFeature.class);
        }

        context.register(FaceletsTemplateProcessor.class);
        context.register(MyApplicationEventListener.class);
        return true;
    }
    
    public static class MyApplicationEventListener implements ApplicationEventListener {

    @Override
    public void onEvent(ApplicationEvent event) {
        System.out.println("debug: edburns: " + event.getType().name());
    }

    @Override
    public RequestEventListener onRequest(RequestEvent requestEvent) {
        return null;
    }
    
    }
    
}

What am I doing wrong? Any pointers?

Thanks,

Ed