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


Java ServletRegistration.getMappings方法代码示例

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


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

示例1: collectUrlPatterns

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
static String[] collectUrlPatterns(ServletContext servletContext, Class<?> servletCls) {
  List<ServletRegistration> servlets = servletContext.getServletRegistrations()
      .values()
      .stream()
      .filter(predicate -> {
        return predicate.getClassName().equals(servletCls.getName());
      })
      .collect(Collectors.toList());
  if (servlets.isEmpty()) {
    return new String[] {};
  }

  ServletRegistration servletRegistration = servlets.get(0);
  Collection<String> mappings = servletRegistration.getMappings();
  if (servlets.size() > 1) {
    LOGGER.info("Found {} {} registered, select the first one, mappings={}.",
        servlets.size(),
        servletCls.getName(),
        mappings);
  }
  return filterUrlPatterns(mappings);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:23,代码来源:ServletUtils.java

示例2: testSaveUrlPrefixNormal

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
@Test
public void testSaveUrlPrefixNormal(@Mocked ServletContext servletContext,
    @Mocked ServletRegistration servletRegistration) {
  System.clearProperty(Const.URL_PREFIX);
  new Expectations() {
    {
      servletContext.getContextPath();
      result = "/root";
      servletRegistration.getClassName();
      result = RestServlet.class.getName();
      servletRegistration.getMappings();
      result = Arrays.asList("/rest/*");
      servletContext.getServletRegistrations();
      result = Collections.singletonMap("test", servletRegistration);
    }
  };

  ServletUtils.saveUrlPrefix(servletContext);

  Assert.assertThat(System.getProperty(Const.URL_PREFIX), Matchers.is("/root/rest"));
  System.clearProperty(Const.URL_PREFIX);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:23,代码来源:TestServletUtils.java

示例3: getServletUrlPattern

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
private static String getServletUrlPattern(final ServletContextEvent servletContextEvent) throws Exception {
    final ServletContext servletContext = servletContextEvent.getServletContext();

    ServletRegistration servletRegistration = servletContext.getServletRegistration(servletName);
    if (servletRegistration == null) {
        throw new NoSuchElementException("no servlet with name \"" + servletName + "\" is found.");
    }
    java.util.Collection<java.lang.String> mappings = servletRegistration.getMappings();
    if (mappings.size() != 1) {
        throw new NoSuchElementException("unable to identify servlet mappings for servlet with name \"" + servletName + "\".");
    }
    String mapping = (String) mappings.toArray()[0];

    //url patterns in  most cases end with '\*'. But a url-pattern with just '\' may be found for exact matches.
    if (mapping.endsWith("*"))
        mapping = mapping.substring(0, mapping.length()-1);
    return mapping;
}
 
开发者ID:EricssonResearch,项目名称:scott-eu,代码行数:19,代码来源:ServletListener.java

示例4: needJDBC

import javax.servlet.ServletRegistration; //导入方法依赖的package包/类
private boolean needJDBC(HttpServletRequest request) {
    System.out.println("JDBC Filter");
    //
    // Servlet Url-pattern: /spath/*
    //
    // => /spath
    String servletPath = request.getServletPath();
    // => /abc/mnp
    String pathInfo = request.getPathInfo();
    String urlPattern = servletPath;

    if (pathInfo != null) {
        // => /spath/*
        urlPattern = servletPath + "/*";
    }

    // Key: servletName.
    // Value: ServletRegistration
    Map<String, ? extends ServletRegistration> servletRegistrations =
    		request.getServletContext().getServletRegistrations();

    // Collection of all servlet in your webapp.
    Collection<? extends ServletRegistration> values = servletRegistrations.values();
    for (ServletRegistration sr : values) {
        Collection<String> mappings = sr.getMappings();
        if (mappings.contains(urlPattern)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:biblelamp,项目名称:JavaEE,代码行数:32,代码来源:JDBCFilter.java


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