LStrike
LStrike

Reputation: 1648

Javax REST Response entity = null

I am using javax to create a REST service to send an Java Object from one system to another.

I send the data like follows:

WebTarget wt = client.target(baseUrl.toString()).path(restUrlSuffix);
response = wt.request(MediaType.APPLICATION_JSON).post(Entity.json(transferJSON));

I defined a method which should receive the entity as a JSON:

@POST
@Path("/post")
@Consumes("application/json")
@Produces("application/json")
public Response saveWorkflowDefinition(@Valid String json) {
    .....
    .....
    String message = "Message to return";
    Response res = Response.ok(message).build();
    return res;
}

With this method everything is fine. Data arrives as JSON, colud be transformed back to my java class and I can work with the object again.

Also it seems, that the Response is correct. If I debug my code, the response is properly filled.

But on the side where I want to receive this response and check it, the entity part is empty.

I have no idea why?

Screen 1 is my response before sending it: enter image description here

Screen 2 is the response after receiving it: enter image description here

Upvotes: 3

Views: 2345

Answers (1)

LStrike
LStrike

Reputation: 1648

I found a solution. I had to add a "valid" readEntity to my WebTarget request. I my case I have written a response object, maybe a String.class might work too. I need my response class later in my code to transfer some more detailed information.

response = wt.request(MediaType.APPLICATION_JSON).post(Entity.json(transferJSON)).readEntity(WFResponse.class);

Upvotes: 2

Related Questions