• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reg Tom cat valve

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I'm trying to implement a custom tomcat valve. My application server is JBoss 4.0.5GA with Tomcat 5.5. I created a class, "RenewSession.java" extending ValveBase.java and I declared the valve in the server.xml as follows.

<Host name="localhost" autoDeploy="false" deployOnStartup="false" deployXML="false">
<Valve className="com.alcatel.ni.html.login.RenewSessionValve" />
<DefaultContext cookies="true" crossContext="true" override="true" />
</Host>


In my project, I'm want to use the valve along with a servlet filter. The flow is suppose to be like this

Valve -> Login filter -> Page servlet -> etc..

My problem is that, I'm getting the request in my Valve but it is not proceeding to the filter. Can anyone help me on this. Its really urgent.

Regards
Shenaz

PS: Please find below my Valve code.



 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have never written a custom valve in Tomcat. But going by its documentation, it appears to be a chain. So i guess in your custom valve, you are responsible for getting the next valve (if any) and invoking it:

 
Shenaz Assu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jaikiran,

I don't have a second valve. Once my request is processed in RenewSession valve, i want it to be available in my login filter. Even if I'm using another valve, how will eventually get the request in login servlet?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shenaz Assu wrote:Hi Jaikiran,

I don't have a second valve. Once my request is processed in RenewSession valve, i want it to be available in my login filter. Even if I'm using another valve, how will eventually get the request in login servlet?




Did you ever resolve this?

I'm interested in doing the same thing.



 
Shenaz Assu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bruce,

Yes, I was able to resolve this issue.

Like Filters you need to hand over to the next Valve in the chain.

getNext().invoke(request, response);

Doesn't matter whether you're using another Valve or not. Unless your Valve performs some kind of redirection, it needs to call invoke() on the next Valve. Yours is just one of several Valves.

Tomcat handles the end of the chain and passes the request/response into the appropriate web application Filter chain and then to the matching Servlet.

Hope this helps.

Regards
Shenaz
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all for an enlightning discussion. My other sources confirm that you're supposed to call getNext().invoke() from within your valve if you want the request passed into your servlet.

I'm curious about a detail or too (some of you won't care).

Is it safe to assume that getNext() doesn't return null? Admitted, you can set next to null on your valve, so it's technically possible that getNext() returns null. But as long as you don't do anything like that, my feeling is you should be safe. Which would suggest:


If you think you should take the null into account, Jaikiran Pai's code is the right one. For thread safety, you should call getNext() only once.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic