Read response body in JAX-RS client from a post request

user2657714

Having some sort of proxy between a mobile app and a web-service, we are puzzled by the response when issuing a post request. We receive response with status 200: OK. But we can not find/extract the JSON response body.

    Client client = ClientBuilder.newClient();
    WebTarget webTarget = client.target(WEBSERVICE_BASE_LOCATION + "mobileDevices?operatorCode=KPNSCP");
    String jsonString = "{\"osVersion\":\"4.1\",\"apiLevel\":16,\"devicePlatform\":\"ANDROID\"}";
    Builder builder = webTarget.request();
    Response response = builder.post(Entity.json(jsonString));

We are using JAX-RS. Can someone please provide some hints to extract the JSON body (String) from the server response?

Juned Ahsan

Try this:

String output = response.getEntity(String.class);

EDIT

Thanks to @Martin Spamer to mention that it will work for Jersey 1.x jars only. For Jersey 2.x use

String output = response.readEntity(String.class);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to log request body in JAX-RS client

From Dev

Ember POST request responding with XML jersey response in JAX-RS

From Dev

How to read body from POST request

From Dev

Postman client not able to parse string response from JAX-RS response builder

From Dev

Read Map entity in JAX-RS client

From Dev

JAX-RS / Jersey : Change response body from Jackson JSON errors

From Dev

JAX-RS (Jersey): String from JSON request body still escaped

From Java

How to get post body data from java jax-rs server

From Dev

Retrieving String from JAX-RS Response

From Dev

Read response body in async request

From Dev

Read HTTP response header and body from one HTTP request in java

From Dev

return custom error codes to client in the response for a JAX-RS

From Dev

Handling custom error response in JAX-RS 2.0 client library

From Dev

Java jax-rs client response entity generic

From Dev

Prevent Tomcat from interfering with Jersey/JAX-RS 2 Response Body on HTTP Error Status 4xx or 5xx

From Dev

Logging request and response in one place with JAX-RS

From Dev

jax-rs Jersey @Post Response entity is empty

From Dev

JAX-RS response.getEntity returns null after post

From Dev

Jersey/JAX-RS Client throwing 400 Bad Request

From Dev

Setting request timeout for JAX-RS 2.0 Client API

From Dev

Sending response to client from within the request.post callback in koa

From Dev

POST using JAX-RS 2.0 Client API

From Dev

POST using JAX-RS 2.0 Client API

From Dev

Write to response body waits for client to read in Go?

From Dev

Handling redirect Response from a Restful or JAX-RS web service

From Dev

JAX-RS 2.0 - How to get entity from Response object

From Dev

Jax-RS : extracting specific header from head call response?

From Dev

Feign Client + Eureka POST request body

From Dev

Download file from REST service using JAX-RS client

Related Related

  1. 1

    How to log request body in JAX-RS client

  2. 2

    Ember POST request responding with XML jersey response in JAX-RS

  3. 3

    How to read body from POST request

  4. 4

    Postman client not able to parse string response from JAX-RS response builder

  5. 5

    Read Map entity in JAX-RS client

  6. 6

    JAX-RS / Jersey : Change response body from Jackson JSON errors

  7. 7

    JAX-RS (Jersey): String from JSON request body still escaped

  8. 8

    How to get post body data from java jax-rs server

  9. 9

    Retrieving String from JAX-RS Response

  10. 10

    Read response body in async request

  11. 11

    Read HTTP response header and body from one HTTP request in java

  12. 12

    return custom error codes to client in the response for a JAX-RS

  13. 13

    Handling custom error response in JAX-RS 2.0 client library

  14. 14

    Java jax-rs client response entity generic

  15. 15

    Prevent Tomcat from interfering with Jersey/JAX-RS 2 Response Body on HTTP Error Status 4xx or 5xx

  16. 16

    Logging request and response in one place with JAX-RS

  17. 17

    jax-rs Jersey @Post Response entity is empty

  18. 18

    JAX-RS response.getEntity returns null after post

  19. 19

    Jersey/JAX-RS Client throwing 400 Bad Request

  20. 20

    Setting request timeout for JAX-RS 2.0 Client API

  21. 21

    Sending response to client from within the request.post callback in koa

  22. 22

    POST using JAX-RS 2.0 Client API

  23. 23

    POST using JAX-RS 2.0 Client API

  24. 24

    Write to response body waits for client to read in Go?

  25. 25

    Handling redirect Response from a Restful or JAX-RS web service

  26. 26

    JAX-RS 2.0 - How to get entity from Response object

  27. 27

    Jax-RS : extracting specific header from head call response?

  28. 28

    Feign Client + Eureka POST request body

  29. 29

    Download file from REST service using JAX-RS client

HotTag

Archive