tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Johan Thorselius <johan.thorsel...@gmail.com>
Subject valve.invoke() called twice in request
Date Mon, 02 Nov 2009 14:10:17 GMT
Why is my valve.invoke() called twice ?

I have developed my own valve like in the code below. I see that the
invoke() method is called twice in the same request - does anyone know why ?

Note that my trace in listValves() shows that it is only one instance of my
valve AuthValve and one of
'org.apache.catalina.core.StandardEngineValve/1.0' which registered with the
pipeline (there are two valves in the list).

Tomcat 6.0.20 is used.

Johan

-- snip ---

public class AuthValve extends ValveBase {

    public AuthValve() {
    }

    @Override
    public void event(Request arg0, Response arg1, CometEvent arg2) throws
IOException, ServletException {
    }

    @Override
    public String getInfo() {
       return "This is the AuthValve";
    }

    @Override
    public Valve getNext() {
       return super.getNext();
    }

    @Override
    public void invoke(Request request, Response response) throws
IOException, ServletException {

        System.out.println("valve.invoke() thread: " +
Thread.currentThread().getName());
        listValves();

        String username = request.getHeader("h_name");
        String rolename = request.getHeader("h_role");
        System.out.println("valve.invoke() name:<" + username + "> role:<" +
rolename + ">");

        /*
         * Store info for LoginModule...
         */
        NameStore.setName(username);
        RoleStore.setRole(rolename);

        getNext().invoke(request,response);
    }


    private void listValves() {

      Container container=this.getContainer();
      if( container == null || ! (container instanceof ContainerBase) )
         return;
      ContainerBase containerBase=(ContainerBase)container;
      Pipeline pipe=containerBase.getPipeline();
      Valve valves[]=pipe.getValves();

      System.out.println(" This valve info:" + this.getInfo() + " : " +
this.toString());
      for (int i = 0; i < valves.length; i++) {
        Valve v = valves[i];
        System.out.println(" Valve " + String.valueOf(i) + " info:" +
v.getInfo() + " : " + v.toString());
      }
    }

}

-- end snip ---

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message