本文整理汇总了Java中org.apache.tomcat.util.descriptor.web.FilterDef.setFilter方法的典型用法代码示例。如果您正苦于以下问题:Java FilterDef.setFilter方法的具体用法?Java FilterDef.setFilter怎么用?Java FilterDef.setFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.descriptor.web.FilterDef
的用法示例。
在下文中一共展示了FilterDef.setFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: createRsHttpListener
import org.apache.tomcat.util.descriptor.web.FilterDef; //导入方法依赖的package包/类
@Override
public AddressInfo createRsHttpListener(final String appId, final String webContext, final HttpListener listener, final ClassLoader classLoader, final String completePath, final String virtualHost, final String auth, final String realm) {
String path = webContext;
if (path == null) {
throw new NullPointerException("contextRoot is null");
}
if (listener == null) {
throw new NullPointerException("listener is null");
}
// find the existing host (we do not auto-create hosts)
Container host;
Context context = null;
if (virtualHost == null) {
host = hosts.getDefault();
} else {
host = hosts.get(virtualHost);
}
if (host == null) {
for (final Host h : hosts) {
context = findContext(h, appId, webContext);
if (context != null) {
host = h;
if (classLoader != null && classLoader.equals(context.getLoader().getClassLoader())) {
break;
} // else try next to find something better
}
}
if (host == null) {
throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'. Do you have a matching Host entry in the server.xml?");
}
} else {
context = findContext(host, appId, webContext);
}
if (context == null) {
throw new IllegalStateException("Invalid context '" + webContext + "'. Cannot find context in host " + host.getName());
}
final CxfRsHttpListener cxfRsHttpListener = findCxfRsHttpListener(listener);
final String description = "tomee-jaxrs-" + listener;
String mapping = completePath;
if (!completePath.endsWith("/*")) { // respect servlet spec (!= from our embedded listeners)
if (completePath.endsWith("*")) {
mapping = completePath.substring(0, completePath.length() - 1);
}
mapping = mapping + "/*";
}
final String urlPattern = removeWebContext(webContext, mapping);
cxfRsHttpListener.setUrlPattern(urlPattern.substring(0, urlPattern.length() - 1));
final FilterDef filterDef = new FilterDef();
filterDef.setAsyncSupported("true");
filterDef.setDescription(description);
filterDef.setFilterName(description);
filterDef.setDisplayName(description);
filterDef.setFilter(new CXFJAXRSFilter(cxfRsHttpListener, context.findWelcomeFiles()));
filterDef.setFilterClass(CXFJAXRSFilter.class.getName());
filterDef.addInitParameter("mapping", urlPattern.substring(0, urlPattern.length() - "/*".length())); // just keep base path
context.addFilterDef(filterDef);
final FilterMap filterMap = new FilterMap();
filterMap.addURLPattern(urlPattern);
for (final DispatcherType type : DispatcherType.values()) {
filterMap.setDispatcher(type.name());
}
filterMap.setFilterName(filterDef.getFilterName());
context.addFilterMap(filterMap);
Registrations.addFilterConfig(context, filterDef);
path = address(connectors, host.getName(), webContext);
final String key = address(connectors, host.getName(), completePath);
listeners.put(new Key(appId, key), listener);
return new AddressInfo(path, key);
}