> hi,guys:
> these days i am reviewing the code of the portlet filter. the portlet
> filter in pluto2.0 is so different from the servlet filter.
> everytime a filter is called, it initialed, doFilter,and then destroyed.
> take the action filter for example, we may find the code in the
> org.apache.pluto.driver.services.container.FilterChainImpl
>  public void doFilter(ActionRequest request, ActionResponse response)
> throws IOException, PortletException {
> ...
>     ActionFilter filter = (ActionFilter)
> loader.loadClass(filterDD.getFilterClass()).newInstance();
>     FilterConfigImpl filterConfig = new
> FilterConfigImpl(filterDD.getFilterName(),filterDD.getInitParam(),portletContext);
>     filter.init(filterConfig);
>     filter.doFilter(request, response, this);
>     filter.destroy();
> ...
> }
>
>
> But it isn't like that in servlet filter. so i writer a servlet filter,
> public class TestServletFilter implements Filter {
>  private int i;
>  public void init(FilterConfig arg0) throws ServletException {
>   i = 0;
>   System.out.println("TestServletFilter init...");
>  }
>  public void destroy() {
>   System.out.println("TestServletFilter destroy...");
>  }
>  public void doFilter(ServletRequest arg0, ServletResponse arg1,
>    FilterChain arg2) throws IOException, ServletException {
>   i++;
>   System.out.println("TestServletFilter msg\t="+i);
>  }
> }
>
>
> then i get the output from the console
> TestServletFilter msg   =1
> TestServletFilter msg   =2
> TestServletFilter msg   =3
> TestServletFilter msg   =4
> TestServletFilter msg   =5
>  also i write a portlet filter,and the output is
> TestPortletFilter:      TestPortletFilter init...
> TestPortletFilter Render iRender=1
> TestPortletFilter:      destroy iRender=1
> TestPortletFilter:      TestPortletFilter init...
> TestPortletFilter Render iRender=1
> TestPortletFilter:      destroy iRender=1
> TestPortletFilter:      TestPortletFilter init...
> TestPortletFilter Render iRender=1
> TestPortletFilter:      destroy iRender=1
>
>
> why portlet filter in pluto is different from the servlet filter?
>
>
>
>
> Liang, Yan
> Technology Center of Software Engineering
> Institute of Software, Chinese Academy of Sciences
> P.O.Box 8718, Beijing 100190, P.R.China
>
> Email: [EMAIL PROTECTED]
> Mobile: (+86)13810249268
> 2008-07-15
>

>From a design perspective, portlet filters are a combination of Chain of
Responsibility and Flyweight patterns.  Without re-reading the spec, since
filters are flyweights, I'm sure is probably legal for the filter instance
to be init'd and destroy'd for every request, as long as it is available
at the right point in the chain (same for portlet instances).  Just like
with servlet programming, instance variables for portlets and filters
violate the flyweight pattern, and the outcome is indeterminate.

That being said, there is certainly a better implementation.  Note however
that the filter implementation is pushed out to the portal implementor,
and the Pluto project is really about the portlet container, not the
portal implementation.

Am I wrong on this?  I can't verify the spec right now because the JCP
site is not working.

Maybe you could provide patch for a better implementation?

-- Ben

Reply via email to