mercredi 4 mai 2016

Run method before every method call of HttpServlet

I'm writing an abstract Tomcat servlet, Foo and I want to make it so that whenever a method is called in FooImplement, it runs a method from Foo.

So before every method call in FooImplement I want to run checkAccess defined in Foo. If the user does not have access, the method is not invoked and the request is redirected elsewhere. If the user does have access, the method is invoked.

I thought I could use a Proxy as seen here but the problem is I cannot pass tomcat the proxy instance because that would involve an impossible constructor of

public Foo() {
    return (Foo) Proxy.newProxyInstance(
    this.getClass().getClassLoader(),
    new Class[]{this.getClass()},
    new FooInvocationHandler(this);
}

Does anyone know of a way I can do this?





Aucun commentaire:

Enregistrer un commentaire