java.lang.IllegalStateException: STREAMED - Consuming JSON fails

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

java.lang.IllegalStateException: STREAMED - Consuming JSON fails

Tate Jones
Hi Group,

I am new to Wicket and I am attempting to read some JSON data posted from a wicket page.

The following exception occurs with Wicket 1.4.18 and Jetty 6.1.x when attempting to read the servlet request - BufferedReader br = hsr.getReader().

Sep 28, 2011 8:50:48 AM org.apache.wicket.RequestCycle logRuntimeException
SEVERE: STREAMED
java.lang.IllegalStateException: STREAMED
        at org.mortbay.jetty.Request.getReader(Request.java:935)
        at tunechipsapp.web.pages.LoginPage$2.onRequest(LoginPage.java:64)
        at org.apache.wicket.request.target.component.listener.BehaviorRequestTarget.processEvents(BehaviorRequestTarget.java:157)
        at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
        at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1252)
        at org.apache.wicket.RequestCycle.step(RequestCycle.java:1331)
        at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1438)
        at org.apache.wicket.RequestCycle.request(RequestCycle.java:546)
        at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
        at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:319)
        at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
        at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)

The code was source from https://cwiki.apache.org/WICKET/how-to-handle-jqueryajax-json-request-.html

   AbstractAjaxBehavior ajaxSaveBehaviour = new AbstractAjaxBehavior() {
            private static final long serialVersionUID = 1L;

            @SuppressWarnings("unchecked")
            public void onRequest() {
                log.info("***** onRequest *****");

                //get parameters
                final RequestCycle requestCycle = RequestCycle.get();

                WebRequest wr = (WebRequest) requestCycle.getRequest();

                HttpServletRequest hsr = wr.getHttpServletRequest();

                try {
                    BufferedReader br = hsr.getReader();  <<< Exception

                    String jsonString = br.readLine();
                    if ((jsonString == null) || jsonString.isEmpty()) {
                        log.error(" no json found");
                    } else {
                        log.info(" json  is :" + jsonString);
                    }


                } catch (IOException ex) {
                    log.error(ex.toString());
                }

                // json string to retir to the jQuery onSuccess function
                String data = "{}";

                log.info("returning json :" + data);
                IRequestTarget t = new StringRequestTarget("application/json", "UTF-8", data);
                getRequestCycle().setRequestTarget(t);
                //requestCycle.setRequestTarget(new StringRequestTarget("application/json", "utf-8", data));
            }
        };
        add(ajaxSaveBehaviour);
 
I have read some posts about this in different forms (eg. pushing content), but I haven't found a solution at this point.

Cheers in advance
Tate
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException: STREAMED - Consuming JSON fails

Martin Grigorov-4
This exception says "Don't use the reader but use the input stream
because something (maybe header) has been already read from the
stream".

On Wed, Sep 28, 2011 at 10:59 AM, Tate Jones <[hidden email]> wrote:

> Hi Group,
>
> I am new to Wicket and I am attempting to read some JSON data posted from a wicket page.
>
> The following exception occurs with Wicket 1.4.18 and Jetty 6.1.x when attempting to read the servlet request - BufferedReader br = hsr.getReader().
>
> Sep 28, 2011 8:50:48 AM org.apache.wicket.RequestCycle logRuntimeException
> SEVERE: STREAMED
> java.lang.IllegalStateException: STREAMED
>        at org.mortbay.jetty.Request.getReader(Request.java:935)
>        at tunechipsapp.web.pages.LoginPage$2.onRequest(LoginPage.java:64)
>        at org.apache.wicket.request.target.component.listener.BehaviorRequestTarget.processEvents(BehaviorRequestTarget.java:157)
>        at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
>        at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1252)
>        at org.apache.wicket.RequestCycle.step(RequestCycle.java:1331)
>        at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1438)
>        at org.apache.wicket.RequestCycle.request(RequestCycle.java:546)
>        at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
>        at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:319)
>        at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
>        at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
>
> The code was source from https://cwiki.apache.org/WICKET/how-to-handle-jqueryajax-json-request-.html
>
>   AbstractAjaxBehavior ajaxSaveBehaviour = new AbstractAjaxBehavior() {
>            private static final long serialVersionUID = 1L;
>
>            @SuppressWarnings("unchecked")
>            public void onRequest() {
>                log.info("***** onRequest *****");
>
>                //get parameters
>                final RequestCycle requestCycle = RequestCycle.get();
>
>                WebRequest wr = (WebRequest) requestCycle.getRequest();
>
>                HttpServletRequest hsr = wr.getHttpServletRequest();
>
>                try {
>                    BufferedReader br = hsr.getReader();  <<< Exception
>
>                    String jsonString = br.readLine();
>                    if ((jsonString == null) || jsonString.isEmpty()) {
>                        log.error(" no json found");
>                    } else {
>                        log.info(" json  is :" + jsonString);
>                    }
>
>
>                } catch (IOException ex) {
>                    log.error(ex.toString());
>                }
>
>                // json string to retir to the jQuery onSuccess function
>                String data = "{}";
>
>                log.info("returning json :" + data);
>                IRequestTarget t = new StringRequestTarget("application/json", "UTF-8", data);
>                getRequestCycle().setRequestTarget(t);
>                //requestCycle.setRequestTarget(new StringRequestTarget("application/json", "utf-8", data));
>            }
>        };
>        add(ajaxSaveBehaviour);
>
> I have read some posts about this in different forms (eg. pushing content), but I haven't found a solution at this point.
>
> Cheers in advance
> Tate



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException: STREAMED - Consuming JSON fails

Tate Jones
Cheers.

Changed the call to.

                    BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                                    hsr.getInputStream()));


On 28/09/2011, at 7:03 PM, Martin Grigorov wrote:

> This exception says "Don't use the reader but use the input stream
> because something (maybe header) has been already read from the
> stream".
>
> On Wed, Sep 28, 2011 at 10:59 AM, Tate Jones <[hidden email]> wrote:
>> Hi Group,
>>
>> I am new to Wicket and I am attempting to read some JSON data posted from a wicket page.
>>
>> The following exception occurs with Wicket 1.4.18 and Jetty 6.1.x when attempting to read the servlet request - BufferedReader br = hsr.getReader().
>>
>> Sep 28, 2011 8:50:48 AM org.apache.wicket.RequestCycle logRuntimeException
>> SEVERE: STREAMED
>> java.lang.IllegalStateException: STREAMED
>>        at org.mortbay.jetty.Request.getReader(Request.java:935)
>>        at tunechipsapp.web.pages.LoginPage$2.onRequest(LoginPage.java:64)
>>        at org.apache.wicket.request.target.component.listener.BehaviorRequestTarget.processEvents(BehaviorRequestTarget.java:157)
>>        at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
>>        at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1252)
>>        at org.apache.wicket.RequestCycle.step(RequestCycle.java:1331)
>>        at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1438)
>>        at org.apache.wicket.RequestCycle.request(RequestCycle.java:546)
>>        at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
>>        at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:319)
>>        at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
>>        at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
>>
>> The code was source from https://cwiki.apache.org/WICKET/how-to-handle-jqueryajax-json-request-.html
>>
>>   AbstractAjaxBehavior ajaxSaveBehaviour = new AbstractAjaxBehavior() {
>>            private static final long serialVersionUID = 1L;
>>
>>            @SuppressWarnings("unchecked")
>>            public void onRequest() {
>>                log.info("***** onRequest *****");
>>
>>                //get parameters
>>                final RequestCycle requestCycle = RequestCycle.get();
>>
>>                WebRequest wr = (WebRequest) requestCycle.getRequest();
>>
>>                HttpServletRequest hsr = wr.getHttpServletRequest();
>>
>>                try {
>>                    BufferedReader br = hsr.getReader();  <<< Exception
>>
>>                    String jsonString = br.readLine();
>>                    if ((jsonString == null) || jsonString.isEmpty()) {
>>                        log.error(" no json found");
>>                    } else {
>>                        log.info(" json  is :" + jsonString);
>>                    }
>>
>>
>>                } catch (IOException ex) {
>>                    log.error(ex.toString());
>>                }
>>
>>                // json string to retir to the jQuery onSuccess function
>>                String data = "{}";
>>
>>                log.info("returning json :" + data);
>>                IRequestTarget t = new StringRequestTarget("application/json", "UTF-8", data);
>>                getRequestCycle().setRequestTarget(t);
>>                //requestCycle.setRequestTarget(new StringRequestTarget("application/json", "utf-8", data));
>>            }
>>        };
>>        add(ajaxSaveBehaviour);
>>
>> I have read some posts about this in different forms (eg. pushing content), but I haven't found a solution at this point.
>>
>> Cheers in advance
>> Tate
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]