Question

I am working with Sitebricks I like it. I wonder,however, what the best approach for services intercepting for cross-cutting tasks, is ? Logging, Validation, Exception Handling, are all tasks to be put in an interceptors like components. Currently I am doing it with AOP on the services like so :

bindInterceptor(annotatedWith(Service.class), returns(only(Reply.class)), new HttpRequestFailureReportInterceptor(new MessageAcceptor() {
          @Override
          public void accept(String message) {
            Logger logger = LoggerFactory.getLogger(this.getClass());
            logger.debug(message);
          }
        }));

Is this a good way to accomplish tasks like that ? If no, why ? What are advantages and drawback of this approach ?

Was it helpful?

Solution

We definitely encourage you to use Guice AOP which is quite robust and full featured. One of the goals of Sitebricks is not to hide Guice but rather rely on it strongly.

The canonical method is by using annotations like @Traced for a method whose execution is traced or @Transactional etc. If you use sitebricks-persist the latter annotation comes for free.

Dhanji.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top