3

Hi,

I am trying to make a gzipped response in a Neo4j unmanaged extension. I found this example: http://www.codingpedia.org/ama/how-to-compress-responses-in-java-rest-api-with-gzip-and-jersey/

I tried to add this WriterInterceptor:

@Provider
@Compress
public class GZIPWriterInterceptor implements WriterInterceptor {

    @Override
    public void aroundWriteTo(WriterInterceptorContext context)
            throws IOException, WebApplicationException {

        MultivaluedMap<String,Object> headers = context.getHeaders();
        headers.add("Content-Encoding", "gzip");

        final OutputStream outputStream = context.getOutputStream();
        context.setOutputStream(new GZIPOutputStream(outputStream));
        context.proceed();
    }
}

And this annotation:

@NameBinding
@Retention(RetentionPolicy.RUNTIME)
public @interface Compress {
}

And in my resource I use it like this:

@GET
@Path("/users")
@Produces(MediaType.APPLICATION_JSON)
@Compress
public List<User> getUsers() {
    return factory.getUserService(graphDb).getUsers();
}

However the WriterInterceptor is never called, why? How can I make my response gzipped?

I want to solve this inside my unmanaged plugin and solutions where the response is gzipped in a proxy outside of Neo4j is not an alternative.

David Berg
  • 1,958
  • 1
  • 21
  • 37

1 Answers1

1

You need to register a servlet filter that cares about gzipping. This can be done in a SPIPluginLifecycle, see this blog post: http://www.markhneedham.com/blog/2013/07/08/neo4j-unmanaged-extension-creating-gzipped-streamed-responses-with-jetty/

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97