Package org.springframework.context.support

Examples of org.springframework.context.support.ClassPathXmlApplicationContext


  /**
   * @param args
   */
  public static void main(String[] args) throws Exception{
    ApplicationContext 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);
  }
View Full Code Here


@IntegrationTest
public class ApplicationTests {

  @Test
  public void testWebSockets() throws InterruptedException {
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("client-context.xml",
        org.springframework.integration.samples.websocket.standard.client.Application.class);
    DirectChannel webSocketInputChannel = ctx.getBean("webSocketInputChannel", DirectChannel.class);

    final CountDownLatch stopLatch = new CountDownLatch(2);

    webSocketInputChannel.addInterceptor(new ChannelInterceptorAdapter() {
      @Override
      public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
        Object payload = message.getPayload();
        assertThat(payload, instanceOf(String.class));
        Date date = null;
        try {
          date = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.DEFAULT).parse((String) payload);
        }
        catch (ParseException e) {
          fail("fail to parse date");
        }
        assertThat(new Date().compareTo(date), greaterThanOrEqualTo(0));
        stopLatch.countDown();
      }

    });
    assertTrue(stopLatch.await(10, TimeUnit.SECONDS));
    ctx.close();
  }
View Full Code Here

public class UserServiceTest {

    @Test
    public void testStartupOfSpringInegrationContext() throws Exception{
        final ApplicationContext context
            = new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml",
                                                  UserServiceTest.class);
        Thread.sleep(2000);
    }
View Full Code Here

    @Test
    public void testExecuteFindUser() {

        final ApplicationContext context
            = new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml",
                                                  UserServiceTest.class);

        final UserService service = context.getBean(UserService.class);

        User user = new User("foo", null, null);
        final User fullUser = service.findUser(user);

        assertEquals("foo", fullUser.getUsername());
View Full Code Here

    @Test
    public void testExecuteFindUserByUsername() {

        final ApplicationContext context
            = new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml",
                                                  UserServiceTest.class);

        final UserService service = context.getBean(UserService.class);

        User user = new User("foo", null, null);
        final User fullUser = service.findUserByUsername(user);

        assertEquals("foo", fullUser.getUsername());
View Full Code Here

*/
public class JmxAdapterDemoTest {

  @Test
  public void testJmxAdapterDemo() throws Exception{
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
        "/META-INF/spring/integration/JmxAdapterDemo-context.xml", JmxAdapterDemoTest.class);
    Thread.sleep(20000);
    context.stop();
  }
View Full Code Here

          + "\n    http://www.springsource.org/spring-integration       "
          + EMPTY_LINE
          + LINE_SEPARATOR );

    final AbstractApplicationContext context =
        new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    final Scanner scanner = new Scanner(System.in);

    final UserService service = context.getBean(UserService.class);

    LOGGER.info(LINE_SEPARATOR
          + EMPTY_LINE
          + "\n    Please press 'q + Enter' to quit the application.                     "
          + EMPTY_LINE
View Full Code Here

          + "\n    http://www.springsource.org/spring-integration       "
          + "\n                                                         "
          + "\n=========================================================" );

    final AbstractApplicationContext context =
        new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/transaction-synch-context.xml");

    context.registerShutdownHook();

    LOGGER.info("\n========================================================="
          + "\n                                                          "
          + "\n    This is the Transaction Synchronization Sample -      "
          + "\n                                                          "
View Full Code Here

public class FtpOutboundChannelAdapterSample {

  @Test
  public void runDemo() throws Exception{
    ConfigurableApplicationContext ctx =
      new ClassPathXmlApplicationContext("META-INF/spring/integration/DynamicFtpOutboundChannelAdapterSample-context.xml");
    MessageChannel channel = ctx.getBean("toDynRouter", MessageChannel.class);
    File file = File.createTempFile("temp", "txt");
    Message<File> message = MessageBuilder.withPayload(file)
            .setHeader("customer", "cust1")
            .build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust1"));
    }
    // send another so we can see in the log we don't create the ac again.
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust1"));
    }
    // send to a different customer; again, check the log to see a new ac is built
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust2").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust2"));
    }

    // send to a different customer; again, check the log to see a new ac is built
    //and the first one created (cust1) should be closed and removed as per the max cache size restriction
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust3").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust3"));
    }

    //send to cust1 again, since this one has been invalidated before, we should
    //see a new ac created (with ac of cust2 destroyed and removed)
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust1").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertEquals("host.for.cust1", e.getCause().getCause().getCause().getMessage());
    }

    ctx.close();
  }
View Full Code Here

*/
public class CafeDemoAppBaristaColdActiveMQ {


  public static void main(String[] args) throws InterruptedException, IOException {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext(
        "/META-INF/spring/integration/activemq/cafeDemo-amq-config.xml",
        "/META-INF/spring/integration/activemq/cafeDemo-amq-baristaCold-xml.xml");

    System.out.println("Press Enter/Return to exit");
    System.in.read();
    context.close();
  }
View Full Code Here

TOP

Related Classes of org.springframework.context.support.ClassPathXmlApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.