Default HTTP Headers set on Servlet Response in WebSphere Application Server

I wanted to check what all headers are set when i make a request to a HttpServlet deployed in WebSphere Application Server, so i created a simple web application which has 2 JSPs index.jsp and second.jsp that include a JavaScript file like this


<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Debug Cache Application</title>

<script type="text/javascript" src="resource/test.js?v1"></script>

</head>
<body>
<h1>Index.jsp</h1>
<a href='second.jsp'>Take to second.jsp</a>
</body>
</html>


In the index.jsp i am including test.js JavaScript on the page but that request is handled by ResourceServingServlet, which is mapped to handle all the requests mapped to /resource path. This is how my ResourceServingServlet looks like


package com.webspherenotes.performance;

import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ResourceServingServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("Entering ResourceServingServlet.doGet()");

System.out.println("Request path " + request.getPathInfo());
System.out.println("Query String " + request.getQueryString());
printRequestHeaders(request);
response.setContentType("application/javascript");
getServletContext().getRequestDispatcher("/js/test.js").include(request, response);
System.out.println("Exiting ResourceServingServlet.doGet()");
}

private void printRequestHeaders(HttpServletRequest request){
System.out.println("************** Request Header ****************");
Enumeration headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements()){
String headerName = headerNames.nextElement();
String headerValue = request.getHeader(headerName);
System.out.println(headerName + " = " + headerValue);
}
System.out.println("************** *********** ****************");
}
}


The ResourceServingServlet is pretty simple in the doGet() method it is printing information about the request such as request path, query string, then forwarding control to printRequestHeaders() for printing all the HTTP headers and finally forwarding control to test.js file located in js folder for generating markup.

After deploying this servlet in my local WAS 6.1 environment i looked at what all headers are returned by Servlet for the request, note that i am setting only Content-Type header but reset of the headers are set by WAS for us



WAS is setting Content-Language header with value equal to English, i am assuming that's the default value and the Content-Length header equal to 44, which is size of the JavaScript file, Value of Date header is time when the response was generated and value of Server headers is WebSphere Application Server/6.1, which is the server which generated the response

2 comments:

  1. Is it possible to set up global settings for example: *.jpg files to
    set Cache-Control (max-age) header ?
    Or E-Tag header.. I have only WAS server.. It is serving dynamic+static content
    I want to have cache control on static content (with Etag or cache-control headers)..

    Thanks in advance

    ReplyDelete