当前位置: 首页>>代码示例>>Java>>正文


Java FilterDef.addInitParameter方法代码示例

本文整理汇总了Java中org.apache.tomcat.util.descriptor.web.FilterDef.addInitParameter方法的典型用法代码示例。如果您正苦于以下问题:Java FilterDef.addInitParameter方法的具体用法?Java FilterDef.addInitParameter怎么用?Java FilterDef.addInitParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.tomcat.util.descriptor.web.FilterDef的用法示例。


在下文中一共展示了FilterDef.addInitParameter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:equella,项目名称:Equella,代码行数:9,代码来源:TomcatServiceImpl.java

示例2: 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();
}
 
开发者ID:nlighten,项目名称:tomcat_exporter,代码行数:41,代码来源:AbstractTomcatMetricsTest.java

示例3: addFilterToContext

import org.apache.tomcat.util.descriptor.web.FilterDef; //导入方法依赖的package包/类
/**
    * Adds a predefined Filter definition and mapping to a Context
    * Method
    * @param rootCtx	the Context to add the predefined Filter to
    */
   public static void addFilterToContext(Context rootCtx) {

// See https://tomcat.apache.org/tomcat-8.5-doc/config/filter.html for filters

/*
<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
  <init-param>
    <param-name>cors.allowed.origins</param-name>
    <param-value>*</param-value>
  </init-param>
   <init-param>
           <param-name>cors.allowed.methods</param-name>
           <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
         </init-param>
         <init-param>
           <param-name>cors.allowed.headers</param-name>
           <param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
         </init-param>
 
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>
*/

String filterName = "CorsFilter";
String filterClass = "org.apache.catalina.filters.CorsFilter";

FilterDef filterDef = new  FilterDef();

filterDef.setFilterName(filterName);
filterDef.setFilterClass(filterClass);

filterDef.addInitParameter("cors.allowed.origins", "*");
filterDef.addInitParameter("cors.allowed.methods", "GET,POST,HEAD,OPTIONS,PUT");
filterDef.addInitParameter("cors.allowed.headers", "Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers");

// Don't forget mapping
FilterMap filterMap = new FilterMap();
filterMap.setFilterName(filterName);
filterMap.addURLPattern("/*");

// Add both filter definition & mapping to context that will be used by a servlet:
rootCtx.addFilterDef(filterDef);
rootCtx.addFilterMap(filterMap);
   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:55,代码来源:TomcatFilterUtil.java

示例4: 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);
}
 
开发者ID:apache,项目名称:tomee,代码行数:82,代码来源:TomcatRsRegistry.java


注:本文中的org.apache.tomcat.util.descriptor.web.FilterDef.addInitParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。