cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Upayavira ...@upaya.co.uk>
Subject Re: gzip compression
Date Mon, 15 Dec 2003 17:48:31 GMT
If you use Apache in front of your servlet container, you could use 
mod_deflate, I believe. Really, HTTP compression of pages is not a job 
for Cocoon as such, but for the servlet container or front end server.

Upayavira

Carmona Perez, David wrote:

>Hi all,
>
>Does someone how can I make some action that activates compressing output data using GZip?
 Gzip compression is an HTTP 1.1 standard feature.
>
>Ideally it would be great if it could be like an action, so that it's easy to activate
it on or off.
>I have tried this code:
>
>import java.io.IOException;
>import java.io.OutputStream;
>import java.util.Map;
>import java.util.zip.GZIPOutputStream;
>
>import javax.servlet.ServletOutputStream;
>import javax.servlet.http.HttpServletResponse;
>
>import org.apache.avalon.framework.parameters.Parameters;
>import org.apache.cocoon.acting.AbstractAction;
>import org.apache.cocoon.environment.ObjectModelHelper;
>import org.apache.cocoon.environment.Redirector;
>import org.apache.cocoon.environment.Request;
>import org.apache.cocoon.environment.SourceResolver;
>import org.apache.cocoon.environment.http.HttpEnvironment;
>import org.apache.cocoon.environment.http.HttpResponse;
>
>public class CompressAction extends AbstractAction {
>	class StreamGzip extends ServletOutputStream {
>		public StreamGzip(OutputStream out) throws IOException {
>			gzip = new GZIPOutputStream(out);
>		}
>		/** @see java.io.OutputStream#write(int) */
>		public void write(int b) throws IOException {
>			gzip.write(b);
>		}
>		/** @see java.io.OutputStream#close() */
>		public void close() throws IOException {
>			gzip.close();
>		}
>		/** @see java.io.OutputStream#flush() */
>		public void flush() throws IOException {
>			gzip.flush();
>		}
>		private GZIPOutputStream gzip;
>	}
>	class GzipResponse extends HttpResponse {
>		GzipResponse(HttpServletResponse resp) throws IOException {
>			super(resp);
>			os = new StreamGzip(resp.getOutputStream());
>		}
>		public ServletOutputStream getOutputStream() throws IOException {
>			return os;
>		}
>		StreamGzip os;
>	}
>	public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String
source, Parameters parameters) throws Exception {
>		Request pet = ObjectModelHelper.getRequest(objectModel);
>		String accept = pet.getHeader("Accept-Encoding");
>		if (accept != null && accept.indexOf("gzip") >= 0) {
>			GzipResponse resp = new GzipResponse((HttpServletResponse)objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT));
>			resp.setHeader("Content-Encoding", "gzip");
>			objectModel.put(ObjectModelHelper.RESPONSE_OBJECT, resp);
>			return EMPTY_MAP;
>		}
>		return null;
>	}
>}
>
>But it doesn't work, because the HttpEnvironment holds also holds a reference to the outputstream.
>Which is the cleanest way to perform this?
>Any suggestion will be greatly appreciated.
>
>
>--------
>David
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message