Skip to content

Instantly share code, notes, and snippets.

@nattaphonjeamjit
Created April 5, 2018 07:05
Show Gist options
  • Save nattaphonjeamjit/7a87072c468c40839ec14f10822e37c5 to your computer and use it in GitHub Desktop.
Save nattaphonjeamjit/7a87072c468c40839ec14f10822e37c5 to your computer and use it in GitHub Desktop.
import org.springframework.web.filter.OncePerRequestFilter;
import java.util.UUID;
@Configuration
public class LogIPAddressFilter extends OncePerRequestFilter {
private static final String KEY = "X-IP-ADDRESS";
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
ThreadContext.put(KEY, request.getRemoteAddr());
chain.doFilter(request, response);
ThreadContext.clearAll();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment