Are you using guice-servlet to bind MyServlet or web.xml? To be intercepted, objects have to be created by Guice... servlets are created by the servlet container unless you use guice-servlet (which is nicer looking and more typesafe than web.xml anyway). See http://code.google.com/p/google-guice/wiki/Servlets
Colin On Wed, Mar 24, 2010 at 10:21 PM, William Chu <[email protected]> wrote: > Hi, > > I have the an interceptor that doesn't get invoked and I'm unable to figure > out why. I was wondering if you had any insight. I have an annotation called > LoggedIn that triggers the Interceptor. > > I have setup the interceptor as follows: > > public class WebModule extends ServletModule { > > @Override > protected void configureServlets() { > > LoggedInInterceptor loggedInInterceptor = new > LoggedInInterceptor(); > bindInterceptor(Matchers.any(), > Matchers.annotatedWith(LoggedIn.class), loggedInInterceptor); > requestInjection(loggedInInterceptor); > .... > > } > } > > > public class MyGuiceServletConfig extends GuiceServletContextListener { > > @Override > protected Injector getInjector() { > > Injector injector = Guice.createInjector(Stage.PRODUCTION, new > WebModule(), new LoggingModule()); > GrabBag.put(GrabBag.GUICE_INJECTOR, injector); > return injector; > > } > > @Override > public void contextDestroyed(ServletContextEvent servletContextEvent) { > super.contextDestroyed(servletContextEvent); > } > } > > > > @Retention(RetentionPolicy.RUNTIME) > @Target(ElementType.METHOD) > public @interface LoggedIn { > > } > > > public class LoggedInInterceptor implements MethodInterceptor { > > @Override > public Object invoke(MethodInvocation invocation) throws Throwable { > System.out.println("LoggedInInterceptor.invoke called"); > .... > } > } > > > > MyServlet extends HttpServlet { > > @LoggedIn > private void doPost(HttpServletRequest request, HttpServletResponse > response) throws ServletException, IOException { > System.out.println("doPost called"); > ..... > } > } > > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
