Search code examples
grailsgroovy

at grails.converters.XML.parse(XML.java:340) ~[grails-plugin-converters-3.0.17.jar:3.0.17]


I implement a end point in my grails controller and try to pass xml data with postman

request.withFormat {
                xml {
                    println("Inside Xml")
                    // render "The XML Title Is ${request.XML.userId}."
                    println("XML: " + request.XML) // exception in this line
                }
}

at grails.converters.XML.parse(XML.java:340) ~[grails-plugin-converters-3.0.17.jar:3.0.17]

Caused by: java.io.IOException: Stream closed
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at grails.converters.XML.parse(XML.java:337)

I am using grails version 3.0.17

request.JSON is working fine but it throws error on request.XML

Below is the filters present on my controller

[pattern: '/demo/requests/**', filters: 'anonymousAuthenticationFilter,restTokenValidationFilter,restExceptionTranslationFilter,filterInvocationInterceptor'],

Solution

  • If you have something that is reading the body of the request before your request.withFormat method is invoked, that would explain the "Stream closed" error.

    Common examples of that include a filter or interceptor in your app that is ready the body of the request before your controller action executes, and if the controller action accepts a command object, the body of the request has to be read before your code executes.