Example usage for org.springframework.context.support ClassPathXmlApplicationContext close

List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext close

Introduction

In this page you can find the example usage for org.springframework.context.support ClassPathXmlApplicationContext close.

Prototype

@Override
public void close() 

Source Link

Document

Close this application context, destroying all beans in its bean factory.

Usage

From source file:org.springframework.integration.monitor.MessageChannelsMonitorIntegrationTests.java

@Test
public void testQueues() throws Exception {

    ClassPathXmlApplicationContext context = createContext("queue-channel.xml", "queue");
    try {/*  w  w  w.j av  a  2  s  . c  om*/
        int before = service.getCounter();
        for (int i = 0; i < 5; i++) {
            channel.send(new GenericMessage<String>("bar"));
            Thread.sleep(20L);
        }
        try {
            channel.send(new GenericMessage<String>("fail"));
        } catch (MessageHandlingException e) {
            // ignore
        }
        for (int i = 0; i < 5; i++) {
            channel.send(new GenericMessage<String>("bar"));
            Thread.sleep(20L);
        }
        assertEquals(before + 10, service.getCounter());

        // The handler monitor is registered under the endpoint id (since it is explicit)
        int sends = messageChannelsMonitor.getChannelSendRate("" + channel).getCount();
        assertEquals("No send statistics for input channel", 11, sends);
        int receives = messageChannelsMonitor.getChannelReceiveCount("" + channel);
        assertEquals("No send statistics for input channel", 11, receives);
        int errors = messageChannelsMonitor.getChannelErrorRate("" + channel).getCount();
        assertEquals("Expect no errors for input channel (handler fails)", 0, errors);
    } finally {
        context.close();
    }

}

From source file:org.springframework.integration.monitor.MessageChannelsMonitorIntegrationTests.java

private void doTest(String config, String channelName) throws Exception {

    ClassPathXmlApplicationContext context = createContext(config, channelName);

    try {//from   www . ja  va2s.  c o  m

        int before = service.getCounter();
        channel.send(new GenericMessage<String>("bar"));
        assertEquals(before + 1, service.getCounter());

        // The handler monitor is registered under the endpoint id (since it is explicit)
        int sends = messageChannelsMonitor.getChannelSendRate("" + channel).getCount();
        assertEquals("No statistics for input channel", 1, sends, 0.01);

    } finally {
        context.close();
    }

}

From source file:org.springframework.integration.samples.jdbc.OutboundGatewayTest.java

@Test
public void insertPersonRecord() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/spring/integration/spring-integration-context.xml");
    PersonService service = context.getBean(PersonService.class);
    logger.info("Creating person Instance");
    Person person = new Person();
    Calendar dateOfBirth = Calendar.getInstance();
    dateOfBirth.set(1980, 0, 1);/*from   w w w  . j ava  2 s .c o  m*/
    person.setDateOfBirth(dateOfBirth.getTime());
    person.setName("Name Of The Person");
    person.setGender(Gender.MALE);
    person = service.createPerson(person);
    Assert.assertNotNull("Expected a non null instance of Person, got null", person);
    logger.info("\n\tGenerated person with id: " + person.getPersonId() + ", with name: " + person.getName());
    context.close();
}

From source file:org.springframework.integration.samples.loanbroker.demo.LoanBrokerDemo.java

public void runDemo() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "META-INF/spring/integration/bootstrap-config/stubbed-loan-broker.xml");
    LoanBrokerGateway broker = context.getBean("loanBrokerGateway", LoanBrokerGateway.class);
    LoanRequest loanRequest = new LoanRequest();
    loanRequest.setCustomer(new Customer());
    LoanQuote loan = broker.getBestLoanQuote(loanRequest);
    logger.info("********* Best Quote *********\n" + loan);
    System.out.println("==============================");
    List<LoanQuote> loanQuotes = broker.getAllLoanQuotes(loanRequest);
    logger.info("********* All Quotes *********");
    for (LoanQuote loanQuote : loanQuotes) {
        logger.info(loanQuote);/*from   www. j a  v a2  s.  c o  m*/
    }
    context.close();
}

From source file:org.springframework.integration.samples.multipart.MultipartClientForHttpOutboundClient.java

public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/spring/integration/http-outbound-config.xml");
    Resource s2logo = new ClassPathResource(resourcePath);
    Map<String, Object> multipartMap = new HashMap<String, Object>();
    multipartMap.put("company", new String[] { "SpringSource", "VMWare" });
    multipartMap.put("company-logo", s2logo);
    logger.info("Created multipart request: " + multipartMap);
    MultipartRequestGateway requestGateway = context.getBean("requestGateway", MultipartRequestGateway.class);
    HttpStatus reply = requestGateway.postMultipartRequest(multipartMap);
    System.out.println("Replied with HttpStatus code: " + reply);
    context.close();
}

From source file:org.springframework.security.authentication.jaas.DefaultJaasAuthenticationProviderTests.java

License:asdf

@Test
public void javadocExample() {
    String resName = "/" + getClass().getName().replace('.', '/') + ".xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(resName);
    context.registerShutdownHook();//from   w  w  w . j  a  v  a  2s.co  m
    try {
        provider = context.getBean(DefaultJaasAuthenticationProvider.class);
        Authentication auth = provider.authenticate(token);
        assertThat(auth.isAuthenticated()).isEqualTo(true);
        assertThat(auth.getPrincipal()).isEqualTo(token.getPrincipal());
    } finally {
        context.close();
    }
}

From source file:org.springmodules.samples.hivemind.main.TestHivemind.java

/**
 * Main method to launch the sample application
 *
 * @param args main arguments/*from   w  ww  .  j a  va2s .  c  o  m*/
 */
public static void main(String[] args) {
    ClassPathXmlApplicationContext ctx = null;
    try {
        ctx = new ClassPathXmlApplicationContext("/applicationContext.xml");
        ISampleService service = (ISampleService) ctx.getBean("hivemindService");
        service.executeService("sample");

    } catch (Exception ex) {
        log.error("Error during execution", ex);
    } finally {
        if (ctx != null) {
            ctx.close();
        }
    }
}

From source file:org.springmodules.samples.jsr94.main.TestJSR94.java

/**
 * Main method to launch the sample application
 * @param args main arguments//from  w w  w  .ja  v a2  s .c om
 */
public static void main(String[] args) {
    ClassPathXmlApplicationContext ctx = null;
    try {
        ctx = new ClassPathXmlApplicationContext(getContextEngine(args));
        CarsService service = (CarsService) ctx.getBean("carsService");
        showGoodBargainCars(service);
    } catch (Exception ex) {
        ex.printStackTrace();
        log.error("Error during execution", ex);
    } finally {
        if (ctx != null) {
            ctx.close();
        }
    }
}