title: Jersey returning 404, after invoking the correct @Path
body: <p>This thing is puzzling me already for quite some time..
      I am trying to embed a Jersey container within Jetty. Following the examples I am able to embed Jersey, and I see my exposed REST method is being exposed. however, for some weird reason my Jersey does return a 404. It looks like Jersey is not capable to resolve the correct endpoint. Unfortunately it doesn't tell me why, but just throws a NotFoundException :-(.</p>
  
  <p>I am 100% certain my method is invoked. The System.out.println within that method is shown in the console, and my Eclipse debugger clearly passes the set breakpoint. It doesn't matter whether I use Jersey 2.0, 2.3, 2.4,1, 2.4. All have the same result.. Here the code snippets of my configuration:</p>
  
  <p><strong>StartJetty.java</strong> :</p>
  
  <pre><code>        final int mainport = 9123;
  
          Server jettyServer = new Server(mainport);
          HandlerCollection handlerCollection = new ContextHandlerCollection();
          jettyServer.setHandler(handlerCollection);
  
          ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/");
          jerseyServlet.setInitOrder(1);
          jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "com.test.rest");
  
          handlerCollection.addHandler(context);
      jettyServer.start();
          jettyServer.join();
  </code></pre>
  
  <p><strong>Snippet from the REST resource:</strong>
      com.test.rest.PersonsRSImpl.class:</p>
  
  <pre><code>@Path("/persons")
  @Produces( MediaType.APPLICATION_JSON)
  public class PersonsRSImpl {
  
      private PersonManager personMgr = PersonManager.getInstance();
  
  
      @Path("/list")
      public Collection&lt;Person&gt; list() {
          System.out.println("In Person::list" );
          return personMgr.getPersons();
      }
  
  
  }
  </code></pre>
  
  <p>My Person object is a simple POJO, with some JAXB annotations. Adding/removing them makes no difference at all.</p>
  
  <p>Last but not least:
   <strong>pom.xml</strong>
      
      http://maven.apache.org/maven-v4_0_0.xsd"></p>
  
  <pre><code>    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.test&lt;/groupId&gt;
      &lt;artifactId&gt;integrationexample&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;Test project&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.build.outputEncoding&gt;UTF-8&lt;/project.build.outputEncoding&gt;
          &lt;jetty.version&gt;7.5.4.v20111024&lt;/jetty.version&gt;
          &lt;jersey.version&gt;2.4.1&lt;/jersey.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jetty-server&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-servlet&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-http-spi&lt;/artifactId&gt;
              &lt;version&gt;${jetty.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Jersey JAX-RS --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-servlet&lt;/artifactId&gt;
              &lt;version&gt;${jersey.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-simple-http&lt;/artifactId&gt;
              &lt;version&gt;${jersey.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-media-moxy&lt;/artifactId&gt;
              &lt;version&gt;${jersey.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.11&lt;/version&gt;
              &lt;scope&gt;test&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;plugin&gt;
                  &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;archive&gt;
                          &lt;manifest&gt;
                              &lt;mainClass&gt;com.test.StartJetty&lt;/mainClass&gt;
                          &lt;/manifest&gt;
                      &lt;/archive&gt;
                      &lt;descriptorRefs&gt;
                          &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
                      &lt;/descriptorRefs&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;make-assembly&lt;/id&gt;
                          &lt;phase&gt;package&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;single&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>I enabled a trace of Jersey (thank you Michal). The result trace is:</p>
  
  <p><strong>Jersey trace</strong></p>
  
  <pre><code>HTTP/1.1 404 Not Found
  X-Jersey-Tracing-000: START       [ ---- /  ---- ms |  ---- %] baseUri=[http://localhost:9123/rest/] requestUri=[http://localhost:9123/rest/persons/list] method=[GET] authScheme=[n/a] accept=[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8] accept-encoding=[gzip, deflate] accept-charset=n/a accept-language=[en-US,en;q=0.5] content-type=n/a content-length=n/a
  X-Jersey-Tracing-001: PRE-MATCH   [ 0,01 /  1,03 ms |  0,10 %] PreMatchRequest summary: 0 filters
  X-Jersey-Tracing-002: MATCH       [ ---- /  1,21 ms |  ---- %] Matching path [/persons/list]
  X-Jersey-Tracing-003: MATCH       [ ---- /  1,27 ms |  ---- %] Pattern [/persons(/.*)?] IS selected
  X-Jersey-Tracing-004: MATCH       [ ---- /  1,41 ms |  ---- %] Matched resource: template=[/persons] regexp=[/persons(/.*)?] matches=[/persons] from=[/persons/list]
  X-Jersey-Tracing-005: MATCH       [ ---- /  1,54 ms |  ---- %] Matching path [/list]
  X-Jersey-Tracing-006: MATCH       [ ---- /  1,58 ms |  ---- %] Pattern [/list(/.*)?] IS selected
  X-Jersey-Tracing-007: MATCH       [ ---- /  1,76 ms |  ---- %] Matched resource: template=[/list] regexp=[/list(/.*)?] matches=[/list] from=[/list]
  X-Jersey-Tracing-008: MATCH       [ ---- /  1,90 ms |  ---- %] Matched locator : public java.util.Collection com.test.rest.PersonsRSImpl.list()
  X-Jersey-Tracing-009: MATCH       [ ---- /  2,08 ms |  ---- %] Resource instance: [com.test.rest.PersonsRSImpl @3cceafcb]
  X-Jersey-Tracing-010: MATCH       [ ---- /  2,21 ms |  ---- %] Resource instance: [java.util.HashMap$Values @25591d82]
  X-Jersey-Tracing-011: MATCH       [ 4,23 /  5,30 ms | 75,92 %] RequestMatching summary
  X-Jersey-Tracing-012: RESP-FILTER [ 0,00 /  5,52 ms |  0,05 %] Response summary: 0 filters
  X-Jersey-Tracing-013: FINISHED    [ ---- /  5,58 ms |  ---- %] Response status: 404/CLIENT_ERROR|Not Found
  Cache-Control: must-revalidate,no-cache,no-store
  Content-Type: text/html;charset=ISO-8859-1
  Content-Length: 1284
  Server: Jetty(7.5.4.v20111024)
  </code></pre>
  
  <p>Hope some of you have a clue on what's going on!</p>