Java Code Examples for org.springframework.web.context.support.AnnotationConfigWebApplicationContext#close()
The following examples show how to use
org.springframework.web.context.support.AnnotationConfigWebApplicationContext#close() .
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: WebConfigurer.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { LOGGER.info("Destroying Web application"); WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; gwac.close(); LOGGER.debug("Web application destroyed"); }
Example 2
Source File: WebSocketDocsTest.java From chassis with Apache License 2.0 | 5 votes |
@Test public void testProtobufMessagesSchema() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("admin.enabled", "true"); properties.put("admin.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("admin.hostname", "localhost"); properties.put("websocket.enabled", "true"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); properties.put("http.enabled", "false"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); RestTemplate httpClient = new RestTemplate(); try { context.refresh(); httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR)); ResponseEntity<String> response = httpClient.getForEntity( new URI("http://localhost:" + properties.get("admin.port") + "/schema/messages/protobuf"), String.class); logger.info("Got response: [{}]", response); Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value()); Assert.assertTrue(response.getBody().contains("message error")); } finally { context.close(); } }
Example 3
Source File: WebSocketDocsTest.java From chassis with Apache License 2.0 | 5 votes |
@Test public void testProtobufMessagesEnvelope() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("admin.enabled", "true"); properties.put("admin.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("admin.hostname", "localhost"); properties.put("websocket.enabled", "true"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); properties.put("http.enabled", "false"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); RestTemplate httpClient = new RestTemplate(); try { context.refresh(); httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR)); ResponseEntity<String> response = httpClient.getForEntity( new URI("http://localhost:" + properties.get("admin.port") + "/schema/envelope/protobuf"), String.class); logger.info("Got response: [{}]", response); Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value()); Assert.assertTrue(response.getBody().contains("message Envelope")); } finally { context.close(); } }
Example 4
Source File: IndexDocTests.java From spring-session with Apache License 2.0 | 5 votes |
@Test void runSpringHttpSessionConfig() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(SpringHttpSessionConfig.class); context.setServletContext(new MockServletContext()); context.refresh(); try { context.getBean(SessionRepositoryFilter.class); } finally { context.close(); } }
Example 5
Source File: WebConfigurer.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { LOGGER.info("Destroying Web application"); WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; gwac.close(); LOGGER.debug("Web application destroyed"); }
Example 6
Source File: PropertySources.java From rice with Educational Community License v2.0 | 5 votes |
protected static PropertySource<?> getPropertySource(String className, AnnotationConfigWebApplicationContext context) { try { logger.info("Loading [{}] to setup a Spring property source", className); Class<?> annotatedClass = Class.forName(className); context.register(annotatedClass); context.refresh(); PropertySource<?> propertySource = getPropertySource(context, annotatedClass); context.close(); logger.info("Spring property source was successfully setup"); return propertySource; } catch (Exception e) { throw new IllegalStateException("Unexpected error configuring Spring property source", e); } }
Example 7
Source File: WebConfigurer.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { LOGGER.info("Destroying Web application"); WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; gwac.close(); LOGGER.debug("Web application destroyed"); }
Example 8
Source File: JPAWebConfigurer.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { LOGGER.info("Destroying Web application"); WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; gwac.close(); LOGGER.debug("Web application destroyed"); }
Example 9
Source File: WebConfigurer.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { LOGGER.info("Destroying Web application"); WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; gwac.close(); LOGGER.debug("Web application destroyed"); }
Example 10
Source File: WebConfigurer.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { LOGGER.info("Destroying Web application"); WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; gwac.close(); LOGGER.debug("Web application destroyed"); }
Example 11
Source File: WebConfigurer.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { LOGGER.info("Destroying Web application"); WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; gwac.close(); LOGGER.debug("Web application destroyed"); }
Example 12
Source File: WebConfigurer.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { log.info("Destroying Web application"); WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; gwac.close(); log.debug("Web application destroyed"); }
Example 13
Source File: JPAWebConfigurer.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { log.info("Destroying Web application"); WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; gwac.close(); log.debug("Web application destroyed"); }
Example 14
Source File: WebConfigurer.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { log.info("Destroying Web application"); WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; gwac.close(); log.debug("Web application destroyed"); }
Example 15
Source File: SharedTest.java From chassis with Apache License 2.0 | 4 votes |
@Test public void testProperties() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("admin.enabled", "true"); properties.put("admin.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("admin.hostname", "localhost"); properties.put("websocket.enabled", "true"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); properties.put("http.enabled", "true"); properties.put("http.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("http.hostname", "localhost"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); context.register(MetricsConfiguration.class); RestTemplate httpClient = new RestTemplate(); try { context.refresh(); httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR)); List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); for (MessageSerDe messageSerDe : context.getBeansOfType(MessageSerDe.class).values()) { messageConverters.add(new SerDeHttpMessageConverter(messageSerDe)); } messageConverters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8)); httpClient.setMessageConverters(messageConverters); ResponseEntity<String> response = httpClient.getForEntity(new URI("http://localhost:" + properties.get("admin.port") + "/admin/properties"), String.class); logger.info("Got response: [{}]", response); Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value()); Assert.assertTrue(response.getBody().contains("user.dir=" + System.getProperty("user.dir"))); } finally { context.close(); } }
Example 16
Source File: SharedTest.java From chassis with Apache License 2.0 | 4 votes |
@Test public void testSwagger() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("admin.enabled", "true"); properties.put("admin.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("admin.hostname", "localhost"); properties.put("websocket.enabled", "true"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); properties.put("http.enabled", "true"); properties.put("http.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("http.hostname", "localhost"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); context.register(MetricsConfiguration.class); RestTemplate httpClient = new RestTemplate(); try { context.refresh(); httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR)); List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); for (MessageSerDe messageSerDe : context.getBeansOfType(MessageSerDe.class).values()) { messageConverters.add(new SerDeHttpMessageConverter(messageSerDe)); } messageConverters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8)); httpClient.setMessageConverters(messageConverters); ResponseEntity<String> response = httpClient.getForEntity(new URI("http://localhost:" + properties.get("http.port") + "/swagger/index.html"), String.class); logger.info("Got response: [{}]", response); Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value()); Assert.assertTrue(response.getBody().contains("<title>Swagger UI</title>")); } finally { context.close(); } }
Example 17
Source File: MetricsTest.java From chassis with Apache License 2.0 | 4 votes |
@Test public void testMetricsPing() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("admin.enabled", "true"); properties.put("admin.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("admin.hostname", "localhost"); properties.put("websocket.enabled", "true"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); properties.put("http.enabled", "true"); properties.put("http.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("http.hostname", "localhost"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); context.register(MetricsConfiguration.class); RestTemplate httpClient = new RestTemplate(); try { context.refresh(); httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR)); List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); for (MessageSerDe serDe : context.getBeansOfType(MessageSerDe.class).values()) { messageConverters.add(new SerDeHttpMessageConverter(serDe)); } messageConverters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8)); httpClient.setMessageConverters(messageConverters); ResponseEntity<String> response = httpClient.getForEntity(new URI("http://localhost:" + properties.get("admin.port") + "/metrics/ping"), String.class); logger.info("Got response: [{}]", response); Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value()); Assert.assertEquals("pong".trim(), response.getBody().trim()); } finally { context.close(); } }
Example 18
Source File: HybridServiceTest.java From chassis with Apache License 2.0 | 4 votes |
@Test public void testHybridService() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("websocket.enabled", "true"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); properties.put("http.enabled", "true"); properties.put("http.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("http.hostname", "localhost"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); context.register(TestCombinedService.class); WebSocketClient wsClient = new WebSocketClient(); RestTemplate httpClient = new RestTemplate(); try { context.refresh(); final MessageSerDe serDe = context.getBean(ProtobufMessageSerDe.class); final WebSocketMessageRegistry messageRegistry = context.getBean(WebSocketMessageRegistry.class); messageRegistry.registerType("stuff", TestObject.class); wsClient.start(); httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR)); List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); for (MessageSerDe messageSerDe : context.getBeansOfType(MessageSerDe.class).values()) { messageConverters.add(new SerDeHttpMessageConverter(messageSerDe)); } messageConverters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8)); httpClient.setMessageConverters(messageConverters); QueuingWebSocketListener webSocket = new QueuingWebSocketListener(serDe, messageRegistry, null); Session session = wsClient.connect(webSocket, new URI("ws://localhost:" + properties.get("websocket.port") + "/protobuf")).get(5000, TimeUnit.MILLISECONDS); Envelope envelope = new Envelope("getStuff", null, null, null); session.getRemote().sendBytes(ByteBuffer.wrap(serDe.serialize(envelope))); TestObject response = webSocket.getResponse(5, TimeUnit.SECONDS); Assert.assertNotNull(response); Assert.assertEquals("stuff", response.value); byte[] rawStuff = serDe.serialize(new TestObject("more stuff")); envelope = new Envelope("setStuff", "stuff", null, ByteBuffer.wrap(rawStuff)); session.getRemote().sendBytes(ByteBuffer.wrap(serDe.serialize(envelope))); response = webSocket.getResponse(5, TimeUnit.SECONDS); Assert.assertNotNull(response); Assert.assertEquals("stuff", response.value); envelope = new Envelope("getStuff", null, null, null); session.getRemote().sendBytes(ByteBuffer.wrap(serDe.serialize(envelope))); response = webSocket.getResponse(5, TimeUnit.SECONDS); Assert.assertNotNull(response); Assert.assertEquals("more stuff", response.value); response = httpClient.getForObject(new URI("http://localhost:" + properties.get("http.port") + "/stuff/"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("more stuff", response.value); response = httpClient.postForObject(new URI("http://localhost:" + properties.get("http.port") + "/stuff/"), new TestObject("even more stuff"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("more stuff", response.value); response = httpClient.getForObject(new URI("http://localhost:" + properties.get("http.port") + "/stuff/"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("even more stuff", response.value); } finally { try { wsClient.stop(); } finally { context.close(); } } }
Example 19
Source File: WebSocketTransportTest.java From chassis with Apache License 2.0 | 4 votes |
@Test public void testEmptyWebSocketFrameUsingBinary() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("websocket.enabled", "true"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); properties.put("http.enabled", "false"); properties.put("http.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("http.hostname", "localhost"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); context.register(TestWebSocketService.class); WebSocketClient wsClient = new WebSocketClient(); try { //start server context.refresh(); // start client wsClient.start(); final MessageSerDe serDe = context.getBean(JsonJacksonMessageSerDe.class); final WebSocketMessageRegistry messageRegistry = context.getBean(WebSocketMessageRegistry.class); QueuingWebSocketListener listener = new QueuingWebSocketListener(serDe, messageRegistry, null); WebSocketSession session = (WebSocketSession)wsClient.connect(listener, new URI("ws://localhost:" + properties.get("websocket.port") + "/" + serDe.getMessageFormatName())) .get(5000, TimeUnit.MILLISECONDS); session.getRemote().sendBytes(ByteBuffer.wrap(new byte[0])); ServiceError error = listener.getResponse(5, TimeUnit.SECONDS); Assert.assertNotNull(error); Assert.assertEquals("EMPTY_ENVELOPE", error.code); Assert.assertEquals("STOPPED", session.getState()); } finally { try { wsClient.stop(); } finally { context.close(); } } }
Example 20
Source File: SharedTest.java From chassis with Apache License 2.0 | 4 votes |
@Test public void testAdminLinks() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("admin.enabled", "true"); properties.put("admin.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("admin.hostname", "localhost"); properties.put("websocket.enabled", "true"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); properties.put("http.enabled", "true"); properties.put("http.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("http.hostname", "localhost"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); context.register(MetricsConfiguration.class); RestTemplate httpClient = new RestTemplate(); try { context.refresh(); httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR)); List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); for (MessageSerDe messageSerDe : context.getBeansOfType(MessageSerDe.class).values()) { messageConverters.add(new SerDeHttpMessageConverter(messageSerDe)); } messageConverters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8)); httpClient.setMessageConverters(messageConverters); ResponseEntity<String> response = httpClient.getForEntity(new URI("http://localhost:" + properties.get("admin.port") + "/admin/index.html"), String.class); logger.info("Got response: [{}]", response); Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value()); Assert.assertTrue(response.getBody().contains("<a href=\"/metrics/ping\">Ping</a>")); Assert.assertTrue(response.getBody().contains("<a href=\"/healthcheck\">Healthcheck</a>")); Assert.assertTrue(response.getBody().contains("<a href=\"/metrics/metrics?pretty=true\">Metrics</a>")); Assert.assertTrue(response.getBody().contains("<a href=\"/admin/properties\">Properties</a>")); Assert.assertTrue(response.getBody().contains("<a href=\"/metrics/threads\">Threads</a>")); Assert.assertTrue(response.getBody().contains("<a href=\"/admin/classpath\">Classpath</a>")); } finally { context.close(); } }