Skip to content

Instantly share code, notes, and snippets.

@boudhayan-dev
Created May 1, 2021 16:33
Show Gist options
  • Save boudhayan-dev/38f2675e3514058270b59b5da6e33a09 to your computer and use it in GitHub Desktop.
Save boudhayan-dev/38f2675e3514058270b59b5da6e33a09 to your computer and use it in GitHub Desktop.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
// Lazily initialize the delegate if necessary.
Filter delegateToUse = this.delegate;
if (delegateToUse == null) {
synchronized (this.delegateMonitor) {
delegateToUse = this.delegate;
if (delegateToUse == null) {
WebApplicationContext wac = findWebApplicationContext();
if (wac == null) {
throw new IllegalStateException("No WebApplicationContext found: " +
"no ContextLoaderListener or DispatcherServlet registered?");
}
delegateToUse = initDelegate(wac);
}
this.delegate = delegateToUse;
}
}
// Let the delegate perform the actual doFilter operation.
invokeDelegate(delegateToUse, request, response, filterChain);
}
protected void invokeDelegate(
Filter delegate, ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
delegate.doFilter(request, response, filterChain);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment