Hi guys,

Any idea how to compress large JSON content using the JAX-RS implementation in 
Restlet? 

I have a MessageBodyWriter that writes Json objects to the output stream. It is 
annotated with:

@javax.ws.rs.Produces("application/json")

and it works fine. But I'd like to be able to compress the content with gzip 
which is automatically recognized by browsers given the appropriate HTTP 
response headers. To achieve that I tried the following:

    public void writeTo(Json t, Class<?> type, Type genericType,
                        Annotation[] annotations, MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream) throws IOException,
            WebApplicationException
    {
        httpHeaders.put("Content-Type", 
Collections.singletonList((Object)"application/json"));
        httpHeaders.put("Content-Encoding", 
Collections.singletonList((Object)"gzip"));
        java.util.zip.GZIPOutputStream gzip = new 
java.util.zip.GZIPOutputStream(entityStream);
        gzip.write(t.toString().getBytes());
    }


But I'm getting an exception: "The changing of the http headers is not 
supported by this runtime environment." What would be the suggested way? 

Thanks much!
Boris

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2949229

Reply via email to