Tag Archives: Application level

compress (GZIP  ) web application

There has two approach to support compress ,but Restlet can not support GIZP output ,so we can implement in the Application server (tomcat) level.
1) Application level:
response.setContentType(“application/json”);
response.setCharacterEncoding(“UTF-8”);
OutputStream output = response.getOutputStream();
String acceptEncoding = request.getHeader(“Accept-Encoding”);
if (acceptEncoding != null && acceptEncoding.contains(“gzip”)) {
response.setHeader(“Content-Encoding”, “gzip”);
output = new GZIPOutputStream(output);
}
output.write(json.getBytes(“UTF-8”));
2) Application server level:
Modify server.xml for Tomcat:
<Connector port=”80″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”443″
compression=”on”
compressableMimeType=”text/html,text/xml,text/plain,application/javascript,application/json,text/javascript” />
<Connector port=”443″ protocol=”HTTP/1.1″ SSLEnabled=”true”
maxThreads=”150″ scheme=”https” secure=”true”
clientAuth=”false” sslProtocol=”TLS” compression=”on”
compressableMimeType=”text/html,text/xml,text/plain,application/javascript,application/json,text/javascript” />
Here has a reference :http://tomcat.apache.org/tomcat-5.5-doc/config/http.html