Example usage for org.springframework.context.support AbstractApplicationContext getResource

List of usage examples for org.springframework.context.support AbstractApplicationContext getResource

Introduction

In this page you can find the example usage for org.springframework.context.support AbstractApplicationContext getResource.

Prototype

@Override
    public Resource getResource(String location) 

Source Link

Usage

From source file:org.rivetlogic.export.components.XmlExtractRequestProcessor.java

private void initializeCMSCreds(Ticket ticketParam)
        throws IOException, AuthenticationFailure, CmaRuntimeException {

    // set up the bean factory
    if (beanFactory == null) {
        PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
        AbstractApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");

        Resource resource = context.getResource("classpath:core/cma-cfg.properties");
        Properties properties = new Properties();
        properties.load(resource.getInputStream());

        configurer.setProperties(properties);

        context.addBeanFactoryPostProcessor(configurer);
        context.refresh();//from   ww w.  j  av a  2s  .  c  o m

        beanFactory = context.getBeanFactory();
        authService = (AuthenticationService) beanFactory.getBean("authenticationService",
                AuthenticationServiceImpl.class);
    }

    // get a ticket
    if (this.ticket == null) {

        if (ticketParam != null) {
            this.ticket = ticketParam;

        } else {
            this.ticket = authService.authenticate(cmaUrl, cmaUsername, cmaPassword.toCharArray());
        }
    }

    try {
        authService.validate(ticket);
    } catch (InvalidTicketException e) {
        log.debug("ticket invalid, getting a new one.");
        ticket = authService.authenticate(cmaUrl, cmaUsername, cmaPassword.toCharArray());
    }
}

From source file:org.rivetlogic.export.components.AbstractXMLProcessor.java

private void initialize() throws AuthenticationFailure, CmaRuntimeException, IOException {

    if (ticket == null) {
        if (beanFactory == null) {
            PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
            AbstractApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");

            Resource resource = context.getResource("classpath:core/cma-cfg.properties");
            Properties properties = new Properties();
            properties.load(resource.getInputStream());

            configurer.setProperties(properties);

            context.addBeanFactoryPostProcessor(configurer);
            context.refresh();//from ww  w  .  j a va2 s  .co  m

            beanFactory = context.getBeanFactory();
        }

        authService = (AuthenticationService) beanFactory.getBean("authenticationService",
                AuthenticationServiceImpl.class);

        ticket = authService.authenticate(cmaUrl, cmaUsername, cmaPassword.toCharArray());
        nodeService = (NodeService) beanFactory.getBean("nodeService", NodeServiceImpl.class);
        searchService = (SearchService) beanFactory.getBean("searchService", SearchServiceImpl.class);

        contentService = (ContentServiceImpl) beanFactory.getBean("contentService", ContentServiceImpl.class);
    }

    try {
        authService.validate(ticket);
    } catch (InvalidTicketException e) {
        logger.debug("ticket invalid, getting a new one.");
        ticket = authService.authenticate(cmaUrl, cmaUsername, cmaPassword.toCharArray());
    }
}