List of usage examples for org.springframework.web SpringServletContainerInitializer SpringServletContainerInitializer
SpringServletContainerInitializer
From source file:org.tmarciniak.mtp.web.websocket.support.server.TomcatWebSocketTestServer.java
@SafeVarargs public final void deployConfig(Class<? extends WebApplicationInitializer>... initializers) { this.context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir")); // Add Tomcat's DefaultServlet Wrapper defaultServlet = this.context.createWrapper(); defaultServlet.setName("default"); defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); this.context.addChild(defaultServlet); // Ensure WebSocket support this.context.addApplicationListener(WS_APPLICATION_LISTENER); this.context.addServletContainerInitializer(new SpringServletContainerInitializer(), new HashSet<Class<?>>(Arrays.asList(initializers))); }
From source file:test.org.spring.websocket.api.tomcat.support.TomcatWebSocketTestServer.java
public void deployConfig(Class<? extends WebApplicationInitializer>... initializers) { this.context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir")); // Add Tomcat's DefaultServlet Wrapper defaultServlet = this.context.createWrapper(); defaultServlet.setName("default"); defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); this.context.addChild(defaultServlet); // Ensure WebSocket support this.context.addApplicationListener(WsContextListener.class.getName()); this.context.addServletContainerInitializer(new SpringServletContainerInitializer(), new HashSet<Class<?>>(Arrays.asList(initializers))); }
From source file:org.appverse.web.framework.backend.frontfacade.websocket.support.TomcatWebSocketTestServer.java
public void deployConfig(Class<? extends WebApplicationInitializer>... initializers) { this.context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir")); // Add Tomcat's DefaultServlet Wrapper defaultServlet = this.context.createWrapper(); defaultServlet.setName("default"); defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); this.context.addChild(defaultServlet); // Ensure WebSocket support this.context.addApplicationListener(WS_APPLICATION_LISTENER); this.context.addServletContainerInitializer(new SpringServletContainerInitializer(), new HashSet<Class<?>>(Arrays.asList(initializers))); }
From source file:com.fitbur.testify.system.SpringSystemTest.java
public ServerContext getServerContext(TestContext testContext, String methodName) { Object testInstance = testContext.getTestInstance(); return testContext.getAnnotation(App.class).map(p -> { Class<?> appType = p.value(); ServiceLoader<ServerProvider> serviceLoader = ServiceLoader.load(ServerProvider.class); ArrayList<ServerProvider> serverProviders = Lists.newArrayList(serviceLoader); checkState(!serverProviders.isEmpty(), "ServiceProvider provider implementation not found in the classpath"); checkState(serverProviders.size() == 1, "Multiple ServiceProvider provider implementations found in the classpath. " + "Please insure there is only one ServiceProvider provider implementation " + "in the classpath."); ServerProvider provider = serverProviders.get(0); interceptor = new SpringSystemServletInterceptor(testContext, methodName, serviceAnnotations, classTestNeeds, classTestNeedContainers); Class<?> proxyAppType = BYTE_BUDDY.subclass(appType).method(not(isDeclaredBy(Object.class))) .intercept(to(interceptor).filter(not(isDeclaredBy(Object.class)))).make() .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded(); Set<Class<?>> handles = new HashSet<>(); handles.add(proxyAppType);/*from w w w.j a v a2 s .com*/ SpringServletContainerInitializer initializer = new SpringServletContainerInitializer(); SpringSystemServerDescriptor descriptor = new SpringSystemServerDescriptor(p, testContext, initializer, handles); Object configuration = provider.configuration(descriptor); testContext.getConfigMethod(configuration.getClass()).map(m -> m.getMethod()).ifPresent(m -> { AccessController.doPrivileged((PrivilegedAction<Object>) () -> { try { m.setAccessible(true); m.invoke(testInstance, configuration); } catch (Exception e) { checkState(false, "Call to config method '%s' in test class '%s' failed.", m.getName(), descriptor.getTestClassName()); throw Throwables.propagate(e); } return null; }); }); ServerInstance serverInstance = provider.init(descriptor, configuration); serverInstance.start(); SpringServiceLocator serviceLocator = interceptor.getServiceLocator(); serviceLocator.addConstant(serverInstance.getClass().getSimpleName(), serverInstance); ServerContext serverContext = new ServerContext(provider, descriptor, serverInstance, serviceLocator, configuration); serviceLocator.addConstant(serverContext.getClass().getSimpleName(), serverContext); TestCaseInstance testCaseInstance = new TestCaseInstance(methodName, testInstance); serviceLocator.addConstant(testCaseInstance.getTestName(), testCaseInstance); return serverContext; }).get(); }