You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Johan Thorselius <jo...@gmail.com> on 2009/11/02 15:10:17 UTC

valve.invoke() called twice in request

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 ---

Re: valve.invoke() called twice in request

Posted by Johan Thorselius <jo...@gmail.com>.
> Are you sure it's called twice in the same
> request?  Or is the browser making multiple
> requests for separate resources on the
> same page?

Yes, sorry - they are multiple requests. A stack trace showed two reqeusts.
I was confused.

It's part of a bigger issue where 'I cannot get rid of the authentication
login user/pwd box' when using an authentication proxy in front of the
Tomcat.  I found that the call to the authentication login user/pwd box is
done approx. between my valve and the StandardEngineValve, or maybe rather
in the StandardEngineValve itself. After the authent. login user/pwd,
obviously my valve is called once again. My bigger issue I described in
another posting last friday.

Thanks

Johan


2009/11/2 Caldarale, Charles R <Ch...@unisys.com>

> > From: Johan Thorselius [mailto:johan.thorselius@gmail.com]
> > Subject: valve.invoke() called twice in request
> >
> > Why is my valve.invoke() called twice ?
>
> Are you sure it's called twice in the same request?  Or is the browser
> making multiple requests for separate resources on the same page?
>
> You could log the stack trace when invoked, and included additional
> information such as the result of the toString() method for both the Request
> and Response object.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you received
> this in error, please contact the sender and delete the e-mail and its
> attachments from all computers.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: valve.invoke() called twice in request

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Johan Thorselius [mailto:johan.thorselius@gmail.com]
> Subject: valve.invoke() called twice in request
> 
> Why is my valve.invoke() called twice ?

Are you sure it's called twice in the same request?  Or is the browser making multiple requests for separate resources on the same page?

You could log the stack trace when invoked, and included additional information such as the result of the toString() method for both the Request and Response object.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org