Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.com.ctbc.maestro.vantive.vraptor;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import br.com.caelum.vraptor.InterceptionException;
- import br.com.caelum.vraptor.Intercepts;
- import br.com.caelum.vraptor.core.InterceptorStack;
- import br.com.caelum.vraptor.http.MutableRequest;
- import br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor;
- import br.com.caelum.vraptor.interceptor.Interceptor;
- import br.com.caelum.vraptor.interceptor.ParametersInstantiatorInterceptor;
- import br.com.caelum.vraptor.ioc.RequestScoped;
- import br.com.caelum.vraptor.resource.ResourceMethod;
- import es.cenobit.const.UserAttributesConstants;
- import es.cenobit.util.AuditThreadLocal;
- /**
- * Intercepta as requisições (HttpRequest).
- *
- * @author Nycholas de Oliveira e Oliveira
- */
- @RequestScoped
- @Intercepts(after = ParametersInstantiatorInterceptor.class, before = ExecuteMethodInterceptor.class)
- public class RequestInterceptor implements Interceptor {
- private static final Logger log = LoggerFactory.getLogger(RequestInterceptor.class);
- private final MutableRequest request;
- public RequestInterceptor(MutableRequest request) {
- this.request = request;
- }
- @Override
- public void intercept(InterceptorStack stack, ResourceMethod method, Object resourceInstance)
- throws InterceptionException {
- this.injectUserAttributesInThreadLocal();
- stack.next(method, resourceInstance);
- }
- @SuppressWarnings("unused")
- private void injectUserAttributesInThreadLocal() {
- log.debug("Init RequestInterceptor::injectUserAttributesInThreadLocal()");
- String userName = this.request.getHeader(UserAttributesConstants.USER_NAME);
- AuditThreadLocal.set(userName);
- }
- @Override
- public boolean accepts(ResourceMethod method) {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment