package de.spring.example.rest.handler;
-import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import de.spring.example.context.UsernameThreadContext;
public class UsernameHandler extends HandlerInterceptorAdapter {
- private final UsernameThreadContext usernameThreadContext;
-
- @Inject
- public UsernameHandler(UsernameThreadContext userNameThreadContext) {
- this.usernameThreadContext = userNameThreadContext;
- }
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
final String userName = request.getHeader(UsernameThreadContext.USERNAME_HEADER);
if (userName != null) {
- usernameThreadContext.setUsername(userName);
+ UsernameThreadContext.setUsername(userName);
} else {
- usernameThreadContext.clearUsername();
+ UsernameThreadContext.clearUsername();
}
return super.preHandle(request, response, handler);
public void afterCompletion(
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception {
- usernameThreadContext.clearUsername();
+ UsernameThreadContext.clearUsername();
}
}