title: Issue calling RESTFul Web Service from Client using Jersey
body: <p>I am trying to learn RESTFul web services using Jersey and following <a href="http://www.vogella.com/articles/REST/article.html" rel="nofollow">this example</a>. I have created a sample service which is accessible at:</p>
  
  <pre><code>    http://localhost:8080/de.vogella.jersey.first/rest/hello. 
  </code></pre>
  
  <p>I have created a client which calls this service but when I run this client I get an exception as follows:</p>
  
  <pre><code>   GET http://localhost:8080/de.vogella.jersey.first/rest/hello 
       returned a response status of 404 Not Found Exception in thread "main"  
     com.sun.jersey.api.client.UniformInterfaceException: 
       GET http://localhost:8080/de.vogella.jersey.first/rest/hello 
         returned a response status of 404 Not Found
  at com.sun.jersey.api.client.WebResource.handle(WebResource.java:686)
  at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
  at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:507)
  at de.vogella.jersey.first.client.Test.main(Test.java:23)
  </code></pre>
  
  <p>Service class is </p>
  
  <pre class="lang-java prettyprint-override"><code>public class Hello {
  
    // This method is called if TEXT_PLAIN is request
    @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;";
    }
  
    // This method is called if HTML is request
    @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;/body&gt;&lt;/h1&gt;" + "&lt;/html&gt; ";
    }
  }
  </code></pre>
  
  <p>Client Code:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Test {
    public static void main(String[] args) {
      ClientConfig config = new DefaultClientConfig();
      Client client = Client.create(config);
      WebResource service = client.resource(getBaseURI());
      System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_PLAIN).get(ClientResponse.class).toString());  
      System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_XML).get(String.class));        
      private static URI getBaseURI() {
      return UriBuilder.fromUri("http://localhost:8080/de.vogella.jersey.first").build();
    }
  } 
  </code></pre>
  
  <p>The strange part is, I can get the right result if I hit      </p>
  
  <pre><code>    http://localhost:8080/de.vogella.jersey.first/rest/hello 
  </code></pre>
  
  <p>from browser. Any help to resolve this issue is appreciated.
  Thanks</p>