本文整理汇总了Java中org.apache.tomcat.util.descriptor.web.FilterDef类的典型用法代码示例。如果您正苦于以下问题:Java FilterDef类的具体用法?Java FilterDef怎么用?Java FilterDef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FilterDef类属于org.apache.tomcat.util.descriptor.web包,在下文中一共展示了FilterDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deployConfig
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
@Override
public void deployConfig(WebApplicationContext wac, Filter... filters) {
Assert.state(this.port != -1, "setup() was never called.");
this.context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
this.context.addApplicationListener(WsContextListener.class.getName());
Tomcat.addServlet(this.context, "dispatcherServlet", new DispatcherServlet(wac)).setAsyncSupported(true);
this.context.addServletMapping("/", "dispatcherServlet");
for (Filter filter : filters) {
FilterDef filterDef = new FilterDef();
filterDef.setFilterName(filter.getClass().getName());
filterDef.setFilter(filter);
filterDef.setAsyncSupported("true");
this.context.addFilterDef(filterDef);
FilterMap filterMap = new FilterMap();
filterMap.setFilterName(filter.getClass().getName());
filterMap.addURLPattern("/*");
filterMap.setDispatcher("REQUEST,FORWARD,INCLUDE,ASYNC");
this.context.addFilterMap(filterMap);
}
}
示例2: dispatchFilter
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
private FilterDef dispatchFilter(String name, String type)
{
FilterDef filterDef = new FilterDef();
filterDef.setFilterName(name);
filterDef.setFilterClass(RequestDispatchFilter.class.getName());
filterDef.addInitParameter("dispatcher", type);
return filterDef;
}
示例3: filterDef
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
/**
* 定义一个过滤器
* @param className 过滤器的全路径
* @return
*/
protected FilterDef filterDef(String className) {
FilterDef def = new FilterDef();
def.setAsyncSupported("true");
def.setFilterClass(className);
def.setFilterName(className);
return def;
}
示例4: setUpTomcat
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
public static void setUpTomcat(String dataSourceFactory) throws LifecycleException, ServletException {
// create a tomcat instance
tomcat = new Tomcat();
tomcat.setBaseDir(".");
tomcat.setPort(0);
tomcat.enableNaming();
// create a context with our test servlet
Context ctx = tomcat.addContext(CONTEXT_PATH, new File(".").getAbsolutePath());
Tomcat.addServlet(ctx, SERVLET_NAME, new TestServlet());
ctx.addServletMappingDecoded("/*", SERVLET_NAME);
// add our metrics filter
FilterDef def = new FilterDef();
def.setFilterClass(TomcatServletMetricsFilter.class.getName());
def.setFilterName("metricsFilter");
def.addInitParameter("buckets",".01, .05, .1, .25, .5, 1, 2.5, 5, 10, 30");
ctx.addFilterDef(def);
FilterMap map = new FilterMap();
map.setFilterName("metricsFilter");
map.addURLPattern("/*");
ctx.addFilterMap(map);
// create a datasource
ContextResource resource = new ContextResource();
resource.setName("jdbc/db");
resource.setAuth("Container");
resource.setType("javax.sql.DataSource");
resource.setScope("Sharable");
resource.setProperty("name", "foo");
resource.setProperty("factory", dataSourceFactory);
resource.setProperty("driverClassName", "org.h2.Driver");
resource.setProperty("url", "jdbc:h2:mem:dummy");
resource.setProperty("jdbcInterceptors", "nl.nlighten.prometheus.tomcat.TomcatJdbcInterceptor(logFailed=true,logSlow=true,threshold=0,buckets=.01|.05|.1|1|10,slowQueryBuckets=1|10|30)");
ctx.getNamingResources().addResource(resource);
// start instance
tomcat.init();
tomcat.start();
}
示例5: readForwardRootControllerUrisSetting
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
/**
* SCIPIO: Reads the forwardRootControllerUris value from ContextFilter init-params from webXml,
* trying to find the most appropriate setting.
*/
public static Boolean readForwardRootControllerUrisSetting(WebXml webXml, String logPrefix) {
// HEURISTIC: we return the value of the highest-rated ContextFilter that
// has forwardRootControllerUris present in its init-params (even if empty)
int bestRating = 0;
String aliasStr = null;
String filterName = null;
for(FilterDef filter : webXml.getFilters().values()) {
int currentRating = rateContextFilterCandidate(filter);
if (currentRating > 0) {
Map<String, String> initParams = filter.getParameterMap();
if (initParams != null && initParams.containsKey("forwardRootControllerUris")) {
if (currentRating > bestRating) {
bestRating = currentRating;
aliasStr = initParams.get("forwardRootControllerUris");
filterName = filter.getFilterName();
}
}
}
}
if (bestRating > 0) {
Boolean alias = UtilMisc.booleanValueVersatile(aliasStr);
if (alias != null) {
if (logPrefix != null) Debug.logInfo(logPrefix+"Found web.xml ContextFilter (filter name '" + filterName + "') init-param forwardRootControllerUris boolean value: " + alias, module);
return alias;
} else {
if (UtilValidate.isNotEmpty(aliasStr)) {
if (logPrefix != null) Debug.logError(logPrefix+"web.xml ContextFilter (filter name '" + filterName + "') init-param forwardRootControllerUris has invalid boolean value: " + aliasStr, module);
} else {
if (logPrefix != null) Debug.logInfo(logPrefix+"Found web.xml ContextFilter (filter name '" + filterName + "') init-param forwardRootControllerUris, was empty; returning as unset", module);
return null;
}
}
} else {
if (logPrefix != null) Debug.logInfo(logPrefix+"web.xml ContextFilter init-param forwardRootControllerUris setting not found", module);
}
return null;
}
示例6: rateContextFilterCandidate
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
/**
* Heuristic for finding the most probable real ContextFilter.
* NOTE: This is a problem because OFbiz frustratingly made a bunch of other classes
* extend ContextFilter, and even scipio is forced to compound the problem as a result
* of lack of good base classes.
* @return a value between 0-5, 5 being best candidate
*/
public static int rateContextFilterCandidate(FilterDef filter) {
String filterClass = filter.getFilterClass();
if (filterClass == null || filterClass.isEmpty()) return 0;
// NOTE: this exact-class check is what stock code does for some other classes, so we have to follow suit
if (ContextFilter.class.getName().equals(filterClass)) return 5;
try {
Class<?> filterCls = Thread.currentThread().getContextClassLoader().loadClass(filterClass);
if (!ContextFilter.class.isAssignableFrom(filterCls)) return 0;
} catch(Exception e) {
Debug.logWarning("Could not load or test filter class (" + filterClass + "); may be invalid or a classloader issue: "
+ e.getMessage(), module);
return 0;
}
String filterName = filter.getFilterName();
if (contextFilterClassName.equals(filterName)) return 4;
if (filterName != null && filterName.contains(contextFilterClassName)) {
if (filterClass.contains(contextFilterClassName)) return 3;
} else {
if (filterClass.contains(contextFilterClassName)) return 2;
}
// 1: at least is subclass, but lowest because stock Ofbiz overextended ContextFilter everywhere
return 1;
}
示例7: setupContext
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
protected void setupContext() throws ServletException {
Context context = tomcat.addWebapp("/", ".");
Tomcat.addServlet(context, "dummy", new DummyServlet());
context.addServletMappingDecoded("/dummy", "dummy");
FilterDef filterDef = new FilterDef();
filterDef.setDisplayName("ipBlocker");
filterDef.setFilter(new IpBlockerFilter());
filterDef.setFilterName("ipBlocker");
context.addFilterDef(filterDef);
FilterMap filterMap = new FilterMap();
filterMap.addURLPattern("/*");
filterMap.setFilterName("ipBlocker");
context.addFilterMap(filterMap);
}
示例8: getApplicationFilterMaps
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
@Override
public List<FilterMapping> getApplicationFilterMaps(Context context) {
FilterMap[] fms = context.findFilterMaps();
List<FilterMapping> filterMaps = new ArrayList<>(fms.length);
for (FilterMap filterMap : fms) {
if (filterMap != null) {
String dm;
switch (filterMap.getDispatcherMapping()) {
case FilterMap.ASYNC:
dm = "ASYNC";
break;
case FilterMap.ERROR:
dm = "ERROR";
break;
case FilterMap.FORWARD:
dm = "FORWARD";
break;
case FilterMap.INCLUDE:
dm = "INCLUDE";
break;
case FilterMap.REQUEST:
dm = "REQUEST";
break;
default:
dm = "";
}
String filterClass = "";
FilterDef fd = context.findFilterDef(filterMap.getFilterName());
if (fd != null) {
filterClass = fd.getFilterClass();
}
List<FilterMapping> filterMappings = getFilterMappings(filterMap, dm, filterClass);
filterMaps.addAll(filterMappings);
}
}
return filterMaps;
}
示例9: getApplicationFilters
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
@Override
public List<FilterInfo> getApplicationFilters(Context context) {
FilterDef[] fds = context.findFilterDefs();
List<FilterInfo> filterDefs = new ArrayList<>(fds.length);
for (FilterDef filterDef : fds) {
if (filterDef != null) {
FilterInfo fi = getFilterInfo(filterDef);
filterDefs.add(fi);
}
}
return filterDefs;
}
示例10: getFilterInfo
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
/**
* Gets the filter info.
*
* @param fd the fd
* @return the filter info
*/
private static FilterInfo getFilterInfo(FilterDef fd) {
FilterInfo fi = new FilterInfo();
fi.setFilterName(fd.getFilterName());
fi.setFilterClass(fd.getFilterClass());
fi.setFilterDesc(fd.getDescription());
return fi;
}
示例11: applicationFilters
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
/**
* Application filters.
*/
@Test
public void applicationFilters() {
Assert.assertNotNull(new Expectations() {
{
context.findFilterDefs();
result = new FilterDef();
}
});
final Tomcat80ContainerAdapter adapter = new Tomcat80ContainerAdapter();
assertEquals(1, adapter.getApplicationFilters(context).size());
}
示例12: applicationFilters
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
/**
* Application filters.
*/
@Test
public void applicationFilters() {
Assert.assertNotNull(new Expectations() {
{
context.findFilterDefs();
result = new FilterDef();
}
});
final Tomcat90ContainerAdapter adapter = new Tomcat90ContainerAdapter();
assertEquals(1, adapter.getApplicationFilters(context).size());
}
示例13: applicationFilters
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
/**
* Application filters.
*/
@Test
public void applicationFilters() {
Assert.assertNotNull(new Expectations() {
{
context.findFilterDefs();
result = new FilterDef();
}
});
final Tomcat85ContainerAdapter adapter = new Tomcat85ContainerAdapter();
assertEquals(1, adapter.getApplicationFilters(context).size());
}
示例14: createGuiceFilter
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
private void createGuiceFilter(Context context) {
FilterDef filterDefinition = new FilterDef();
filterDefinition.setFilterName(GuiceFilter.class.getSimpleName());
filterDefinition.setFilterClass(GuiceFilter.class.getName());
context.addFilterDef(filterDefinition);
FilterMap filterMapping = new FilterMap();
filterMapping.setFilterName(GuiceFilter.class.getSimpleName());
filterMapping.addURLPattern("/*");
context.addFilterMap(filterMapping);
}
示例15: getApplicationFilterMaps
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入依赖的package包/类
public List getApplicationFilterMaps(Context context) {
FilterMap[] fms = context.findFilterMaps();
List filterMaps = new ArrayList(fms.length);
for (int i = 0; i < fms.length; i++) {
if (fms[i] != null) {
String dm;
switch(fms[i].getDispatcherMapping()) {
case FilterMap.ERROR: dm = "ERROR"; break;
case FilterMap.FORWARD: dm = "FORWARD"; break;
// case FilterMap.FORWARD_ERROR: dm = "FORWARD,ERROR"; break;
case FilterMap.INCLUDE: dm = "INCLUDE"; break;
// case FilterMap.INCLUDE_ERROR: dm = "INCLUDE,ERROR"; break;
// case FilterMap.INCLUDE_ERROR_FORWARD: dm = "INCLUDE,ERROR,FORWARD"; break;
//case FilterMap.INCLUDE_FORWARD: dm = "INCLUDE,FORWARD"; break;
case FilterMap.REQUEST: dm = "REQUEST"; break;
// case FilterMap.REQUEST_ERROR: dm = "REQUEST,ERROR"; break;
//case FilterMap.REQUEST_ERROR_FORWARD: dm = "REQUEST,ERROR,FORWARD"; break;
//case FilterMap.REQUEST_ERROR_FORWARD_INCLUDE: dm = "REQUEST,ERROR,FORWARD,INCLUDE"; break;
//case FilterMap.REQUEST_ERROR_INCLUDE: dm = "REQUEST,ERROR,INCLUDE"; break;
//case FilterMap.REQUEST_FORWARD: dm = "REQUEST,FORWARD"; break;
//case FilterMap.REQUEST_INCLUDE: dm = "REQUEST,INCLUDE"; break;
//case FilterMap.REQUEST_FORWARD_INCLUDE: dm = "REQUEST,FORWARD,INCLUDE"; break;
default: dm = "";
}
String filterClass = "";
org.apache.tomcat.util.descriptor.web.FilterDef fd = context.findFilterDef(fms[i].getFilterName());
if (fd != null) {
filterClass = fd.getFilterClass();
}
List filterMappings = getFilterMappings(fms[i], dm, filterClass);
filterMaps.addAll(filterMappings);
}
}
return filterMaps;
}