ro.isdc.wro.http
Class WroFilter

java.lang.Object
  extended by ro.isdc.wro.http.WroFilter
All Implemented Interfaces:
javax.servlet.Filter
Direct Known Subclasses:
ConfigurableWroFilter

public class WroFilter
extends Object
implements javax.servlet.Filter

Main entry point. Perform the request processing by identifying the type of the requested resource. Depending on the way it is configured.

Author:
Alex Objelean

Constructor Summary
WroFilter()
           
 
Method Summary
protected  void configureDefaultHeaders(Map<String,String> map)
          Deprecated. use WroFilter#newResponseHeaderConfigurer() and ResponseHeadersConfigurer.configureDefaultHeaders(Map)
 void destroy()
          
 void doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)
          
protected  void doInit(javax.servlet.FilterConfig config)
          Custom filter initialization - can be used for extended classes.
 WroConfiguration getConfiguration()
           
protected  MBeanServer getMBeanServer()
          Override this method if you want to provide a different MBeanServer.
 WroManagerFactory getWroManagerFactory()
           
 void init(javax.servlet.FilterConfig config)
          
protected  String newMBeanName()
           
protected  RequestHandlerFactory newRequestHandlerFactory()
           
protected  ResponseHeadersConfigurer newResponseHeadersConfigurer()
           
protected  ObjectFactory<WroConfiguration> newWroConfigurationFactory(javax.servlet.FilterConfig filterConfig)
           
protected  WroManagerFactory newWroManagerFactory()
          Factory method for WroManagerFactory.
protected  void onException(Exception e, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain)
          Invoked when a Exception is thrown.
protected  void onRequestProcessed()
          Useful for unit tests to check the post processing.
protected  void onRuntimeException(RuntimeException e, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain)
          Deprecated. use onException(Exception, HttpServletResponse, FilterChain)
 void setConfiguration(WroConfiguration config)
          Once set, this configuration will be used, instead of the one built by the factory.
 void setEnable(boolean enable)
          Sets the enable flag used to toggle filter.
 void setRequestHandlerFactory(RequestHandlerFactory requestHandlerFactory)
          Sets the RequestHandlerFactory used to create the collection of requestHandlers
protected  void setResponseHeaders(javax.servlet.http.HttpServletResponse response)
          Method called for each request and responsible for setting response headers, used mostly for cache control.
 void setWroManagerFactory(WroManagerFactory wroManagerFactory)
          Allows external configuration of WroManagerFactory (ex: using spring IoC).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WroFilter

public WroFilter()
Method Detail

init

public final void init(javax.servlet.FilterConfig config)
                throws javax.servlet.ServletException

Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException

newMBeanName

protected String newMBeanName()
Returns:
the name of MBean to be used by JMX to configure wro4j.

getMBeanServer

protected MBeanServer getMBeanServer()
Override this method if you want to provide a different MBeanServer.

Returns:
MBeanServer to use for JMX.

newResponseHeadersConfigurer

protected ResponseHeadersConfigurer newResponseHeadersConfigurer()
Returns:
the ResponseHeadersConfigurer.

newRequestHandlerFactory

protected RequestHandlerFactory newRequestHandlerFactory()
Returns:
default implementation of RequestHandlerFactory

configureDefaultHeaders

@Deprecated
protected void configureDefaultHeaders(Map<String,String> map)
Deprecated. use WroFilter#newResponseHeaderConfigurer() and ResponseHeadersConfigurer.configureDefaultHeaders(Map)

Allow configuration of default headers. This is useful when you need to set custom expires headers.

Parameters:
map - the Map where key represents the header name, and value - header value.

doInit

protected void doInit(javax.servlet.FilterConfig config)
               throws javax.servlet.ServletException
Custom filter initialization - can be used for extended classes.

Throws:
javax.servlet.ServletException
See Also:
Filter.init(FilterConfig).

doFilter

public final void doFilter(javax.servlet.ServletRequest req,
                           javax.servlet.ServletResponse res,
                           javax.servlet.FilterChain chain)
                    throws IOException,
                           javax.servlet.ServletException

Specified by:
doFilter in interface javax.servlet.Filter
Throws:
IOException
javax.servlet.ServletException

onException

protected void onException(Exception e,
                           javax.servlet.http.HttpServletResponse response,
                           javax.servlet.FilterChain chain)
Invoked when a Exception is thrown. Allows custom exception handling. The default implementation redirects to 404 WroRuntimeException is thrown when in DEPLOYMENT mode.

Parameters:
e - Exception thrown during request processing.

onRuntimeException

@Deprecated
protected void onRuntimeException(RuntimeException e,
                                             javax.servlet.http.HttpServletResponse response,
                                             javax.servlet.FilterChain chain)
Deprecated. use onException(Exception, HttpServletResponse, FilterChain)

Invoked when a RuntimeException is thrown. Allows custom exception handling. The default implementation redirects to 404 for a specific WroRuntimeException exception when in DEPLOYMENT mode.

Parameters:
e - RuntimeException thrown during request processing.

setResponseHeaders

protected void setResponseHeaders(javax.servlet.http.HttpServletResponse response)
Method called for each request and responsible for setting response headers, used mostly for cache control. Override this method if you want to change the way headers are set.

Parameters:
response - HttpServletResponse object.

setWroManagerFactory

public void setWroManagerFactory(WroManagerFactory wroManagerFactory)
Allows external configuration of WroManagerFactory (ex: using spring IoC). When this value is set, the default WroManagerFactory initialization won't work anymore.

Note: call this method before init(FilterConfig) is invoked.

Parameters:
wroManagerFactory - the wroManagerFactory to set

getWroManagerFactory

public final WroManagerFactory getWroManagerFactory()
Returns:
configured and decorated WroManagerFactory instance.

setRequestHandlerFactory

public void setRequestHandlerFactory(RequestHandlerFactory requestHandlerFactory)
Sets the RequestHandlerFactory used to create the collection of requestHandlers

Parameters:
requestHandlerFactory - to set

newWroManagerFactory

protected WroManagerFactory newWroManagerFactory()
Factory method for WroManagerFactory.

Creates a WroManagerFactory configured in WroConfiguration using reflection. When no configuration is found a default implementation is used.

Note: this method is not invoked during initialization if a WroManagerFactory is set using setWroManagerFactory(WroManagerFactory).

Returns:
WroManagerFactory instance.

newWroConfigurationFactory

protected ObjectFactory<WroConfiguration> newWroConfigurationFactory(javax.servlet.FilterConfig filterConfig)
Returns:
implementation of ObjectFactory used to create a WroConfiguration object.

getConfiguration

public final WroConfiguration getConfiguration()
Returns:
the WroConfiguration associated with this filter instance.

setConfiguration

public final void setConfiguration(WroConfiguration config)
Once set, this configuration will be used, instead of the one built by the factory.

Parameters:
config - a not null WroConfiguration to set.

setEnable

public void setEnable(boolean enable)
Sets the enable flag used to toggle filter. This might be useful when the filter has to be enabled/disabled based on environment configuration.

Parameters:
enable - flag for enabling the WroFilter.

onRequestProcessed

protected void onRequestProcessed()
Useful for unit tests to check the post processing.


destroy

public void destroy()

Specified by:
destroy in interface javax.servlet.Filter


Copyright © 2008-2013. All Rights Reserved.