【问题标题】:i am not able to read the entity message from javax.ws.rs.core.Response in java client我无法从 java 客户端中的 javax.ws.rs.core.Response 读取实体消息
【发布时间】:2013-09-24 07:03:43
【问题描述】:

嗨,我在 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

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

【问题讨论】:

    标签: java jax-rs restful-authentication


    【解决方案1】:

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

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

    您是否尝试过阅读此信息流?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-23
      • 2011-05-27
      • 2016-03-18
      • 2015-06-02
      相关资源
      最近更新 更多