Sitebricks service interception?

90 Views Asked by At

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 ?

1

There are 1 best solutions below

1
Dhanji R. Prasanna On BEST ANSWER

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.