You need to attach the filter to the router and then attach the ServerResource to the filter using the method setNext(Class<? extends ServerResource> targetClass)
:
Filter myFilter = new MyFilter(getContext());
myFilter.setNext(MyServerResource.class);
router.attach("/test", myFilter);
Now you can preprocess using the filter's beforeHandle(Request request, Response response)
method. If you return CONTINUE
in this method, the filter will pass the request to the ServerResource.