• 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

Logging HTTP Response Headers

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any way to read HTTP response headers with Servlets? HttpServletResponse does not seem to have anything that serves this purpose.

Also I'm using a JBoss server, so if there is no way to do this with the Servlet spec, is there some JBoss specific way of reading this information before it gets served?
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Is there any way to read HTTP response headers with Servlets?


Yes you can get these values.

HttpServletResponse does not seem to have anything that serves this purpose.


Please see the specification of getHeader(java.lang.String name) method of this class HttpServletResponse.java it provides you with the value of the response header with the given name.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Please see the specification of getHeader(java.lang.String name) method of this class HttpServletResponse


HttpServletResponse has no such method; it's possible to set headers, not get them.
 
Gaurav Sainii
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please refer the API specification.

For method getHeader here is the direct link:-

getHeader(java.lang.String name)

Please correct me if I am missing anything. :-)
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That assumes a Servlet 3.0 container, which are not widely used yet.
 
Ranch Hand
Posts: 129
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getHeader

java.lang.String getHeader(java.lang.String name)
Gets the value of the response header with the given name.
If a response header with the given name exists and contains multiple values, the value that was added first will be returned.

This method considers only response headers set or added via setHeader(java.lang.String, java.lang.String), addHeader(java.lang.String, java.lang.String), setDateHeader(java.lang.String, long), addDateHeader(java.lang.String, long), setIntHeader(java.lang.String, int), or addIntHeader(java.lang.String, int), respectively.

Parameters:
name - the name of the response header whose value to return
Returns:
the value of the response header with the given name, or null if no header with the given name has been set on this response
Since:
Servlet 3.0
 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:That assumes a Servlet 3.0 container, which are not widely used yet.



Yes, I'm using the 2.5 Java EE API where HttpServletResponse.getHeaders is not yet implemented.

It looks like 3.0 is still a draft specification? I don't think I am ready to adopt it yet.

Is there any other less obvious way to read the response headers?
 
please buy this thing and then I get a fat cut of the action:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic