Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Logging HTTP Response Headers  RSS feed

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • 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
  • 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: 42975
76
  • Mark post as helpful
  • send pies
  • 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
  • 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: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That assumes a Servlet 3.0 container, which are not widely used yet.
 
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!