简体   繁体   中英

Simple JAX-RS Client - Issue with Jersey

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM