title: Compression with Restlet + Jetty embedded
body: <p>I'm trying to enable the compression in restlet + jetty embedded but in my test application the compression works only with requests handled directly by servlets and not for those handled by restlet. </p>
  
  <p>My test code:</p>
  
  <pre class="lang-java prettyprint-override"><code>package restlettest;
  
  import java.io.IOException;
  import java.util.EnumSet;
  
  import javax.servlet.DispatcherType;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.eclipse.jetty.server.Server;
  import org.eclipse.jetty.servlet.ServletContextHandler;
  import org.eclipse.jetty.servlets.GzipFilter;
  import org.restlet.Application;
  import org.restlet.Restlet;
  import org.restlet.ext.servlet.ServerServlet;
  import org.restlet.routing.Router;
  
  public class RestletTestServerJettyEmbedded {
  
      public static class RestletTestApplication extends Application {
  
          @Override
          public synchronized Restlet createInboundRoot() {
  
              Router router = new Router(getContext());
              router.attach("/sayHello", HelloWorldResource.class);
  
              return router;
          }
      }
  
      @SuppressWarnings("serial")
      public static class JettyServlet extends HttpServlet {
  
          @Override
          protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                  throws ServletException, IOException {
  
              resp.getWriter().println("Hello from jetty!");
          };
      }
  
      public static void main(String[] args) throws Exception {
  
          Server server = new Server(8080);
  
          final ServletContextHandler serveltContext = new ServletContextHandler(
                  ServletContextHandler.SESSIONS);
          serveltContext.setContextPath("/");
          serveltContext.setInitParameter("org.restlet.application",
                  RestletTestApplication.class.getName());
  
          serveltContext.addFilter(GzipFilter.class, "/*",
                  EnumSet.of(DispatcherType.REQUEST));
  
          serveltContext.addServlet(ServerServlet.class, "/restlet/*");
          serveltContext.addServlet(JettyServlet.class, "/jetty/*");
  
          server.setHandler(serveltContext);
  
          server.start();
          server.join();
      }
  }
  </code></pre>
  
  <p>The project POM:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.devmao.restlettest&lt;/groupId&gt;
      &lt;artifactId&gt;restlettest&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
      &lt;properties&gt;
  
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  
          &lt;jetty.version&gt;8.1.7.v20120910&lt;/jetty.version&gt;
          &lt;restlet.version&gt;2.1.0&lt;/restlet.version&gt;
  
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
  
          &lt;!-- Jetty --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jetty-servlets&lt;/artifactId&gt;
              &lt;version&gt;${jetty.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jetty-webapp&lt;/artifactId&gt;
              &lt;version&gt;${jetty.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- /Jetty --&gt;
  
          &lt;!-- Restlet --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.restlet.jee&lt;/groupId&gt;
              &lt;artifactId&gt;org.restlet.ext.servlet&lt;/artifactId&gt;
              &lt;version&gt;${restlet.version}&lt;/version&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.restlet.jee&lt;/groupId&gt;
              &lt;artifactId&gt;org.restlet.ext.httpclient&lt;/artifactId&gt;
              &lt;version&gt;${restlet.version}&lt;/version&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;!-- /Restlet --&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
              &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
              &lt;version&gt;4.2.2&lt;/version&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3.2&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.6&lt;/source&gt;
                      &lt;target&gt;1.6&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;repositories&gt;
  
          &lt;!-- Restlet Repositories --&gt;
          &lt;repository&gt;
              &lt;id&gt;maven-restlet&lt;/id&gt;
              &lt;name&gt;Public online Restlet repository&lt;/name&gt;
              &lt;url&gt;http://maven.restlet.org&lt;/url&gt;
          &lt;/repository&gt;
          &lt;!-- /Restlet Repositories --&gt;
  
      &lt;/repositories&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Testing servlet request:</p>
  
  <pre><code>$ curl -i -H 'Accept-Encoding: gzip,deflate' http://localhost:8080/jetty
  HTTP/1.1 200 OK
  Vary: Accept-Encoding
  Content-Encoding: gzip
  Transfer-Encoding: chunked
  Server: Jetty(8.1.7.v20120910)
  </code></pre>
  
  <p>Testing restlet request:</p>
  
  <pre><code>$ curl -i -H 'Accept-Encoding: gzip,deflate' http://localhost:8080/restlet/sayHello
  HTTP/1.1 200 OK
  Vary: Accept-Encoding
  Content-Type: text/plain;charset=UTF-8
  Date: Tue, 06 Nov 2012 09:24:01 GMT
  Accept-Ranges: bytes
  Server: Restlet-Framework/2.1.0
  Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
  Content-Length: 12
  </code></pre>