package org.zalando.nakadi.filters;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.security.web.firewall.RequestRejectedException;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletResponse;

@Aspect
@Component
public class RequestRejectedFilter {

    @Around("execution(public void org.springframework.security.web.FilterChainProxy.doFilter(..))")
    public void handleRequestRejectedException(ProceedingJoinPoint pjp) throws Throwable {
        try {
            pjp.proceed();
        } catch (RequestRejectedException exception) {
            HttpServletResponse response = (HttpServletResponse) pjp.getArgs()[1];
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
    }
}

@@ -45,40 +45,36 @@
 org.
-a
 sp
-ectj.lang.ProceedingJoinPoint
+ringframework.core.Ordered
 ;%0Aim
@@ -86,63 +86,28 @@
 org.
-a
 sp
-ectj.lang.annotation.Around;%0Aimport org.aspectj.lang
+ringframework.core
 .ann
@@ -114,22 +114,21 @@
 otation.
-Aspect
+Order
 ;%0Aimport
@@ -256,295 +256,528 @@
 ort 
-javax.servlet.http.HttpServletResponse;%0A%0A@Aspect%0A@Component%0Apublic class RequestRejectedFilter %7B%0A%0A    @Around(%22execution(public void org.springframework.security.web.FilterChainProxy.doFilter(..))%22)%0A    public void handleRequestRejectedException(ProceedingJoinPoint pjp) throws Throwable
+org.springframework.web.filter.GenericFilterBean;%0Aimport javax.servlet.FilterChain;%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.ServletRequest;%0Aimport javax.servlet.ServletResponse;%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport java.io.IOException;%0A%0A%0A@Component%0A@Order(Ordered.HIGHEST_PRECEDENCE)%0Apublic class RequestRejectedFilter extends GenericFilterBean %7B%0A%0A    @Override%0A    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException
  %7B%0A 
@@ -805,20 +805,31 @@
     
-pjp.proceed(
+chain.doFilter(req, res
 );%0A 
@@ -870,24 +870,16 @@
 eption e
-xception
 ) %7B%0A    
@@ -943,26 +943,14 @@
 se) 
-pjp.getArgs()%5B1%5D
+res
 ;%0A
+%0A
     
@@ -1003,19 +1003,17 @@
 .SC_
-BAD_REQUEST
+NOT_FOUND
 );%0A 

Refactor RequestRejectedFilter to a bean component