sahaya / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

ResponseLoggingFilter changes xml response #199

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Version: 1.6.3-SNAPSHOT

Problem: RsponseLoggingFilter changes the response instead of just logging it

What steps will reproduce the problem?

1. Activate ResponseLoggingFilter: RestAssured.filters(new 
ResponseLoggingFilter());
2. e.g. run a test which calls a server which returns xml
3. the xml is changed such that e.g. dates cannot be parsed correctly

Example:

Reponse from server is:

<a>
  <b>2012-12-31</b>
</a>

With logging on the response will be

<a>
  <b>
    2012-12-31
  </b>
</a>

If a date parser is used which is not lenient then the date cannot be parsed.

After investigating this specific example I found that the logger is using the 
XmlNodePrinter to generate the prettified xml output. This class has a flag 
'preserveWhiteSpace'. If its turned on this specific problem for xml seems to 
be fixed because no newlines will be inserted.

In general I think that a logger should never change the actual response.

Original issue reported on code.google.com by the...@gmail.com on 7 Sep 2012 at 10:52

GoogleCodeExporter commented 9 years ago
I tried this approach but now I'm getting a nullpointerexception in the 
findContentType method of the RestAssuredResponseImpl.

Looking at the log I see this (among things)

Content-Type=application/xml
Content-Length=2391

What I got from the server was

Content-Type: application/xml
Content-Length: 2391

So it looks like the response headers are also broken.

Original comment by the...@gmail.com on 7 Sep 2012 at 11:05

GoogleCodeExporter commented 9 years ago
It's true that the logger, by default, changes the response because 
pretty-printing is enabled. If you log using: 

expect().log().body(false) instead then pretty printing will not be used and 
the response should be left intact on logging. You can also configure this for 
each request by using "detailed logging configuration" (see 
https://code.google.com/p/rest-assured/wiki/Usage#Detailed_configuration and 
http://rest-assured.googlecode.com/svn/tags/1.6.2/apidocs/com/jayway/restassured
/config/LogConfig.html).

Original comment by johan.ha...@gmail.com on 10 Sep 2012 at 6:33

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 7 Mar 2014 at 11:18