2

I am getting following Error: java.lang.IllegalStateException: getInputStream() has already been called for this request while implementing JSON with Struts2. Exception:

org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: 
    java.lang.reflect.InvocationTargetException
        org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:230)
        org.apache.struts2.json.JSONWriter.process(JSONWriter.java:160)
        org.apache.struts2.json.JSONWriter.value(JSONWriter.java:126)
        org.apache.struts2.json.JSONWriter.write(JSONWriter.java:94)
        org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:115)
        org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
        org.apache.struts2.json.JSONResult.execute(JSONResult.java:170)
        com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374)
    ...........

java.lang.IllegalStateException: getInputStream() has already been called for this request


org.apache.catalina.connector.Request.getReader(Request.java:1242)
    org.apache.catalina.connector.RequestFacade.getReader(RequestFacade.java:506)
    javax.servlet.ServletRequestWrapper.getReader(ServletRequestWrapper.java:212)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:210)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:160)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:126)
    org.apache.struts2.json.JSONWriter.add(JSONWriter.java:355)
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:215)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:160)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:126)
    org.apache.struts2.json.JSONWriter.write(JSONWriter.java:94)
    org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:115)
    org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
    org.apache.struts2.json.JSONResult.execute(JSONResult.java:170)

.........

Kindly help me with this Error as I am stuck with this issue I have few question: I have implemented ServletRequestAware and using the same to get the userLocale. Is it conflicting with the JSONWriter Object.

Coder
  • 6,948
  • 13
  • 56
  • 86
Mithil Shukla
  • 113
  • 3
  • 8

1 Answers1

5

I'm assuming that you are using the 2.x version of Struts, I faced the same issue and found one existing bug with Struts - explained here

Actually, any action that is RequestAware or SessionAware does the auto binding of session and request. I removed my getter of request from action and things started working fine.

Ashish
  • 3,572
  • 3
  • 18
  • 25