private static void executeSample1() { final Scanner scanner = new Scanner(System.in); final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); context.load("classpath:META-INF/spring/integration/spring-integration-sample1-context.xml"); context.registerShutdownHook(); context.refresh(); final StringConversionService service = context.getBean(StringConversionService.class); final String message = "\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n=========================================================" + "\n\n Please enter a string and press <enter>: "; System.out.print(message); while (!scanner.hasNext("q")) { String input = scanner.nextLine(); System.out.println("Converting String to Uppcase using Stored Procedure..."); String inputUpperCase = service.convertToUpperCase(input); System.out.println("Retrieving Numeric value via Sql Function..."); Integer number = service.getNumber(); System.out.println(String.format("Converted '%s' - End Result: '%s_%s'.", input, inputUpperCase, number)); System.out.print("To try again, please enter a string and press <enter>:"); } scanner.close(); context.close(); System.out.println("Back to main menu."); }
context.registerShutdownHook(); context.refresh();
public static GenericXmlApplicationContext setupContext() { final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); if (System.getProperty(AVAILABLE_SERVER_SOCKET) == null) { System.out.print("Detect open server socket..."); int availableServerSocket = SocketUtils.findAvailableTcpPort(5678); final Map<String, Object> sockets = new HashMap<>(); sockets.put(AVAILABLE_SERVER_SOCKET, availableServerSocket); final MapPropertySource propertySource = new MapPropertySource("sockets", sockets); context.getEnvironment().getPropertySources().addLast(propertySource); } System.out.println("using port " + context.getEnvironment().getProperty(AVAILABLE_SERVER_SOCKET)); context.load("classpath:META-INF/spring/integration/tcpClientServerDemo-context.xml"); context.registerShutdownHook(); context.refresh(); return context; }
@SuppressWarnings("resource") public static void main(final String... args) { final String agentName = System.getProperty(Constants.SENTILO_AGENT_NAME_ENV); Assert.hasText(agentName, "[Assertion failed] Property sentilo.agent.name must be configured as system property."); final Pattern namePattern = Pattern.compile("[a-zA-Z-]+"); Assert.isTrue(namePattern.matcher(agentName).matches(), "[Assertion failed] Property sentilo.agent.name must follow the following pattern [a-zA-Z-]+"); final String activeProfiles = System.getProperty("spring.profiles.active"); LOGGER.info("Starting agent {}", agentName); LOGGER.info("Active profile:{}", activeProfiles); Runtime.getRuntime().addShutdownHook(new SentiloShutdownHook(agentName)); LOGGER.info("Sentilo shutdown hook registered"); final GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.getEnvironment().setActiveProfiles(activeProfiles); ctx.registerShutdownHook(); ctx.load("classpath:spring/" + args[0]); ctx.refresh(); }
@SuppressWarnings("resource") public static void main(final String... args) { final String activeProfiles = System.getProperty("spring.profiles.active"); LOGGER.info("Starting server"); LOGGER.info("Active profile:{}", activeProfiles); Runtime.getRuntime().addShutdownHook(new SentiloShutdownHook("server")); LOGGER.info("Sentilo shutdown hook registered"); final GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.getEnvironment().setActiveProfiles(activeProfiles); ctx.registerShutdownHook(); ctx.load("classpath:spring/platform-server-context.xml"); ctx.refresh(); final RequestListenerThread t = (RequestListenerThread) ctx.getBean("listener"); t.setDaemon(false); t.start(); } }
private SpringContextServiceReference load( final String serviceId, final Map<String, String> updatedProperties) { final String configurationPath = serviceDefinition.getMainContextPath(); final String serviceBeanName = serviceDefinition.getServiceBeanName(); final PropertyPlaceholderConfigurer placeholderConfigurer = createPlaceholderConfigurer(); Properties properties = new Properties(); properties.putAll(updatedProperties); properties.put(ServiceConstants.SERVICE_ID_PROPERTY, serviceId); placeholderConfigurer.setProperties(properties); final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); for(Entry<String, BeanPostProcessor> postProcessorEntry: applicationContext.getBeansOfType(BeanPostProcessor.class).entrySet()){ context.getBeanFactory().registerSingleton(postProcessorEntry.getKey(), postProcessorEntry.getValue()); } context.load(configurationPath); context.setParent(applicationContext); context.addBeanFactoryPostProcessor(placeholderConfigurer); context.registerShutdownHook(); context.refresh(); final SpringContextServiceReference serviceReference; if (StringUtils.isNotBlank(serviceBeanName)) { serviceReference = findBeanByName(serviceBeanName, context); } else { serviceReference = findBeanByClass(context); } return serviceReference; }
context.registerShutdownHook(); context.refresh();