You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Konstantin Kolinko <kn...@gmail.com> on 2010/06/01 05:31:17 UTC

Re: slow servlet filter for ByteArrayOutputStream response Wrapper

2010/6/1 Manny Mondeo <ma...@yahoo.com>:
> Hi ,
> I have written a filter that strips the response of some html tags.
> The filter is working and executing around 30milliseconds.

How do you measure the time?

> The problem is that the request takes around 30 seconds to load this in a browser. The filter gets executed fast but the status bar in the browser does not complete and the page gets struck to about 25 seconds before the response comes and gets rendered.

Maybe it loads images, loads and executes javascript, or maybe your
HTML is invalid. Maybe you have a firewall that scans your traffic for
malware. Have you tried it with a different browser?

>      String content = new String(c);

The above line is wrong. Use some explicit encoding.

>                  StringBuffer buffer = new StringBuffer();

java.lang.StringBuilder may be a bit faster (though it is unlikely
that you will notice).

>          //PrintWriter out = httpRes.getWriter();
>          PrintWriter out = wrapp.getWriter();

Why wrapp.getWriter(); ??

>          httpRes.setContentLength(content.toString().length());
>          httpRes.setContentType( "text/html; charset=UTF-8" ) ;

You cannot set charset when you already called getWriter(). Move the
above line higher in the code.

>             public PrintWriter getWriter()
>             {
>                 if (writer == null)
>                 {
>                     try
>                     {
>                         writer = new PrintWriter(new OutputStreamWriter(outputStream, this.getCharacterEncoding()));

The above will throw an exception if outputStream is null.

Best regards,
Konstantin Kolinko

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