Your service is mapped to (and you are saying you can access it): http://localhost:8080/jerseysample/rest/hello
but using your client you are calling http://localhost:8080/restserver/rest/hello
which is different URL. What is the surprise?
Try
WebTarget target = ClientBuilder.newClient().target("http://localhost:8080/jerseysample/rest/").path("hello");
As for the second test, try calling getUri() on your WebTarget to see what URL you are actually calling, it should help you see where is the problem.
After your update:
Well first thing is, you haven't specified (in terms of content negotiation) what content your client accepts (you did this in your previous example, which you deleted). But that should not be a problem since in that case server should send you any of implemented ones since by not specifying it you are stating you are supporting all kind of responses. But the problem probably is putting String.class
into get()
method. There should go an entity you want Jersey to transform the response into. If you want to get String I would do something like this:
Response response = target.path("jerseysample").path("rest").path("hello").
request().get();
StringWriter responseCopy = new StringWriter();
IOUtils.copy((InputStream) response.getEntity(), responseCopy);
But you can't tell for sure which one of your three method is going to be called since it is on the same PATH, so you should also specify the content by passing it to request
method.