예제 #1
0
 public void initialize() throws TaskSystemException {
   try {
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     DocumentBuilder builder = factory.newDocumentBuilder();
     Document document = builder.parse(getTaskConfigurationInputSource());
     NodeList rootElement =
         document.getElementsByTagName(SchedulerConstants.SPRING_BEANS_FILE_ROOT_TAG);
     if (rootElement.getLength() > 0) { // new Quartz scheduler
       springTaskContext =
           new FileSystemXmlApplicationContext("file:" + getTaskConfigurationFilePath());
       scheduler =
           (Scheduler) springTaskContext.getBean(SchedulerConstants.SPRING_SCHEDULER_BEAN_NAME);
       jobExplorer =
           (JobExplorer) springTaskContext.getBean(SchedulerConstants.JOB_EXPLORER_BEAN_NAME);
       jobRepository =
           (JobRepository) springTaskContext.getBean(SchedulerConstants.JOB_REPOSITORY_BEAN_NAME);
       jobLauncher =
           (JobLauncher) springTaskContext.getBean(SchedulerConstants.JOB_LAUNCHER_BEAN_NAME);
       jobLocator =
           (JobLocator) springTaskContext.getBean(SchedulerConstants.JOB_LOCATOR_BEAN_NAME);
     } else { // old legacy Mifos Scheduler
       StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
       String configPath = getQuartzSchedulerConfigurationFilePath();
       schedulerFactory.initialize(configPath);
       scheduler = schedulerFactory.getScheduler();
       if (!scheduler.isInStandbyMode()) {
         scheduler.standby();
       }
       registerTasksOldConfigurationFile(document);
       scheduler.start();
     }
   } catch (Exception e) {
     throw new TaskSystemException(e);
   }
 }
예제 #2
0
 public MongoEngine() {
   context = new ClassPathXmlApplicationContext("org/soldieringup/mongo-config.xml");
   userRepository = context.getBean(UserRepository.class);
   accountRepository = context.getBean(SoldierUpAccountRepository.class);
   zipRepository = context.getBean(ZipRepository.class);
   tagRepository = context.getBean(TagRepository.class);
   questionRepository = context.getBean(QuestionRepository.class);
   meetingRepository = context.getBean(MeetingRequestRepository.class);
 }
 @Test
 public void reverseEndpoint() throws Exception {
   ConfigurableApplicationContext context =
       new SpringApplicationBuilder(
               ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class)
           .properties("websocket.uri:ws://localhost:" + PORT + "/ws/reverse")
           .run("--spring.main.web_environment=false");
   long count = context.getBean(ClientConfiguration.class).latch.getCount();
   AtomicReference<String> messagePayloadReference =
       context.getBean(ClientConfiguration.class).messagePayload;
   context.close();
   assertThat(count).isEqualTo(0);
   assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
 }
 @Test
 public void testSubscribersNotInterrupted() throws Exception {
   ConfigurableApplicationContext context =
       SpringApplication.run(TestTimeWindows.class, "--server.port=0");
   Sink sink = context.getBean(Sink.class);
   TestTimeWindows testTimeWindows = context.getBean(TestTimeWindows.class);
   sink.input().send(MessageBuilder.withPayload("hello1").build());
   sink.input().send(MessageBuilder.withPayload("hello2").build());
   sink.input().send(MessageBuilder.withPayload("hello3").build());
   assertThat(testTimeWindows.latch.await(5, TimeUnit.SECONDS)).isTrue();
   assertThat(testTimeWindows.interruptionState).isNotNull();
   assertThat(testTimeWindows.interruptionState).isFalse();
   context.close();
 }
예제 #5
0
  public void initialize() {
    try {
      if (appContext == null) {
        appContext = new ClassPathXmlApplicationContext(DLRConstants.appContextPath);
      }

      schema = getSchema();
      schema = schema + ".";

      jdbcTemplate = (JdbcTemplate) appContext.getBean("jdbcTemplate");

      // Use connection to run query because it is faster and use less
      // memory than JdbcTemplate.queryForList()
      con1 = jdbcTemplate.getDataSource().getConnection();

      ht.clear();
      ht.put("01", "JR.  ");
      ht.put("02", "SR.  ");
      ht.put("03", "II   ");
      ht.put("04", "III  ");
      ht.put("05", "IV   ");
      ht.put("06", "V    ");
      ht.put("07", "VI   ");
      ht.put("08", "VII  ");
      ht.put("09", "VIII ");
      ht.put("10", "IX   ");
    } catch (Exception e) {
      logger.error("Exception during initialize()", e);
      System.out.println(e);
      rc = false;
    }
  }
예제 #6
0
  private IBatchProcessor getBatchProcessor() {
    IBatchProcessor iBatchProcessor = null;

    iBatchProcessor = (IBatchProcessor) appContext.getBean("baseBatchProcessor");

    return iBatchProcessor;
  }
 @Override
 public void addInterceptors(final InterceptorRegistry registry) {
   LocaleChangeInterceptor localeChangeInterceptor =
       applicationContext.getBean(LocaleChangeInterceptor.class);
   Assert.notNull(localeChangeInterceptor);
   registry.addInterceptor(localeChangeInterceptor);
 }
예제 #8
0
  public static void main(String[] args) {
    System.out.println("load context");
    ConfigurableApplicationContext context =
        new ClassPathXmlApplicationContext("spring-config.xml");

    Projects johnsproject = new Projects();
    johnsproject.setProjectTitle("APP project");
    johnsproject.setProjectType("IOS");

    List<Projects> projectList = new ArrayList<Projects>();
    projectList.add(johnsproject);

    Employee em = new Employee();
    em.setId("11");
    em.setName("eee");
    em.setAge(22);
    em.setProjects(projectList);

    EmployeeService emService = (EmployeeService) context.getBean("employeeService");

    emService.persistEmployee(em);
    System.out.println("Updated age :" + emService.findEmployeeById("11").getAge());

    //        em.setAge(53);
    //        emService.updateEmployee(em);
    //        System.out.println("Updated age :" + emService.findEmployeeById("88").getAge());

    emService.deleteEmployee(em);

    context.close();
  }
예제 #9
0
 public static void main(String[] args) {
   ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
   CustomEventPublisher customEventPublisher =
       (CustomEventPublisher) context.getBean("customEventPublisher");
   customEventPublisher.publish();
   customEventPublisher.publish();
 }
 public static void main(String[] args) {
   ConfigurableApplicationContext context =
       new ClassPathXmlApplicationContext("/META-INF/spring/integration/http-outbound-config.xml");
   RequestGateway requestGateway = context.getBean("requestGateway", RequestGateway.class);
   String reply = requestGateway.echo("Hello");
   logger.info("\n\n++++++++++++ Replied with: " + reply + " ++++++++++++\n");
 }
  @Test
  public void simpleMessageListener() {
    ConfigurableApplicationContext context =
        new AnnotationConfigApplicationContext(Config.class, SimpleMessageListenerTestBean.class);

    JmsListenerContainerTestFactory factory =
        context.getBean(JmsListenerContainerTestFactory.class);
    assertEquals(
        "One container should have been registered", 1, factory.getListenerContainers().size());
    MessageListenerTestContainer container = factory.getListenerContainers().get(0);

    JmsListenerEndpoint endpoint = container.getEndpoint();
    assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
    MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
    assertNotNull(methodEndpoint.getBean());
    assertNotNull(methodEndpoint.getMethod());

    SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
    methodEndpoint.setupListenerContainer(listenerContainer);
    assertNotNull(listenerContainer.getMessageListener());

    assertTrue("Should have been started " + container, container.isStarted());
    context.close(); // Close and stop the listeners
    assertTrue("Should have been stopped " + container, container.isStopped());
  }
예제 #12
0
 // works sort of. doesn't resolve placeholders in the loaded context. can;t load beans from
 // bootstrap context
 public static void bootstrap() {
   //	    System.setProperty("context", "Spel-context2.xml");
   ConfigurableApplicationContext ctx =
       new ClassPathXmlApplicationContext(
           "classpath:/com/rooney/spring/spel/Spel-bootstrap-context.xml");
   System.out.println(ctx.getBean("stringBean"));
   // System.out.println(ctx.getBean("stringBeanBootstrap"));
 }
예제 #13
0
파일: Main.java 프로젝트: HarishM/adbcj
  public static void main(String[] args) {
    ConfigurableApplicationContext applicationContext =
        new ClassPathXmlApplicationContext("META-INF/spring/applicationContext.xml");

    ServerBootstrap bootstrap = applicationContext.getBean("bootstrap", ServerBootstrap.class);
    bootstrap.bind(new InetSocketAddress(8080));
    System.out.println("Server ready");
  }
예제 #14
0
 public static void main(String[] args) {
   @SuppressWarnings("resource")
   ConfigurableApplicationContext context =
       new ClassPathXmlApplicationContext("BeansCustEvent.xml");
   CustomEventPublisher cvp = (CustomEventPublisher) context.getBean("customEventPublisher");
   cvp.publish();
   cvp.publish();
 }
 @Test
 public void testDefaultProfile() {
   SpringApplication app = new SpringApplication(AdminApplication.class);
   ConfigurableApplicationContext context = app.run(new String[] {"--server.port=0"});
   assertThat(context.containsBean("processModuleDeployer"), is(true));
   assertThat(context.getBean("processModuleDeployer"), instanceOf(LocalModuleDeployer.class));
   context.close();
 }
 @Test
 public void simpleDynamicRouter() {
   context.start();
   Message<?> message = new GenericMessage<Integer>(1);
   simpleDynamicInput.send(message);
   PollableChannel chanel1 = (PollableChannel) context.getBean("channel1");
   PollableChannel chanel2 = (PollableChannel) context.getBean("channel2");
   assertTrue(chanel1.receive(0).getPayload().equals(1));
   assertNull(chanel2.receive(0));
 }
예제 #17
0
 public static void main(final String[] args) {
   try (ConfigurableApplicationContext ctx =
       new SpringApplicationBuilder()
           .bannerMode(Mode.OFF)
           .sources(Application.class)
           .build()
           .run(args)) {
     ctx.getBean(CamelSpringBootApplicationController.class).blockMainThread();
   }
 }
 @Before
 public void bootstrapTestContext() throws Exception {
   context =
       new ClassPathXmlApplicationContext(
           "/spring-scheduleevent.xml", "/spring-scheduleevent-embbed-datasource.xml");
   databaseTester = new DataSourceDatabaseTester(getDataSource());
   databaseTester.setDataSet(getDataSet());
   databaseTester.onSetup();
   scheduleEventDao = context.getBean(ScheduleEventDao.class);
 }
예제 #19
0
  public static void main(String[] args) {
    // java 7 Automatic resource management
    try (ConfigurableApplicationContext appCtx =
        new ClassPathXmlApplicationContext("spring/spring-app.xml", "spring/mock.xml")) {
      System.out.println(Arrays.toString(appCtx.getBeanDefinitionNames()));
      AdminRestController adminUserController = appCtx.getBean(AdminRestController.class);
      System.out.println(
          adminUserController.create(
              new User(1, "userName", "email", "password", 2005, Role.ROLE_ADMIN)));
      System.out.println();

      UserMealRestController mealController = appCtx.getBean(UserMealRestController.class);
      List<UserMealWithExceed> filteredMealsWithExceeded =
          mealController.getBetween(
              LocalDate.of(2015, Month.MAY, 30), LocalTime.of(7, 0),
              LocalDate.of(2015, Month.MAY, 31), LocalTime.of(11, 0));
      filteredMealsWithExceeded.forEach(System.out::println);
    }
  }
 @Test
 public void checkMessageRouting() {
   context.start();
   Message<?> message = new GenericMessage<Integer>(1);
   channel.send(message);
   PollableChannel chanel1 = (PollableChannel) context.getBean("channel1");
   PollableChannel chanel2 = (PollableChannel) context.getBean("channel2");
   assertTrue(chanel1.receive(0).getPayload().equals(1));
   assertTrue(chanel2.receive(0).getPayload().equals(1));
 }
예제 #21
0
  public static void main(String[] args) {
    ConfigurableApplicationContext context =
        new ClassPathXmlApplicationContext("springMailContext.xml");
    SendMailExample bean = (SendMailExample) context.getBean("mailService");

    // bean.sendMail("*****@*****.**", "*****@*****.**", "FYME email test",
    //		"Testing.. \n Hello Spring Email Sender");
    // bean.sendMailWithTemplate("User", "Welcome to FYME");
    bean.sendMailWithAttachment("User", "Welcome to FYME");
    context.close();
  }
  @Before
  public void setUp() throws Exception {
    // get the original path
    originalImage = new File(getClass().getResource("/" + IMAGE_NAME).getPath());
    assertThat(originalImage.exists(), is(true));

    // bootstrap the Spring context
    ctx = new ClassPathXmlApplicationContext("classpath:/spring-image.xml");
    ctx.start();
    processor = ctx.getBean(ImageResizingProcessor.class);
  }
예제 #23
0
 private void sendEvent(EventEndpoint endpoint, ApplicationEventNFVO event) {
   EventSender sender =
       (EventSender) context.getBean(endpoint.getType().toString().toLowerCase() + "EventSender");
   log.trace("Sender is: " + sender.getClass().getSimpleName());
   try {
     sender.send(endpoint, event);
   } catch (IOException e) {
     e.printStackTrace();
     log.error("Error while dispatching event " + event);
   }
 }
  @Test
  public void withAnnotationOnArgumentAndCglibProxy() {
    ConfigurableApplicationContext ctx =
        new AnnotationConfigApplicationContext(
            ConfigWithCglibProxy.class, SampleService.class, LoggingAspect.class);

    SampleService sampleService = ctx.getBean(SampleService.class);
    sampleService.execute(new SampleDto());
    sampleService.execute(new SampleInputBean());
    sampleService.execute((SampleDto) null);
    sampleService.execute((SampleInputBean) null);
  }
 @Test
 public void noSelectorMatchRouter() {
   context.start();
   Message<?> message = new GenericMessage<Integer>(1);
   noSelectorMatchInput.send(message);
   PollableChannel chanel1 = (PollableChannel) context.getBean("channel1");
   PollableChannel chanel2 = (PollableChannel) context.getBean("channel2");
   Message<?> output = chanel1.receive(0);
   assertNotNull(output);
   assertTrue(output.getPayload().equals(1));
   assertNull(chanel2.receive(0));
 }
예제 #26
0
  public static void main(String[] args) {
    try {
      ConfigurableApplicationContext applicationContext =
          SpringApplication.run(SwitterBotApplication.class, args);

      final PostService postService = (PostService) applicationContext.getBean("postService");
      Thread postThread =
          new Thread(
              new Runnable() {
                @Override
                public void run() {
                  int delayMultiplier = 1;
                  while (true) {
                    try {
                      if (!postService.postNewPicture()) {
                        System.out.println("NO PICTURES TO POST!");
                        delayMultiplier = delayMultiplier * 2;
                      } else {
                        delayMultiplier = 1;
                      }
                      Thread.sleep(60000 * 30 * delayMultiplier);
                    } catch (Exception e) {
                      e.printStackTrace();
                      return;
                    }
                  }
                }
              });
      postThread.start();
      postThread.join();

      /*final CleanService cleanService = (CleanService) applicationContext.getBean("cleanService");
      Thread cleanThread = new Thread(new Runnable() {
          @Override
          public void run() {
              while (true) {
                  try {
                      cleanService.clean();
                      Thread.sleep(60000*60*24);
                  } catch (Exception e) {
                      e.printStackTrace();
                      return;
                  }
              }
          }
      });
      cleanThread.start();
      cleanThread.join();*/

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #27
0
파일: App.java 프로젝트: kerryland/examples
  public static void main(String[] args) {
    final ConfigurableApplicationContext context =
        new AnnotationConfigApplicationContext(AppConfig.class, DbConfig.class);
    System.out.println("spring-tx-text start");

    try {
      context.start();

      if (LOGGER.isDebugEnabled()) {
        final Map<String, Object> beanDefMap = context.getBeansOfType(Object.class);
        LOGGER.debug("Bean definitions: {}", beanDefMap);
      }

      // run application service
      context.getBean(AppService.class).run(args);

      context.getBean(DbaService.class).doDbAccess();
    } finally {
      context.close();
    }
  }
예제 #28
0
  protected void onSetUp() throws Exception {
    ConfigurableApplicationContext cac = getContext(getConfigLocations());

    synchronized (isInitialized) {
      if (!isInitialized.booleanValue()) {

        invoiceService = (IInvoiceService) cac.getBean("invoiceService");
        accountService = (IAccountService) cac.getBean("accountService");
        contractService = (IContractService) cac.getBean("contractService");
        familyAccountService = (IFamilyAccountService) cac.getBean("familyAccountService");
        paymentService = (IPaymentService) cac.getBean("paymentService");
        externalApplicationService =
            (IExternalApplicationService) cac.getBean("externalApplicationService");

        webServiceClient = (WebServiceClient) cac.getBean("webServiceClient");

        // create an external application to be used by tests cases
        try {
          externalApplication =
              BusinessObjectsFactory.gimmeExternalApplication("ExternalApplication");
          externalApplicationService.create(externalApplication);
        } catch (CpmBusinessException e) {
          // can't happen
        }

        logger.debug("onSetUp() starting");
        isInitialized = Boolean.TRUE;
      }
    }
  }
  @SuppressWarnings("resource")
  public static void main(String[] args) {

    ConfigurableApplicationContext context =
        new ClassPathXmlApplicationContext("example-xmlconfig.xml");

    BusinessLogic businessLogic = context.getBean("businessLogic", BusinessLogic.class);

    businessLogic.doBusiness("http://example.org/remotefile");

    context.close();
    System.out.println("Application ended");
  }
  @Test
  public void testWorkflow() throws Exception {
    final ConfigurableApplicationContext context =
        new ClassPathXmlApplicationContext(
            new String[] {
              "transient-engine-application-context.xml",
              "SimpleTransientEngineTest-application-context.xml"
            });
    final TransientScottyEngine engine = (TransientScottyEngine) context.getBean("transientEngine");
    final BackChannelQueue backChannelQueue = context.getBean(BackChannelQueue.class);

    assertEquals(EngineState.STARTED, engine.getEngineState());

    try {
      engine.run("de.scoopgmbh.copper.test.tranzient.simple.SimpleTestParentWorkflow", "testData");
      WorkflowResult r = backChannelQueue.dequeue(2000, TimeUnit.MILLISECONDS);
      assertNotNull(r);
    } finally {
      context.close();
    }
    assertEquals(EngineState.STOPPED, engine.getEngineState());
  }