0

嗨,我在 apache tomee 中使用 jax-rs 创建了 restful 服务器和客户端。我正在从服务器返回状态和实体,我正在读取成功,但我无法从响应对象中读取实体。

这是我在服务器端 Rest 中的代码。

@Path("/login")
@POST
public javax.ws.rs.core.Response login(String user,@Context HttpServletRequest  request,@Context HttpServletResponse response)throws ServletException, IOException 
{
    int sc=200;
    //this above status code i am changing base on the error
    return  javax.ws.rs.core.Response.status(sc).entity("error on server side").type(MediaType.TEXT_PLAIN).build();
}

我创建了用于在 java 中调用上述服务的客户端

   Response response=WebClient.create("http://myserver:8080/Snefocare").path("/User/login").post(user);
System.out.println("the status is "+response.getStatus());          
System.out.println("the metadata is "+response.getEntity());
System.out.println("the entity "+response.getEntity());   

上述代码的输出

    the status is 200
    the metadata is sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@294c4c55
    the entity sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@294c4c55

我不知道为什么实体以其他格式打印。

4

1 回答 1

0

响应实体是一个InputStream,从这一行应该很明显;

the entity sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@294c4c55

您是否尝试过阅读此流?

于 2013-09-19T09:28:50.740 回答