javax.servlet.ServletRegistration.Dynamic源码实例Demo

类javax.servlet.ServletRegistration.Dynamic源码实例Demo

下面列出了javax.servlet.ServletRegistration.Dynamic 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sakai   文件: WebAppConfiguration.java
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setServletContext(servletContext);
    rootContext.register(ThymeleafConfig.class);

    servletContext.addListener(new ToolListener());
    servletContext.addListener(new SakaiContextLoaderListener(rootContext));
    
    FilterRegistration requestFilterRegistration = servletContext.addFilter("sakai.request", RequestFilter.class);
    requestFilterRegistration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE), true, "/*");
    requestFilterRegistration.setInitParameter(RequestFilter.CONFIG_UPLOAD_ENABLED, "true");       

    Dynamic servlet = servletContext.addServlet("sakai-site-group-manager", new DispatcherServlet(rootContext));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
 
源代码2 项目: sakai   文件: WebAppConfiguration.java
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
	rootContext.setServletContext(servletContext);
	rootContext.register(ThymeleafConfig.class);

	servletContext.addListener(new ToolListener());
	servletContext.addListener(new SakaiContextLoaderListener(rootContext));

	servletContext.addFilter("sakai.request", RequestFilter.class)
		.addMappingForUrlPatterns(
			EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE),
			true,
			"/*");

	Dynamic servlet = servletContext.addServlet("sakai.datemanager", new DispatcherServlet(rootContext));
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
}
 
源代码3 项目: sakai   文件: WebAppConfiguration.java
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setServletContext(servletContext);
    rootContext.register(ThymeleafConfig.class);

    servletContext.addListener(new ToolListener());
    servletContext.addListener(new SakaiContextLoaderListener(rootContext));

    servletContext.addFilter("sakai.request", RequestFilter.class)
            .addMappingForUrlPatterns(
                    EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE),
                    true,
                    "/*");

    Dynamic servlet = servletContext.addServlet("sakai.message.bundle.manager", new DispatcherServlet(rootContext));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
 
源代码4 项目: piranha   文件: DefaultWebApplication.java
/**
 * Add the filter.
 *
 * @param filterName the filter name.
 * @param filterClass the filter class.
 * @return the filter dynamic.
 * @see ServletContext#addFilter(java.lang.String, java.lang.Class)
 */
@Override
public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass) {
    if (status == SERVICING) {
        throw new IllegalStateException("Cannot call this after web application has started");
    }

    if (filterName == null || filterName.trim().equals("")) {
        throw new IllegalArgumentException("Filter name cannot be null or empty");
    }

    DefaultFilterEnvironment filterEnvironment;
    if (filters.containsKey(filterName)) {
        filterEnvironment = filters.get(filterName);
    } else {
        filterEnvironment = new DefaultFilterEnvironment();
        filterEnvironment.setFilterName(filterName);
        filterEnvironment.setWebApplication(this);
        filters.put(filterName, filterEnvironment);
    }
    filterEnvironment.setClassName(filterClass.getCanonicalName());

    return filterEnvironment;
}
 
public Dynamic inject(ServletContext servletContext, String urlPattern) {
  String[] urlPatterns = splitUrlPattern(urlPattern);
  if (urlPatterns.length == 0) {
    LOGGER.warn("urlPattern is empty, ignore register {}.", SERVLET_NAME);
    return null;
  }

  String listenAddress = ServletConfig.getLocalServerAddress();
  if (!ServletUtils.canPublishEndpoint(listenAddress)) {
    LOGGER.warn("ignore register {}.", SERVLET_NAME);
    return null;
  }

  // dynamic deploy a servlet to handle serviceComb RESTful request
  Dynamic dynamic = servletContext.addServlet(SERVLET_NAME, RestServlet.class);
  dynamic.setAsyncSupported(true);
  dynamic.addMapping(urlPatterns);
  dynamic.setLoadOnStartup(0);
  LOGGER.info("RESTful servlet url pattern: {}.", Arrays.toString(urlPatterns));

  return dynamic;
}
 
@Test
public void testDefaultInjectListen(@Mocked ServletContext servletContext,
    @Mocked Dynamic dynamic) throws UnknownHostException, IOException {
  try (ServerSocket ss = new ServerSocket(0, 0, InetAddress.getByName("127.0.0.1"))) {
    int port = ss.getLocalPort();

    new Expectations(ServletConfig.class) {
      {
        ServletConfig.getServletUrlPattern();
        result = "/rest/*";
        ServletConfig.getLocalServerAddress();
        result = "127.0.0.1:" + port;
      }
    };

    Assert.assertEquals(dynamic, RestServletInjector.defaultInject(servletContext));
  }
}
 
源代码7 项目: sakai   文件: WebAppConfiguration.java
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setServletContext(servletContext);
    rootContext.register(ThymeleafConfig.class);

    servletContext.addListener(new ToolListener());
    servletContext.addListener(new SakaiContextLoaderListener(rootContext));

    servletContext.addFilter("sakai.request", RequestFilter.class)
            .addMappingForUrlPatterns(
                    EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE),
                    true,
                    "/*");

    Dynamic servlet = servletContext.addServlet("sakai.message.bundle.manager", new DispatcherServlet(rootContext));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
 
源代码8 项目: sakai   文件: WebAppConfiguration.java
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setServletContext(servletContext);
    rootContext.register(ThymeleafConfig.class);

    servletContext.addListener(new SakaiContextLoaderListener(rootContext));

    servletContext.addFilter("sakai.request", RequestFilter.class)
            .addMappingForUrlPatterns(
                    EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE),
                    true,
                    "/*");

    Dynamic servlet = servletContext.addServlet("sakai.googledrive", new DispatcherServlet(rootContext));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
 
源代码9 项目: sakai   文件: WebAppConfiguration.java
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setServletContext(servletContext);
    rootContext.register(ThymeleafConfig.class);

    servletContext.addListener(new ToolListener());
    servletContext.addListener(new SakaiContextLoaderListener(rootContext));
    
    FilterRegistration requestFilterRegistration = servletContext.addFilter("sakai.request", RequestFilter.class);
    requestFilterRegistration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE), true, "/*");
    requestFilterRegistration.setInitParameter(RequestFilter.CONFIG_UPLOAD_ENABLED, "true");       

    Dynamic servlet = servletContext.addServlet("sakai-site-group-manager", new DispatcherServlet(rootContext));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
 
@Override
public FilterRegistration.Dynamic addFilter(String filterName,
        Class<? extends Filter> filterClass) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (FilterRegistration.Dynamic) doPrivileged("addFilter",
                new Class[]{String.class, Class.class},
                new Object[]{filterName, filterClass});
    } else {
        return context.addFilter(filterName, filterClass);
    }
}
 
@Override
public ServletRegistration.Dynamic addServlet(String servletName,
        Servlet servlet) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (ServletRegistration.Dynamic) doPrivileged("addServlet",
                new Class[]{String.class, Servlet.class},
                new Object[]{servletName, servlet});
    } else {
        return context.addServlet(servletName, servlet);
    }
}
 
@Override
public ServletRegistration.Dynamic addServlet(String servletName,
        Class<? extends Servlet> servletClass) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (ServletRegistration.Dynamic) doPrivileged("addServlet",
                new Class[]{String.class, Class.class},
                new Object[]{servletName, servletClass});
    } else {
        return context.addServlet(servletName, servletClass);
    }
}
 
源代码13 项目: piranha   文件: DefaultWebApplication.java
/**
 * Add the filter.
 *
 * @param filterName the filter name.
 * @param filter the filter.
 * @return the filter dynamic registration.
 */
@Override
public FilterRegistration.Dynamic addFilter(String filterName, Filter filter) {
    if (status == SERVICING) {
        throw new IllegalStateException("Cannot call this after web application has started");
    }

    DefaultFilterEnvironment filterEnvironment = new DefaultFilterEnvironment(this, filterName, filter);
    filters.put(filterName, filterEnvironment);

    return filterEnvironment;

}
 
源代码14 项目: piranha   文件: DefaultWebApplication.java
/**
 * Add the servlet.
 *
 * @param servletName the servlet name.
 * @param className the class name.
 * @return the servlet dynamic.
 */
@Override
public Dynamic addServlet(String servletName, String className) {
    DefaultServletEnvironment result = servlets.get("servletName");
    if (result == null) {
        result = new DefaultServletEnvironment(this, servletName);
        result.setClassName(className);
        servlets.put(servletName, result);
    } else {
        result.setClassName(className);
    }

    return result;
}
 
源代码15 项目: piranha   文件: DefaultWebApplicationTest.java
/**
 * Test addMapping method (verify the # of mappings > 0).
 */
@Test
public void testAddMapping() {
    DefaultWebApplicationRequestMapper webAppRequestMapper = new DefaultWebApplicationRequestMapper();
    DefaultWebApplication webApp = new DefaultWebApplication();
    webApp.setWebApplicationRequestMapper(webAppRequestMapper);
    ServletRegistration.Dynamic dynamic
            = webApp.addServlet("echo", "servlet.EchoServlet");
    assertNotNull(dynamic);
    dynamic.addMapping("/echo");
    assertTrue(dynamic.getMappings().size() > 0);
}
 
源代码16 项目: mycore   文件: MCRUploadServletDeployer.java
@Override
public void startUp(ServletContext servletContext) {
    if (servletContext != null) {
        String servletName = "MCRUploadViaFormServlet";
        MultipartConfigElement multipartConfig = getMultipartConfig();
        try {
            checkTempStoragePath(multipartConfig.getLocation());
        } catch (IOException e) {
            throw new MCRConfigurationException("Could not setup " + servletName + "!", e);
        }
        Dynamic uploadServlet = servletContext.addServlet(servletName, MCRUploadViaFormServlet.class);
        uploadServlet.addMapping("/servlets/MCRUploadViaFormServlet");
        uploadServlet.setMultipartConfig(multipartConfig);
    }
}
 
源代码17 项目: piranha   文件: DefaultWebApplicationTest.java
/**
 * Test getAsync.
 *
 * @throws Exception
 */
@Test
public void testGetAsync() throws Exception {
    DefaultWebApplicationRequestMapper webAppRequestMapper = new DefaultWebApplicationRequestMapper();
    DefaultWebApplication webApp = new DefaultWebApplication();
    webApp.setWebApplicationRequestMapper(webAppRequestMapper);
    Dynamic registration = webApp.addServlet("Chat", TestChat1Servlet.class);
    registration.setAsyncSupported(true);
    webApp.addServletMapping("Chat", "/chat");
    webApp.initialize();
    webApp.start();
    TestWebApplicationRequest request = new TestWebApplicationRequest();
    request.setWebApplication(webApp);
    request.setServletPath("/chat");
    TestWebApplicationResponse response = new TestWebApplicationResponse();
    webApp.service(request, response);
    assertNotNull(response.getResponseBytes());
    request = new TestWebApplicationRequest();
    request.setWebApplication(webApp);
    request.setAsyncSupported(true);
    request.setServletPath("/chat");
    request.setMethod("POST");
    request.setParameter("action", new String[]{"login"});
    request.setParameter("name", new String[]{"username"});
    response = new TestWebApplicationResponse();
    webApp.service(request, response);
    assertNotNull(response.getResponseBytes());
    request = new TestWebApplicationRequest();
    request.setWebApplication(webApp);
    request.setServletPath("/chat");
    request.setMethod("POST");
    request.setParameter("action", new String[]{"post"});
    request.setParameter("name", new String[]{"username"});
    request.setParameter("message", new String[]{new Date().toString()});
    response = new TestWebApplicationResponse();
    webApp.service(request, response);
    assertNotNull(response.getResponseBytes());
}
 
源代码18 项目: piranha   文件: DefaultWebApplicationTest.java
/**
 * Test getAsync.
 *
 * @throws Exception
 */
@Test
public void testGetAsync2() throws Exception {
    DefaultWebApplicationRequestMapper webAppRequestMapper = new DefaultWebApplicationRequestMapper();
    DefaultWebApplication webApp = new DefaultWebApplication();
    webApp.setWebApplicationRequestMapper(webAppRequestMapper);
    Dynamic registration = webApp.addServlet("Chat", TestChat2Servlet.class);
    registration.setAsyncSupported(true);
    webApp.addServletMapping("Chat", "/chat");
    webApp.initialize();
    webApp.start();
    TestWebApplicationRequest request = new TestWebApplicationRequest();
    request.setWebApplication(webApp);
    request.setServletPath("/chat");
    TestWebApplicationResponse response = new TestWebApplicationResponse();
    webApp.service(request, response);
    assertNotNull(response.getResponseBytes());
    request = new TestWebApplicationRequest();
    request.setWebApplication(webApp);
    request.setServletPath("/chat");
    request.setMethod("POST");
    request.setParameter("action", new String[]{"login"});
    request.setParameter("name", new String[]{"username"});
    response = new TestWebApplicationResponse();
    webApp.service(request, response);
    assertNotNull(response.getResponseBytes());
    request = new TestWebApplicationRequest();
    request.setWebApplication(webApp);
    request.setServletPath("/chat");
    request.setMethod("POST");
    request.setParameter("action", new String[]{"post"});
    request.setParameter("name", new String[]{"username"});
    request.setParameter("message", new String[]{new Date().toString()});
    response = new TestWebApplicationResponse();
    webApp.service(request, response);
    assertNotNull(response.getResponseBytes());
}
 
@Test
public void testInjectServlet(@Mocked ConfigurableListableBeanFactory beanFactory) {
  Holder<Boolean> holder = new Holder<>();
  new MockUp<RestServletInjector>() {
    @Mock
    public Dynamic defaultInject(ServletContext servletContext) {
      holder.value = true;
      return null;
    }
  };

  context.invokeBeanFactoryPostProcessors(beanFactory);

  Assert.assertTrue(holder.value);
}
 
源代码20 项目: birt   文件: ServletContextSimulator.java
@Override
public javax.servlet.FilterRegistration.Dynamic addFilter(
		String filterName, Class<? extends Filter> filterClass )
{
	// TODO Auto-generated method stub
	return null;
}
 
源代码21 项目: springMvc4.x-project   文件: WebInitializer.java
@Override
public void onStartup(ServletContext servletContext)
		throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(MyMvcConfig.class);
	ctx.setServletContext(servletContext); // ②

	Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // ③
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
}
 
源代码22 项目: springMvc4.x-project   文件: WebInitializer.java
@Override
public void onStartup(ServletContext servletContext)
		throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(MyMvcConfig.class);
	ctx.setServletContext(servletContext); // ②

	Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
}
 
源代码23 项目: springMvc4.x-project   文件: WebInitializer.java
@Override
public void onStartup(ServletContext servletContext)
		throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(MyMvcConfig.class);
	ctx.setServletContext(servletContext); // ②

	Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
}
 
源代码24 项目: wiztowar   文件: DWAdapter.java
/**
 * This method is adapted from ServerFactory.createInternalServlet.
 */
private void createInternalServlet(final ExtendedEnvironment env, final ServletContext context) {
    if (context.getMajorVersion() >= 3) {

        // Add the Task servlet
        final ServletRegistration.Dynamic taskServlet = context.addServlet("TaskServlet", new TaskServlet(env.getTasks()));
        taskServlet.setAsyncSupported(true);
        taskServlet.addMapping("/tasks/*");

        // Add the Admin servlet
        final ServletRegistration.Dynamic adminServlet = context.addServlet("AdminServlet", new AdminServlet());
        adminServlet.setAsyncSupported(true);
        adminServlet.addMapping("/admin/*");
    } else throw new IllegalStateException("The WizToWar adapter doesn't support servlet versions under 3");
}
 
源代码25 项目: arctic-sea   文件: MockServletContext.java
@Override
public ServletRegistration.Dynamic addServlet(String string, Class<? extends Servlet> type) {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
源代码26 项目: pulsar   文件: MockServletContext.java
@Override
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Filter filter) {
    return null;
}
 
源代码27 项目: flex-poker   文件: WebInitializer.java
@Override
protected void customizeRegistration(Dynamic registration) {
    registration.setAsyncSupported(true);
}
 
源代码28 项目: onetwo   文件: HackServletContextStandardContext.java
public javax.servlet.FilterRegistration.Dynamic addFilter(
		String filterName, String className) {
	return servletContext.addFilter(filterName, className);
}
 
源代码29 项目: live-chat-engine   文件: MockServletContext.java
@Override
public javax.servlet.FilterRegistration.Dynamic addFilter(
		String filterName, Filter filter) {
	// TODO Auto-generated method stub
	return null;
}
 
源代码30 项目: cxf   文件: ThreadLocalServletContext.java
public Dynamic addServlet(String servletName, String className) throws IllegalArgumentException,
    IllegalStateException {
    return get().addServlet(servletName, className);
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法