0

hi i created the restful server and client using jax-rs in apache tomee.i am returning status and entity from server and i am reading successful but i am not able to read the entity from response object.

This is my code in server side 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();
}

i created client for invoking the above service in 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());   

output of above code

    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

i do not know why entity is printing in some other formate.

user2549122
  • 203
  • 1
  • 5
  • 18

1 Answers1

0

The response entity is an InputStream, which should be obvious from this line;

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

Have you tried reading this stream?

Qwerky
  • 18,217
  • 6
  • 44
  • 80