-1

I`m trying to request to web-service by jersey client:

WebResource service = client.resource(UriBuilder.fromUri("http://localhost:8080/jersey-example-new/").build());
System.out.println(service.path("rs/").path("account/details/1").accept(MediaType.APPLICATION_JSON).get(String.class));

but I get:

GET http://localhost:8080/jersey-example-new/rs/account/details/1 returned a response status of 406 Not Acceptable

Please, note that url path http://localhost:8080/jersey-example-new/rs/account/details/1 works in browser. What is wrong with java client request?

the endpoint code:

@Path("account")
public class AccountDetailsService {

    @GET
    @Path("/details/{param}")
    @Produces(MediaType.TEXT_PLAIN)
    public Response getAccountDetails(@PathParam("param") String accountName) {
        String output = "Account Name : " + accountName;
        return Response.status(200).entity(output).build();
    }
}
andy007
  • 907
  • 1
  • 15
  • 41

1 Answers1

1

You should change

System.out.println(service.path("rs/").path("account/details/1").accept(MediaType.APPLICATION_JSON).get(String.class));

to System.out.println(service.path("rs/").path("account/details/1").accept(MediaType.TEXT_PLAIN).get(String.class));

You are only producing TEXT_PLAIN, but you request the media-type APPLICATION_JSON (via accept header), this is why you get the response, that the request is not acceptable.

burna
  • 2,932
  • 18
  • 27