开发者

Seam and ServletOutputStream - flush is not immediately visible

I am converting a 6 year old application to Seam 2.2. The application is used to run in java 1.4 and weblogic 8. It only uses jsp and servlet. In one servlet I use:

    public void doGet (HttpServletRequest req,HttpServletResponse res) throws  ServletException,IOException
        {
            //...

            ServletOutputStream out = = res.getOutputStream();

            // displaying a lot of messages
            // after each println() I do a flush()
            out.println("lots of messages.....");
            out.flush();

            out.close(); 
            //...
        } 

When running the application the messages were immediately seen in the browser.

When I run this using Seam 2.2 in Weblogic 10 and Java 1.6 the messages are not immediately seen in the browser. Only when the servlet is finished running.

Can I change something to fix this?

I do not want to change/convert the servlet into a Seam component. The servlet is running fine. The only thing is the flushing of messages to the browser window which only happens after the servlet has stopped running.

Could it be that the reason is that the servlet now goes through the Seam filter:

<filter>
  <filter-name>Seam Filter</filter-name>
  <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
开发者_如何学JAVA
<filter-mapping>
  <filter-name>Seam Filter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>


The reason is probably that the request goes through the SeamFilter, as you supposed. I think it's not the SeamFilter itself that buffer the data stream from your servlet but the Ajax4Jsf filter that is invoked in the filter chain.

If you have RichFaces in the classpath there is a seam component that registers the Ajax4jsf filter in the chain. Namely, the Seam component is org.jboss.seam.web.ajax4jsfFilter.

If you don't need RichFaces try removing it from the classpath. If you need it, I suggest that you override org.jboss.seam.web.ajax4jsfFilter in order to skip the Ajax4Jsf filter for requests directed to your servlet.

Another possible solution is converting your servlet in a filter as a Seam component (see @Filter annotation) and positioning it at the beginning of the chain with the around attribute. Something like:

@Name("FormerServlet")
@Scope(STATELESS)
@BypassInterceptors
@Filter(around = "org.jboss.seam.web.ajax4jsfFilterInstantiator")
public class FormerServletFilter implements Filter
{

    protected void init(FilterConfig filterConfig) throws Exception
    {
    }


    protected void doDestroy()
    {
    }

    /**
     * Performs the filtering for a request.
     */
    protected void doFilter(final HttpServletRequest request, final HttpServletResponse response,
                            final FilterChain chain) throws Exception
    {
        if (thisRequestShoudBeManagedByMyServlet(request) )
        {
           // do here what you previously did in the servlet

        } else
        {
            // go ahead with the Seam lifecycle
            chain.doFilter(request, response);
        }
    }


You're running a servlet - there's nothing to do with Seam here. I suspect you need to re-evaluate your design, as there's not really an exact translation from servlet to Seam structure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜