سؤال

I'd like to create a simple project to have a connection between this project and a web service I created in Jersey.

My web service have the following service :

http://localhost:8080/esinister/test/findtest?testnumber=12345. 

The definition of this service is :

@GET
@Path("findtest")
@Produces(MediaType.APPLICATION_XML)
public Customer findTest(@DefaultValue("") @QueryParam("testnumber") String clientNumber)

I'd like to create an application to have the Customer number 12345 (String). How I can create this ?

I started my application on this way ...

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:8080/esinister/test/findtest?testnumber=12345");
    javax.ws.rs.core.Response rs = target.request(MediaType.TEXT_PLAIN).get();
    System.out.println(rs.toString());
}

But I think I forgot something ...

My error is :

InboundJaxrsResponse{ClientResponse{method=GET, uri= http://localhost:8080/esinister/test/findtest?testnumber=12345, status=406, reason=Inacceptable}}

Have you got an idea ?

هل كانت مفيدة؟

المحلول

Your service produces XML response. The client is not able to read this because you have set the response type in the client as plain text. You will need to tell the client to accept XML response. You have to call the service as follows:

javax.ws.rs.core.Response rs = target.request(MediaType.APPLICATION_XML).get();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top