Package spark.servlet
Class SparkFilter
- java.lang.Object
-
- spark.servlet.SparkFilter
-
- All Implemented Interfaces:
javax.servlet.Filter
public class SparkFilter extends java.lang.Object implements javax.servlet.Filter
Filter that can be configured to be used in a web.xml file. Needs the init parameter 'applicationClass' set to the application class where the adding of routes should be made.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
APPLICATION_CLASS_PARAM
private SparkApplication[]
applications
It contains all the Spark application instances that was declared in the filter configuration.private java.lang.String
filterPath
private static org.slf4j.Logger
LOG
private MatcherFilter
matcherFilter
-
Constructor Summary
Constructors Constructor Description SparkFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
destroy()
void
doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
protected SparkApplication
getApplication(java.lang.String applicationClassName)
Returns an instance ofSparkApplication
which on whichinit()
will be called.protected SparkApplication
getApplication(javax.servlet.FilterConfig filterConfig)
Deprecated.UsegetApplications(FilterConfig)
instead.protected SparkApplication[]
getApplications(javax.servlet.FilterConfig filterConfig)
Returns the instances ofSparkApplication
which on whichinit()
will be called.void
init(javax.servlet.FilterConfig filterConfig)
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
APPLICATION_CLASS_PARAM
public static final java.lang.String APPLICATION_CLASS_PARAM
- See Also:
- Constant Field Values
-
filterPath
private java.lang.String filterPath
-
matcherFilter
private MatcherFilter matcherFilter
-
applications
private SparkApplication[] applications
It contains all the Spark application instances that was declared in the filter configuration. They can be one or more class names separated by commas.
-
-
Method Detail
-
init
public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
- Specified by:
init
in interfacejavax.servlet.Filter
- Throws:
javax.servlet.ServletException
-
getApplication
@Deprecated protected SparkApplication getApplication(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
Deprecated.UsegetApplications(FilterConfig)
instead.Returns an instance ofSparkApplication
which on whichinit()
will be called. Default implementation looks up the class name in the filterConfig using the key "applicationClass". Subclasses can override this method to use different techniques to obtain an instance (i.e. dependency injection).- Parameters:
filterConfig
- the filter configuration for retrieving parameters passed to this filter.- Returns:
- the spark application containing the configuration.
- Throws:
javax.servlet.ServletException
- if anything went wrong.
-
getApplication
protected SparkApplication getApplication(java.lang.String applicationClassName) throws javax.servlet.ServletException
Returns an instance ofSparkApplication
which on whichinit()
will be called. Default implementation looks up the class name in the filterConfig using the key "applicationClass". Subclasses can override this method to use different techniques to obtain an instance (i.e. dependency injection).- Parameters:
applicationClassName
- the spark application class name passed to this filter.- Returns:
- the spark application containing the configuration.
- Throws:
javax.servlet.ServletException
- if anything went wrong.
-
getApplications
protected SparkApplication[] getApplications(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
Returns the instances ofSparkApplication
which on whichinit()
will be called. Default implementation looks up the class names in the filterConfig using the key "applicationClass". Subclasses can override this method to use different techniques to obtain an instance (i.e. dependency injection).- Parameters:
filterConfig
- the filter configuration for retrieving parameters passed to this filter.- Returns:
- the spark applications containing the configuration.
- Throws:
javax.servlet.ServletException
- if anything went wrong.
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException
- Specified by:
doFilter
in interfacejavax.servlet.Filter
- Throws:
java.io.IOException
javax.servlet.ServletException
-
destroy
public void destroy()
- Specified by:
destroy
in interfacejavax.servlet.Filter
-
-