Friday, August 24, 2012

Struts2 Json: java.lang.IllegalStateException: STREAM


I recently got an uncomfortable exception in struts2 I could not resolve easily. The exception "java.lang.IllegalStateException: STREAM"  'suddenly' started appearing, and broke my ajax-requests. After some fiddling, I found that I had included one to many property in my action-super-class: servletRequest. A getter on this property made the JSONWriter try to parse the whole servletRequest to json, leading to a crash with java.lang.IllegalStateException: STREAM.

The solution for me was to add servletRequest to the excludeProperties-property in my struts-config:


<action class="personSearchAction" method="getPerson" name="personSearchApi">
            <result type="json">
                <param name="ignoreHierarchy" />false
                <param name="excludeProperties" />
                    servletRequest, actionErrors,actionMessages
            </result>
</action>