简体   繁体   中英

Build Response Entity without sending it

I have the following situation: In my spring application I make a request to another web service. This web service sends me a ResponseEntity back. Now I have modified the ResponseEntity this worked perfectly, except that I cannot build a new ResponseEntity, I don't know why. Can someone tell me how to build a new ResponseEntity?

Thats my code:

 JsonNode modifiedBody = //body
 HttpHeaders modifiedHeader = //header
 HttpEntity<Object> newResponse = new HttpEntity<>(modifiedBody, modifiedHeader);

 //until this point everything works perfect now I want to create a new ResponseEntity without calling a webservice
 ResponseEntity<Object> entity = //MAKE NEW RESPONSE ENTITY

Can someone please tell me how to make a new response entity without sending it? Thanks in advance.

Edit: Disappearing value:

在此处输入图片说明

If I look in the debugger I find the value. But in the next step its gone.

在此处输入图片说明

As simple as that:

ResponseEntity<Object> entity = ResponseEntity
                .status(200) // status
                .headers(...)
                .body(...); // maybe some body

Please note that you cannot pass HttpEntity there, so you must set headers and body through these static methods as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM