Examples of GenericXmlApplicationContext


Examples of org.springframework.context.support.GenericXmlApplicationContext

    System.out.println("\t3. Use EclipseLink");

    System.out.println("\tq. Quit the application");
    System.out.print("Enter you choice: ");

    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    while (true) {
      final String input = scanner.nextLine();

      if("1".equals(input.trim())) {
        context.getEnvironment().setActiveProfiles("hibernate");
        break;
      } else if("2".equals(input.trim())) {
        context.getEnvironment().setActiveProfiles("openjpa");
        break;
      } else if("3".equals(input.trim())) {
        context.getEnvironment().setActiveProfiles("eclipselink");
        break;
      } else if("q".equals(input.trim())) {
        System.out.println("Exiting application...bye.");
        System.exit(0);
      } else {
        System.out.println("Invalid choice\n\n");
        System.out.print("Enter you choice: ");
      }
    }

    context.load("classpath:META-INF/spring/integration/*-context.xml");
    context.registerShutdownHook();
    context.refresh();

    final PersonService personService = context.getBean(PersonService.class);

    System.out.println("Please enter a choice and press <enter>: ");
    System.out.println("\t1. List all people");
    System.out.println("\t2. Create a new person");
    System.out.println("\tq. Quit the application");
View Full Code Here

Examples of org.springframework.context.support.GenericXmlApplicationContext

            + "\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");
View Full Code Here

Examples of org.springframework.context.support.GenericXmlApplicationContext

  /**
   * @param args Not used.
   */
  public static void main(String... args) throws Exception{

    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    final ConfigurableEnvironment env = context.getEnvironment();
    boolean mapQuestApiKeyDefined = env.containsProperty("mapquest.apikey");

    if (mapQuestApiKeyDefined) {
      env.setActiveProfiles("mapquest");
    }

    context.load("classpath:META-INF/spring/*.xml");
    context.refresh();

    final TravelGateway travelGateway = context.getBean("travelGateway", TravelGateway.class);

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

    System.out.println("\n========================================================="
            + "\n                                                         "
View Full Code Here

Examples of org.springframework.context.support.GenericXmlApplicationContext

   * @param targetClass the class who's classloader we will use to laod the context file
   * @param profile a profile name
   * @return the spring context
   */
  public static AbstractApplicationContext loadProfileContext(String path, Class<?> targetClass, String profile) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.getEnvironment().setActiveProfiles(profile);
    ctx.setClassLoader(targetClass.getClassLoader());
    ctx.load(path);
    ctx.refresh();
    return ctx;
  }
View Full Code Here

Examples of org.springframework.context.support.GenericXmlApplicationContext

    System.exit(0);

  }

  public static GenericXmlApplicationContext setupContext() {
    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    System.out.print("Detect open server socket...");
    int availableServerSocket = SocketUtils.findAvailableServerSocket(5678);

    final Map<String, Object> sockets = new HashMap<String, Object>();
    sockets.put("availableServerSocket", availableServerSocket);

    final MapPropertySource propertySource = new MapPropertySource("sockets", sockets);

    context.getEnvironment().getPropertySources().addLast(propertySource);

    System.out.println("using port " + context.getEnvironment().getProperty("availableServerSocket"));

    context.load("classpath:META-INF/spring/integration/tcpClientServerDemo-context.xml");
    context.registerShutdownHook();
    context.refresh();

    return context;
  }
View Full Code Here

Examples of org.springframework.context.support.GenericXmlApplicationContext

  @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();
  }
View Full Code Here

Examples of org.springframework.context.support.GenericXmlApplicationContext

  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>:");
    }

    context.close();
    System.out.println("Back to main menu.");

  }
View Full Code Here

Examples of org.springframework.context.support.GenericXmlApplicationContext

  @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();
  }
View Full Code Here

Examples of org.springframework.context.support.GenericXmlApplicationContext

  private static void executeSample2() {

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

    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load("classpath:META-INF/spring/integration/spring-integration-sample2-context.xml");
    context.registerShutdownHook();
    context.refresh();

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

    final String message = "\n\n" +
      "* Please enter 'list' and press <enter> to get a list of coffees.\n" +
      "* Enter a coffee id, e.g. '1' and press <enter> to get a description.\n" +
      "* Please press 'q + Enter' to quit the application.\n";

    System.out.println(message);

    while (!scanner.hasNext("q")) {

      String input = scanner.nextLine();

      if ("list".equalsIgnoreCase(input)) {
        List<CoffeeBeverage> coffeeBeverages = service.findAllCoffeeBeverages();

        for (CoffeeBeverage coffeeBeverage : coffeeBeverages) {
          System.out.println(String.format("%s - %s", coffeeBeverage.getId(),
                                coffeeBeverage.getName()));
        }

      } else {
        System.out.println("Retrieving coffee information...");
        String coffeeDescription = service.findCoffeeBeverage(Integer.valueOf(input));

        System.out.println(String.format("Searched for '%s' - Found: '%s'.", input, coffeeDescription));
        System.out.print("To try again, please enter another coffee beverage and press <enter>:\n\n");
      }

    }

    context.close();

    System.out.println("Back to main menu.");
  }
View Full Code Here

Examples of org.springframework.context.support.GenericXmlApplicationContext

    System.out.println("\t3. Use a Dummy client");

    System.out.println("\tq. Quit the application");
    System.out.print("Enter you choice: ");

    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    while (true) {
      final String input = scanner.nextLine();

      if("1".equals(input.trim())) {
        context.getEnvironment().setActiveProfiles("default");
        break;
      } else if("2".equals(input.trim())) {
        context.getEnvironment().setActiveProfiles("jetty");
        break;
      } else if("3".equals(input.trim())) {
        context.getEnvironment().setActiveProfiles("dummy");
        break;
      } else if("q".equals(input.trim())) {
        System.out.println("Exiting application...bye.");
        System.exit(0);
      } else {
        System.out.println("Invalid choice\n\n");
        System.out.print("Enter you choice: ");
      }
    }

    context.load("classpath:META-INF/spring/integration/*-context.xml");
    context.registerShutdownHook();
    context.refresh();

    final ConnectionBroker connectionBroker = context.getBean(ConnectionBroker.class);

    if (LOGGER.isInfoEnabled()) {
      LOGGER.info("\n========================================================="
            + "\n                                                         "
            + "\n    Please press 'q + Enter' to quit the application.    "
            + "\n    For statistical information press 'i + Enter'.       "
            + "\n                                                         "
            + "\n    In your browser open:                                "
            + "\n    file:///.../src/main/webapp/index.html               "
            + "\n=========================================================" );
    }

    while (true) {

      final String input = scanner.nextLine();

      if("q".equals(input.trim())) {
        break;
      }
      else if("i".equals(input.trim()))  {
        LOGGER.info("\n========================================================="
              + "\n                                                         "
              + "\n Number of connected clients: " + connectionBroker.connectedClients()
              + "\n                                                         "
              + "\n=========================================================" );
      }

    }

    if (LOGGER.isInfoEnabled()) {
      LOGGER.info("Exiting application...bye.");
    }

    context.close();
    System.exit(0);

  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.