How to get response body in Zuul post filter?

Dariusz Mydlarz

How it is possible to read a response body while using Zuul as a proxy in post filter?

I am trying to call the code like this:

@Component
public class PostFilter extends ZuulFilter {

    private static final Logger log = LoggerFactory.getLogger(PostFilter.class);

    @Override
    public String filterType() {
        return "post";
    }

    @Override
    public int filterOrder() {
        return 2000;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext ctx = RequestContext.getCurrentContext();
        ctx.getResponseBody(); // null

        // cant't do this, cause input stream is used later in other filters and I got InputStream Closed exception
        // GZIPInputStream gzipInputStream = new GZIPInputStream(stream);
        return null;
    }

}
Dariusz Mydlarz

I've managed to overcome this. The solution consists of 4 steps:

  1. Read ctx.getResponseDataStream() into a ByteArrayOutputStream
  2. Copy OutputStream to 2 InputStreams.
  3. Use one of it for your custom purposes.
  4. Use the second to reassign to context: context.setResponseBody(inputStream)
    • reading stream from point 1 would cause that the stream cannot be read again, so this way you're passing a new fresh stream that wasn't read yet

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Guzzlehttp - How get the body of a response from Guzzle 6?

From Java

How to get response body with request.send() in dart

From Java

How to get body / json response from XHR request with Puppeteer

From Dev

How to get Response after POST in AngularJS?

From Dev

Spring: How to get parameters from POST body?

From Dev

Parsing the body of a post response, Java

From Dev

How to get Response Body when Server responds with 302 in Grails?

From Dev

How to get response body to retrofit exception?

From Dev

How to alter the body of a http response in a filter

From Dev

How to get response headers and body in dispatch request?

From Dev

Jersey response logging filter excluding response body for GET

From Dev

How get response body on php guzzle?

From Dev

WebApi get the post raw body inside a filter

From Dev

How to get the response of form with POST method by cURL?

From Dev

How to get full post body using symfony?

From Dev

Stream the response body of an HTTP GET to an HTTP POST with Ruby

From Dev

How to get response object from POST request?

From Dev

php - how to get the server response header and body

From Dev

how to get the response body in code webtest?

From Dev

How would i get a specific variable in response body after a POST request

From Dev

How to send post data and retrieve the response body in android?

From Dev

How to alter the body of a http response in a filter

From Dev

How to get response from API after POST

From Dev

Processing GET Body with Zuul

From Dev

Slim 3 How to get the Post mothod body

From Dev

how can I write netflix zuul filter to change response location header attribute?

From Dev

How to transform POST body response to get the elements?

From Dev

How can I send data as a POST with a JSON body, and navigate to the response?

From Dev

Android retrofit response body, jwt in response, how do to get it?

Related Related

  1. 1

    Guzzlehttp - How get the body of a response from Guzzle 6?

  2. 2

    How to get response body with request.send() in dart

  3. 3

    How to get body / json response from XHR request with Puppeteer

  4. 4

    How to get Response after POST in AngularJS?

  5. 5

    Spring: How to get parameters from POST body?

  6. 6

    Parsing the body of a post response, Java

  7. 7

    How to get Response Body when Server responds with 302 in Grails?

  8. 8

    How to get response body to retrofit exception?

  9. 9

    How to alter the body of a http response in a filter

  10. 10

    How to get response headers and body in dispatch request?

  11. 11

    Jersey response logging filter excluding response body for GET

  12. 12

    How get response body on php guzzle?

  13. 13

    WebApi get the post raw body inside a filter

  14. 14

    How to get the response of form with POST method by cURL?

  15. 15

    How to get full post body using symfony?

  16. 16

    Stream the response body of an HTTP GET to an HTTP POST with Ruby

  17. 17

    How to get response object from POST request?

  18. 18

    php - how to get the server response header and body

  19. 19

    how to get the response body in code webtest?

  20. 20

    How would i get a specific variable in response body after a POST request

  21. 21

    How to send post data and retrieve the response body in android?

  22. 22

    How to alter the body of a http response in a filter

  23. 23

    How to get response from API after POST

  24. 24

    Processing GET Body with Zuul

  25. 25

    Slim 3 How to get the Post mothod body

  26. 26

    how can I write netflix zuul filter to change response location header attribute?

  27. 27

    How to transform POST body response to get the elements?

  28. 28

    How can I send data as a POST with a JSON body, and navigate to the response?

  29. 29

    Android retrofit response body, jwt in response, how do to get it?

HotTag

Archive