简体   繁体   English

简单的JAX-RS客户端-球衣问题

[英]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. 我想创建一个简单的项目,以使该项目与我在泽西岛创建的Web服务之间建立连接。

My web service have the following service : 我的Web服务具有以下服务:

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). 我想创建一个具有12345(字符串)客户编号的应用程序。 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. 您的服务产生XML响应。 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. 您将需要告诉客户端接受XML响应。 You have to call the service as follows: 您必须按以下方式致电服务:

javax.ws.rs.core.Response rs = target.request(MediaType.APPLICATION_XML).get();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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