You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by heikki <tr...@gmail.com> on 2013/06/25 01:03:49 UTC

Is it possible to change MarkupStream ?

hello,

I'm using Wicket 1.5.9. I'm trying to do some string manipulation in a
MarkupStream, like this:

    @Override
    public IMarkupFragment getMarkup() {
        IMarkupFragment fragment = super.getMarkup();
        return manipulate(fragment);
    }

    protected IMarkupFragment manipulate(IMarkupFragment fragment) throws
Exception {
        MarkupResourceStream markupStream =
fragment.getMarkupResourceStream();
        InputStream is = markupStream.getInputStream();
        String x = getStringFromInputStream(is);
        //
        // do some string manipulation here on string x
        //
        return createMarkupFragmentFromString(x);
    }

    protected IMarkupFragment createMarkupFragmentFromString(String s) {
        IResourceStream resourceStream = new StringResourceStream(s);
        MarkupResourceStream markupStream = new
MarkupResourceStream(resourceStream);
        IMarkupFragment fragment = new Markup(markupStream);
        return fragment;
    }

Unit tests for those last two methods work fine; but when I run it in a
Wicket application, I get a

IOException: stream already closed.

Does anyone have an idea what is going wrong, and how could I achieve this?

Kind regards
Heikki Doeleman



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Is-it-possible-to-change-MarkupStream-tp4659757.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Is it possible to change MarkupStream ?

Posted by heikki <tr...@gmail.com>.
No,

I used Firefox 21.0, with the app running in Tomcat 6.

Any ideas, anyone ?
thanks
Heikki Doeleman



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Is-it-possible-to-change-MarkupStream-tp4659757p4659832.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Is it possible to change MarkupStream ?

Posted by Paul Bors <pa...@bors.ws>.
Let me guess, you used IE9 or IE10 in what web app server?
GlassFish by any chance?


On Tue, Jun 25, 2013 at 7:36 AM, heikki <tr...@gmail.com> wrote:

> hi,
>
> the stacktrace is here: http://pastebin.com/Kgba3zxF.
>
> I noticed I did not supply the code of getStringFromInputStream() -- I took
> it from
> http://www.mkyong.com/java/how-to-convert-inputstream-to-string-in-java/and
> it is
>
>     protected static String getStringFromInputStream(InputStream is) {
>         BufferedReader br = null;
>         StringBuilder sb = new StringBuilder();
>         String line;
>         try {
>             br = new BufferedReader(new InputStreamReader(is));
>             while ((line = br.readLine()) != null) {
>                 sb.append(line);
>             }
>         }
>         catch (IOException e) {
>             e.printStackTrace();
>         }
>         finally {
>             if (br != null) {
>                 try {
>                     br.close();
>                 }
>                 catch (IOException e) {
>                     e.printStackTrace();
>                 }
>             }
>         }
>         return sb.toString();
>     }
>
> Can you see why I get java.io.IOException: Stream Closed ?
>
> thanks,
> Heikki Doeleman
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Is-it-possible-to-change-MarkupStream-tp4659757p4659769.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Is it possible to change MarkupStream ?

Posted by heikki <tr...@gmail.com>.
hi,

the stacktrace is here: http://pastebin.com/Kgba3zxF.

I noticed I did not supply the code of getStringFromInputStream() -- I took
it from
http://www.mkyong.com/java/how-to-convert-inputstream-to-string-in-java/ and
it is

    protected static String getStringFromInputStream(InputStream is) {
        BufferedReader br = null;
        StringBuilder sb = new StringBuilder();
        String line;
        try {
            br = new BufferedReader(new InputStreamReader(is));
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            if (br != null) {
                try {
                    br.close();
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return sb.toString();
    }

Can you see why I get java.io.IOException: Stream Closed ?

thanks,
Heikki Doeleman



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Is-it-possible-to-change-MarkupStream-tp4659757p4659769.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Is it possible to change MarkupStream ?

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Please paste the stack trace of the exception so we can see how you use
these methods.
A new MarkupStream is created for each rendering of a page. It is being
closed at the end of the rendering.


On Tue, Jun 25, 2013 at 2:03 AM, heikki <tr...@gmail.com> wrote:

> hello,
>
> I'm using Wicket 1.5.9. I'm trying to do some string manipulation in a
> MarkupStream, like this:
>
>     @Override
>     public IMarkupFragment getMarkup() {
>         IMarkupFragment fragment = super.getMarkup();
>         return manipulate(fragment);
>     }
>
>     protected IMarkupFragment manipulate(IMarkupFragment fragment) throws
> Exception {
>         MarkupResourceStream markupStream =
> fragment.getMarkupResourceStream();
>         InputStream is = markupStream.getInputStream();
>         String x = getStringFromInputStream(is);
>         //
>         // do some string manipulation here on string x
>         //
>         return createMarkupFragmentFromString(x);
>     }
>
>     protected IMarkupFragment createMarkupFragmentFromString(String s) {
>         IResourceStream resourceStream = new StringResourceStream(s);
>         MarkupResourceStream markupStream = new
> MarkupResourceStream(resourceStream);
>         IMarkupFragment fragment = new Markup(markupStream);
>         return fragment;
>     }
>
> Unit tests for those last two methods work fine; but when I run it in a
> Wicket application, I get a
>
> IOException: stream already closed.
>
> Does anyone have an idea what is going wrong, and how could I achieve this?
>
> Kind regards
> Heikki Doeleman
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Is-it-possible-to-change-MarkupStream-tp4659757.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>