Hitachi

uCosminexus Application Server Compatibility Guide


10.2.3 Executing the applications that use the HTTP response compression filter

This section describes the precautions to be taken when developing applications that use the HTTP response compression filter.

Organization of this subsection

(1) Order of invocation when the HTTP response compression filter is combined with other filters

The HTTP response compression filter must be invoked before the other filters specified in the HTTP response header. When you use the setHeader method, addHeader method, setIntHeader method, and addIntHeader method of javax.servlet.http.HttpServletResponse to use other filters that set Content-Length header and Content-Encoding header, deploy the other filters after the HTTP response compression filter.

(2) Precautions related to HTTP response buffer

When the HTTP response compression functionality is enabled, the buffer with the size specified in the compression threshold is installed before the HTTP response buffer. Data is written in the HTTP response buffer when the output data exceeds the compression threshold.

Unless the compressed data size exceeds the HTTP response buffer size, the HTTP response is not written in the Web client. If you are required to write the HTTP response in the Web client before the output data size exceeds the compression threshold, you must explicitly invoke the flush method of the stream for response output#. However, if the flush method or flushBuffer method of the javax.servlet.ServletResponse interface is invoked before the output data size exceeds the compression threshold, the output data is written in the Web client without being compressed.

#

The stream for response output indicates the following objects:

  • javax.servlet.ServletOutputStream acquired by the getOutputStream method of the javax.servlet.ServletResponse interface

  • java.io.PrintWriter acquired by the getWriter method of the javax.servlet.ServletResponse interface

  • javax.servlet.jsp.JspWriter implicitly available in JSP

(3) Precautions related to the response header of the HTTP response

When the response body of the HTTP response is compressed with the HTTP response compression functionality, gzip is specified in the Content-Encoding header and Accept-Encoding is specified in the Vary header of this HTTP response. Nothing is specified in the Content-Length header.

Therefore, note the following points when you use the setContentLength method of the javax.servlet.ServletResponse interface and when you use API# for adding and changing the response header of the javax.servlet.http.HttpServletResponse interface:

#

The API for adding and changing the response header indicates the following methods of the javax.servlet.http.HttpServletResponse interface:

  • setHeader method

  • addHeader method

  • setIntHeader method

  • addIntHeader method

(4) Precautions related to data output for HTTP response

Note the following points when ServletOutputStream or PrintWriter is acquired with the getOutputStream method or the getWriter method of the javax.servlet.ServletResponse interface and the HTTP response is output:

(5) Precautions for compressing HTTP responses in applications

For HTTP responses compressed in applications, specify settings so that the HTTP response compression functionality is not enabled. If the HTTP response compression functionality is enabled for the HTTP responses compressed in applications, the operations might not function properly.