question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

body(InputStream) does not work

See original GitHub issue

The 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
snowbldrcommented, Sep 9, 2021

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…

1reaction
fedinskiycommented, Mar 21, 2022

Issue, described by snowbldr still persists in 4.5.1. Instead of sending content of InputStream, current implementation sends a name of Java object.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found