body(InputStream) does not work
See original GitHub issueThe same error as reported fixed in the closed issue https://github.com/rest-assured/rest-assured/issues/1040.
I am using rest-assured
4.3.3 (the version is forced by the newest Spring Boot 2.5.0).
My code:
class MyTest {
@Value("classpath:/valid-request.xml")
private Resource validRequest;
....
@Test
void myTest() {
given()
.header("Content-Type", "text/xml; charset=UTF-8")
.header("SOAPAction", "myService")
.body(validRequest.getInputStream()) // this does not work
// .body(validRequest.getFile()) // this works
.when()
.post("/myApi")
.then()
.log().ifValidationFails()
.statusCode(200)
.contentType("text/xml")
;
}
}
Rest-assured interprets the InputStream
as an Object and cannot handle it.
However, when I replace getInputStream()
with getFile()
, it works.
Error message:
java.io.BufferedInputStream@6ceb953
2021-06-11 17:35:47.083 ERROR [,628aa0b986fe0c98,628aa0b986fe0c98] 11428 --- [o-auto-1-exec-1] com.sun.xml.messaging.saaj.soap : SAAJ0511: Unable to create envelope from given source
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
java - InputStream doesn't work - Stack Overflow
Yes, you should expect that. BufferedReader is for text streams, it will translate the binary input to characters (e.g. UTF-8). But it shows ......
Read more >Is it better not to .close() inside API method body when passed ...
Here: if Reader or InputStream gets passed as a parameter to a method of an API, then do not .close() on it inside...
Read more >Have a method that returns java.io.InputStream for body content
getBodyContent().getInputStream() ) does not work. The method will return null regardless of the type of response given by an API. The reason ...
Read more >Read an InputStream using the Java Server Socket - Baeldung
Learn how to read data from a Java Server Socket.
Read more >Java InputStream - Jenkov.com
The Java InputStream is a byte based stream of data you can read from. ... means that there are no more bytes to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I observed the same issue using restAssured. It seems that it’s calling .toString() somewhere on the inputStream and sending the string instead of the contents of the InputStream…
Issue, described by snowbldr still persists in 4.5.1. Instead of sending content of InputStream, current implementation sends a name of Java object.