title: Jersey2 Client throwing javax.ws.rs.NotFoundException
body: <p>I have written a sample REST service using Jersey2.</p>
  
  <p>Here is my web.xml:</p>
  
  <pre><code>&lt;web-app&gt;
    &lt;display-name&gt;jerseysample&lt;/display-name&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;javax.ws.rs.Application&lt;/param-name&gt;
              &lt;param-value&gt;com.adaequare.rest.config.JerseyResourceInitializer&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Here is my sample class:</p>
  
  <pre><code>package com.adaequare.resource;
  
  import javax.ws.rs.Consumes;
  import javax.ws.rs.GET;
  import javax.ws.rs.PUT;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  
  @Path("/hello")
  public class Hello {
      @GET
      @Produces(MediaType.TEXT_HTML)
      public String sayHtmlHello(){
          return "&lt;html&gt;&lt;title&gt;Hello Jersey&lt;/title&gt;&lt;body&gt;&lt;h1&gt;Hello Jersey&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;";
      }
  
      @GET
      @Produces(MediaType.TEXT_PLAIN)
      public String sayPlainTextHello() {
          return "Hello Jersey";
      }
  
      // This method is called if XML is request
      @GET
      @Produces(MediaType.TEXT_XML)
      public String sayXMLHello() {
          return "&lt;?xml version=\"1.0\"?&gt;" + "&lt;hello&gt; Hello Jersey" + "&lt;/hello&gt;";
      }
  
  }
  </code></pre>
  
  <p>I have deployed it to Tomcat and am able to access the following URL:</p>
  
  <pre class="lang-none prettyprint-override"><code>http://localhost:8080/jerseysample/rest/hello
  </code></pre>
  
  <p>I tried writing a unit test this way:</p>
  
  <pre><code>package com.adaequare.client;
  
  public class MyResourceTest {
      public static final URI BASE_URI = UriBuilder.fromUri("http://localhost").port(8080).build();
      private HttpServer server;
      private WebTarget target;
  
      @Before
      public void setUp() throws Exception {
  
          ResourceConfig rc = new ResourceConfig(Hello.class);
          server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, rc);
  
          server.start();
          Client c = ClientBuilder.newClient();
          target = c.target(BASE_URI);
      }
  
      @After
      public void tearDown() throws Exception {
          server.shutdownNow();
      }
  
  
      @Test
      public void testGetIt() {
          String responseMsg = target.path("jerseysample").path("rest").path("hello").request().get(String.class);
          System.out.println("I am here");
          assertEquals("Got it!", responseMsg);
      }
  }
  </code></pre>
  
  <p>This class also throws the exception.</p>
  
  <p>On executing this class, I am getting the following exception:</p>
  
  <pre><code>Exception in thread "main" javax.ws.rs.NotFoundException: HTTP 404 Not Found
      at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:917)
      at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:770)
      at org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:90)
      at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:671)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:423)
      at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:667)
      at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:396)
      at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:296)
      at com.adaequare.client.TestClient.main(TestClient.java:14)
  </code></pre>
  
  <p>I am sure I am missing some configuration stuff. I have browsed to see the root cause of the issue but to no avail. Can someone please let me know if I am missing something?</p>