Java Code Examples for javax.servlet.ServletRegistration.Dynamic#setAsyncSupported()

The following examples show how to use javax.servlet.ServletRegistration.Dynamic#setAsyncSupported() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestServletInjector.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: BootstrapAppInitializer.java    From oxygen with Apache License 2.0 5 votes vote down vote up
@Override
public void onStartup(ServletContext context) {
  Bootstrap.start();
  Dynamic dynamic = context
      .addServlet(DispatcherServlet.class.getSimpleName(), DispatcherServlet.class);
  dynamic.setLoadOnStartup(0);
  dynamic.addMapping(Strings.SLASH);
  dynamic.setAsyncSupported(true);
}
 
Example 3
Source File: DefaultWebApplicationTest.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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());
}
 
Example 4
Source File: DefaultWebApplicationTest.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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());
}
 
Example 5
Source File: WebInitializer.java    From springMvc4.x-project with Apache License 2.0 5 votes vote down vote up
@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);
	servlet.setAsyncSupported(true);//①
}
 
Example 6
Source File: WebInitializer.java    From springMvc4.x-project with Apache License 2.0 5 votes vote down vote up
@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);
	servlet.setAsyncSupported(true);//①
}
 
Example 7
Source File: WebAppInitializer.java    From nio-multipart with Apache License 2.0 5 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation("org.synchronoss.cloud.nio.multipart.example.config");
    context.setServletContext(servletContext);
    Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
    dynamic.setAsyncSupported(true);
    dynamic.addMapping("/");
    dynamic.setLoadOnStartup(1);

}
 
Example 8
Source File: WebInitializer.java    From Project with Apache License 2.0 4 votes vote down vote up
@Override
protected void customizeRegistration(Dynamic registration) {
	registration.setAsyncSupported(true);
}
 
Example 9
Source File: WebInitializer.java    From Project with Apache License 2.0 4 votes vote down vote up
@Override
protected void customizeRegistration(Dynamic registration) {
	registration.setAsyncSupported(true);
}
 
Example 10
Source File: WebInitializer.java    From Project with Apache License 2.0 4 votes vote down vote up
@Override
protected void customizeRegistration(Dynamic registration) {
	registration.setAsyncSupported(true);
}
 
Example 11
Source File: WebInitializer.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void customizeRegistration(Dynamic registration) {
    registration.setAsyncSupported(true);
}