Search in sources :

Example 31 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration-samples by spring-projects.

the class GatewayDemoTest method testGatewayDemo.

@Test
public void testGatewayDemo() throws InterruptedException {
    System.setProperty("spring.profiles.active", "testCase");
    final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(configFilesGatewayDemo);
    final MessageChannel stdinToJmsOutChannel = applicationContext.getBean("stdinToJmsOutChannel", MessageChannel.class);
    stdinToJmsOutChannel.send(MessageBuilder.withPayload("jms test").build());
    final QueueChannel queueChannel = applicationContext.getBean("queueChannel", QueueChannel.class);
    @SuppressWarnings("unchecked") Message<String> reply = (Message<String>) queueChannel.receive(20000);
    Assert.assertNotNull(reply);
    String out = reply.getPayload();
    Assert.assertEquals("JMS response: JMS TEST", out);
    applicationContext.close();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.Test)

Example 32 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration-samples by spring-projects.

the class Main method main.

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments
 */
public static void main(final String... args) {
    final Scanner scanner = new Scanner(System.in);
    System.out.println("\n=========================================================" + "\n                                                         " + "\n    Welcome to the Spring Integration                    " + "\n          TCP-Client-Server Sample!                      " + "\n                                                         " + "\n    For more information please visit:                   " + "\n    http://www.springintegration.org/                    " + "\n                                                         " + "\n=========================================================");
    final GenericXmlApplicationContext context = Main.setupContext();
    final SimpleGateway gateway = context.getBean(SimpleGateway.class);
    final AbstractServerConnectionFactory crLfServer = context.getBean(AbstractServerConnectionFactory.class);
    System.out.print("Waiting for server to accept connections...");
    TestingUtilities.waitListening(crLfServer, 10000L);
    System.out.println("running.\n\n");
    System.out.println("Please enter some text and press <enter>: ");
    System.out.println("\tNote:");
    System.out.println("\t- Entering FAIL will create an exception");
    System.out.println("\t- Entering q will quit the application");
    System.out.print("\n");
    System.out.println("\t--> Please also check out the other samples, " + "that are provided as JUnit tests.");
    System.out.println("\t--> You can also connect to the server on port '" + crLfServer.getPort() + "' using Telnet.\n\n");
    while (true) {
        final String input = scanner.nextLine();
        if ("q".equals(input.trim())) {
            break;
        } else {
            final String result = gateway.send(input);
            System.out.println(result);
        }
    }
    System.out.println("Exiting application...bye.");
    System.exit(0);
}
Also used : Scanner(java.util.Scanner) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext)

Example 33 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration-samples by spring-projects.

the class ChannelAdapterDemoTest method testChannelAdapterDemo.

@Test
public void testChannelAdapterDemo() throws InterruptedException {
    System.setProperty("spring.profiles.active", "testCase");
    final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(configFilesChannelAdapterDemo);
    final MessageChannel stdinToJmsOutChannel = applicationContext.getBean("stdinToJmsOutChannel", MessageChannel.class);
    stdinToJmsOutChannel.send(MessageBuilder.withPayload("jms test").build());
    final QueueChannel queueChannel = applicationContext.getBean("queueChannel", QueueChannel.class);
    @SuppressWarnings("unchecked") Message<String> reply = (Message<String>) queueChannel.receive(20000);
    Assert.assertNotNull(reply);
    String out = reply.getPayload();
    Assert.assertEquals("jms test", out);
    applicationContext.close();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.Test)

Example 34 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project ANNIS by korpling.

the class AnnisBaseRunner method getBean.

public static Object getBean(String beanName, boolean logToConsole, String... contextLocations) {
    checkForAnnisHome();
    setupLogging(logToConsole);
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.setValidating(false);
    AnnisXmlContextHelper.prepareContext(ctx);
    ctx.load(contextLocations);
    ctx.refresh();
    return ctx.getBean(beanName);
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext)

Example 35 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project ANNIS by korpling.

the class AnnisServiceRunner method createWebServer.

private void createWebServer() {
    // create beans
    ctx = new GenericXmlApplicationContext();
    ctx.setValidating(false);
    AnnisXmlContextHelper.prepareContext(ctx);
    ctx.load("file:" + Utils.getAnnisFile("conf/spring/Service.xml").getAbsolutePath());
    ctx.refresh();
    ResourceConfig rc = new PackagesResourceConfig("annis.service.internal", "annis.provider", "annis.rest.provider");
    final IoCComponentProviderFactory factory = new SpringComponentProviderFactory(rc, ctx);
    int port = overridePort == null ? ctx.getBean(QueryServiceImpl.class).getPort() : overridePort;
    try {
        // only allow connections from localhost
        // if the administrator wants to allow external acccess he *has* to
        // use a HTTP proxy which also should use SSL encryption
        InetSocketAddress addr = new InetSocketAddress("localhost", port);
        server = new Server(addr);
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
        context.setContextPath("/");
        server.setHandler(context);
        server.setThreadPool(new ExecutorThreadPool());
        ServletContainer jerseyContainer = new ServletContainer(rc) {

            @Override
            protected void initiate(ResourceConfig rc, WebApplication wa) {
                wa.initiate(rc, factory);
            }
        };
        ServletHolder holder = new ServletHolder(jerseyContainer);
        context.addServlet(holder, "/*");
        context.setInitParameter(EnvironmentLoader.ENVIRONMENT_CLASS_PARAM, MultipleIniWebEnvironment.class.getName());
        if (useAuthentification) {
            log.info("Using authentification");
            context.setInitParameter(EnvironmentLoader.CONFIG_LOCATIONS_PARAM, "file:" + System.getProperty("annis.home") + "/conf/shiro.ini," + "file:" + System.getProperty("annis.home") + "/conf/develop_shiro.ini");
        } else {
            log.warn("*NOT* using authentification, your ANNIS service *IS NOT SECURED*");
            context.setInitParameter(EnvironmentLoader.CONFIG_LOCATIONS_PARAM, "file:" + System.getProperty("annis.home") + "/conf/shiro_no_security.ini");
        }
        EnumSet<DispatcherType> gzipDispatcher = EnumSet.of(DispatcherType.REQUEST);
        context.addFilter(GzipFilter.class, "/*", gzipDispatcher);
        // configure Apache Shiro with the web application
        context.addEventListener(new EnvironmentLoaderListener());
        EnumSet<DispatcherType> shiroDispatchers = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ERROR);
        context.addFilter(ShiroFilter.class, "/*", shiroDispatchers);
    } catch (IllegalArgumentException ex) {
        log.error("IllegalArgumentException at ANNIS service startup", ex);
        isShutdownRequested = true;
        errorCode = 101;
    } catch (NullPointerException ex) {
        log.error("NullPointerException at ANNIS service startup", ex);
        isShutdownRequested = true;
        errorCode = 101;
    } catch (AnnisRunnerException ex) {
        errorCode = ex.getExitCode();
    }
}
Also used : EnvironmentLoaderListener(org.apache.shiro.web.env.EnvironmentLoaderListener) Server(org.eclipse.jetty.server.Server) MultipleIniWebEnvironment(annis.security.MultipleIniWebEnvironment) SpringComponentProviderFactory(com.sun.jersey.spi.spring.container.SpringComponentProviderFactory) InetSocketAddress(java.net.InetSocketAddress) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) PackagesResourceConfig(com.sun.jersey.api.core.PackagesResourceConfig) IoCComponentProviderFactory(com.sun.jersey.core.spi.component.ioc.IoCComponentProviderFactory) AnnisRunnerException(annis.AnnisRunnerException) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) ExecutorThreadPool(org.eclipse.jetty.util.thread.ExecutorThreadPool) PackagesResourceConfig(com.sun.jersey.api.core.PackagesResourceConfig) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) WebApplication(com.sun.jersey.spi.container.WebApplication) DispatcherType(javax.servlet.DispatcherType)

Aggregations

GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)61 Test (org.junit.Test)21 Test (org.junit.jupiter.api.Test)13 MBeanServer (javax.management.MBeanServer)5 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)5 Scanner (java.util.Scanner)4 ObjectName (javax.management.ObjectName)4 Resource (org.springframework.core.io.Resource)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 MessageChannel (org.springframework.messaging.MessageChannel)4 ApplicationContext (org.springframework.context.ApplicationContext)3 ByteArrayResource (org.springframework.core.io.ByteArrayResource)3 Message (org.springframework.messaging.Message)3 MBeanOperationInfo (javax.management.MBeanOperationInfo)2 Server (org.eclipse.jetty.server.Server)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 BatchStatus (org.springframework.batch.core.BatchStatus)2 BeanDefinitionParsingException (org.springframework.beans.factory.parsing.BeanDefinitionParsingException)2 CacheInterceptor (org.springframework.cache.interceptor.CacheInterceptor)2