Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access Response Status From Filter

 
Brian M Smith
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm attempting to access a Responses status to check to see if the page has a 404 or 500 status. Any idea what function I need to call to gain access to this information?
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

What are you wanting to do with this once you get it?

Sean
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your filter could create a custom HttpServletResponseWrapper with a custom setStatus method which tracked the status as it is set.

Bill
 
Brian M Smith
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the responses guys. I'm looking to just get the status not change it. I'm looking for a getStatus function call.
 
Shashank Rudra
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is not in the response header there, something that keeps track of the status code and status details.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because HttpServletResponse is an interface, the actual code and variables are not exposed directly.

Inside the actual implementation you might find something like the following from Tomcat 6.0.18 source code



So - if your HttpServletResponse is an instance of org.apache.catalina.connector.Response, you could call that method.

But note that this is not a general solution.

Bill
 
Brian M Smith
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill,

Thanks for the reply. What I'm looking for is something that is standard for Java, I can't use anything provided by apache other than struts.

Any ideas?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65339
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

More often than not, when you find yourself confronted with something that you can't do through the standard interfaces, it's something you shouldn't be doing, and can probably get yourself into trouble with by trying work-arounds.

So what is you are really trying to accomplish? Perhaps someone can come up with a better, standard way of doing it.
 
Brian M Smith
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to write a filter that will look to see if a javascript/css file has been requested. If one has, I want to minify that file and then sent it to the user. The problem is that if I get a 500 or 404 status it's attempting to minify the page being returned. The idea is that I want to check the status to make sure that 500 and 404 conditions don't exist.

Basically I'm trying to do on the fly file minification.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65339
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dumb question #2058: why are you doing this at run-time versus at build time?

We minify our scripts as part of the deployment build process and then never have to worry about it again.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah; it's one thing to gzip a dynamic page, but if the JS/CSS files are static this seems like an unnecessary complication.

You could also get the URI and determine if it's a CSS or JS--if it is, stop the filter chain, read, minify, and cache the file, and write to the response directly (I think, anyway). But why?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic