Example usage for org.springframework.beans.factory.config PropertiesFactoryBean getObject

List of usage examples for org.springframework.beans.factory.config PropertiesFactoryBean getObject

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config PropertiesFactoryBean getObject.

Prototype

@Override
    @Nullable
    public final Properties getObject() throws IOException 

Source Link

Usage

From source file:com.vnet.demo.service.azure.servicebus.AzureServiceBusServiceFactory.java

public AzureServiceBusService create() {
    if (this.azureServiceBusService == null) {
        try {/*from ww  w  .j a v a 2s  .  c o  m*/
            PropertiesFactoryBean properties = SpringUtil.getBean(PropertiesFactoryBean.class);
            this.username = (String) properties.getObject().get("azure.servicebus.username");
            this.password = (String) properties.getObject().get("azure.servicebus.password");
            this.host = (String) properties.getObject().get("azure.servicebus.host");
            String defaultQueue = (String) properties.getObject().get("azure.servicebus.queue");

            String connectionString = "amqps://" + username + ":" + encode(password) + "@" + host;
            Hashtable<String, String> env = new Hashtable<String, String>();
            env.put(Context.INITIAL_CONTEXT_FACTORY,
                    "org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
            env.put("connectionfactory.ServiceBusConnectionFactory", connectionString);

            Context context = new InitialContext(env);
            ConnectionFactory connectionFactory = (ConnectionFactory) context
                    .lookup("ServiceBusConnectionFactory");
            azureServiceBusService = new AzureServiceBusService(connectionFactory, defaultQueue);
        } catch (NamingException | IOException e) {
            e.printStackTrace();
        }
        ;
    }
    return this.azureServiceBusService;
}

From source file:com.orange.clara.pivotaltrackermirror.config.QuartzConfig.java

@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}

From source file:edu.harvard.i2b2.fr.util.FRUtil.java

/**
 * Load application property file into memory
 *///from w w w  .  j  a  va 2 s  .co m
private String getPropertyValue(String propertyName) throws I2B2Exception {
    if (appProperties == null) {
        //read application directory property file
        loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
        //read application directory property
        String appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);
        if (appDir == null) {
            throw new I2B2Exception("Could not find " + APPLICATIONDIR_PROPERTIES + "from "
                    + APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
        }
        String appPropertyFile = appDir + "/" + APPLICATION_PROPERTIES_FILENAME;
        try {
            FileSystemResource fileSystemResource = new FileSystemResource(appPropertyFile);
            PropertiesFactoryBean pfb = new PropertiesFactoryBean();
            pfb.setLocation(fileSystemResource);
            pfb.afterPropertiesSet();
            appProperties = (Properties) pfb.getObject();
        } catch (IOException e) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }
        if (appProperties == null) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }
    }

    String propertyValue = appProperties.getProperty(propertyName);

    if ((propertyValue != null) && (propertyValue.trim().length() > 0)) {
        ;
    } else {
        throw new I2B2Exception("Application property file(" + APPLICATION_PROPERTIES_FILENAME + ") missing "
                + propertyName + " entry");
    }

    return propertyValue;
}

From source file:edu.harvard.i2b2.pm.util.PMUtil.java

/**
 * Load application property file into memory
 *//*from  w  ww.jav  a2s.  c om*/
private String getPropertyValue(String propertyName) throws I2B2Exception {
    if (appProperties == null) {
        //read application directory property file
        Properties loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);

        //read application directory property
        String appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);

        if (appDir == null) {
            throw new I2B2Exception("Could not find " + APPLICATIONDIR_PROPERTIES + "from "
                    + APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
        }

        String appPropertyFile = appDir + "/" + APPLICATION_PROPERTIES_FILENAME;

        try {
            FileSystemResource fileSystemResource = new FileSystemResource(appPropertyFile);
            PropertiesFactoryBean pfb = new PropertiesFactoryBean();
            pfb.setLocation(fileSystemResource);
            pfb.afterPropertiesSet();
            appProperties = (Properties) pfb.getObject();
        } catch (IOException e) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }

        if (appProperties == null) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }
    }

    String propertyValue = appProperties.getProperty(propertyName);

    if ((propertyValue != null) && (propertyValue.trim().length() > 0)) {
        ;
    } else {
        throw new I2B2Exception("Application property file(" + APPLICATION_PROPERTIES_FILENAME + ") missing "
                + propertyName + " entry");
    }

    return propertyValue;
}

From source file:edu.harvard.i2b2.ontology.util.OntologyUtil.java

/**
 * Load application property file into memory
 *//*  ww w. ja  v a2  s  .co  m*/
private String getPropertyValue(String propertyName) throws I2B2Exception {
    if (appProperties == null) {
        // read application directory property file
        Properties loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);

        // read application directory property
        String appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);

        if (appDir == null) {
            throw new I2B2Exception("Could not find " + APPLICATIONDIR_PROPERTIES + "from "
                    + APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
        }

        String appPropertyFile = appDir + "/" + APPLICATION_PROPERTIES_FILENAME;

        try {
            FileSystemResource fileSystemResource = new FileSystemResource(appPropertyFile);
            PropertiesFactoryBean pfb = new PropertiesFactoryBean();
            pfb.setLocation(fileSystemResource);
            pfb.afterPropertiesSet();
            appProperties = (Properties) pfb.getObject();
        } catch (IOException e) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }

        if (appProperties == null) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }
    }

    String propertyValue = appProperties.getProperty(propertyName);

    if ((propertyValue != null) && (propertyValue.trim().length() > 0)) {
        ;
    } else {
        throw new I2B2Exception("Application property file(" + APPLICATION_PROPERTIES_FILENAME + ") missing "
                + propertyName + " entry");
    }

    return propertyValue;
}

From source file:edu.harvard.i2b2.crc.loader.util.CRCLoaderUtil.java

/**
 * Load application property file into memory
 *//*from w  ww.ja  v a  2  s  .  c  om*/
private String getPropertyValue(String propertyName) throws I2B2Exception {
    if (appProperties == null) {
        // read application directory property file
        loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
        // read application directory property
        String appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);
        if (appDir == null) {
            throw new I2B2Exception("Could not find " + APPLICATIONDIR_PROPERTIES + "from "
                    + APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
        }
        String appPropertyFile = appDir + "/" + APPLICATION_PROPERTIES_FILENAME;
        try {
            FileSystemResource fileSystemResource = new FileSystemResource(appPropertyFile);
            PropertiesFactoryBean pfb = new PropertiesFactoryBean();
            pfb.setLocation(fileSystemResource);
            pfb.afterPropertiesSet();
            appProperties = (Properties) pfb.getObject();
        } catch (IOException e) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }
        if (appProperties == null) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }
    }

    String propertyValue = appProperties.getProperty(propertyName);

    if ((propertyValue != null) && (propertyValue.trim().length() > 0)) {
        ;
    } else {
        throw new I2B2Exception("Application property file(" + APPLICATION_PROPERTIES_FILENAME + ") missing "
                + propertyName + " entry");
    }

    return propertyValue;
}

From source file:org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.java

/**
 * The {@link MessageSourceAccessor} to provide messages for {@link ResourceDescription}s being rendered.
 * /*from w ww .  j  a va2s.co m*/
 * @return
 */
@Bean
public MessageSourceAccessor resourceDescriptionMessageSourceAccessor() {

    try {

        PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
        propertiesFactoryBean.setLocation(new ClassPathResource("rest-default-messages.properties"));
        propertiesFactoryBean.afterPropertiesSet();

        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasename("classpath:rest-messages");
        messageSource.setCommonMessages(propertiesFactoryBean.getObject());
        messageSource.setDefaultEncoding("UTF-8");

        return new MessageSourceAccessor(messageSource);

    } catch (Exception o_O) {
        throw new BeanCreationException("resourceDescriptionMessageSourceAccessor", "", o_O);
    }
}

From source file:org.jahia.test.framework.JahiaWebInitializer.java

@Override
public void initialize(GenericWebApplicationContext webAppContext) {
    try {/*from w ww . ja va  2 s.  co m*/
        Resource[] resources = webAppContext
                .getResources("classpath*:org/jahia/config/jahiaunittest.properties");
        PropertiesFactoryBean propertiesFactory = new PropertiesFactoryBean();
        propertiesFactory.setLocations(resources);
        propertiesFactory.afterPropertiesSet();
        Properties properties = propertiesFactory.getObject();

        String jackrabbitHome = (String) properties.get("jahia.jackrabbit.home");
        if (jackrabbitHome != null) {
            jackrabbitHome = webAppContext.getResource(jackrabbitHome).getURL().getPath();
            File repoHome = new File(jackrabbitHome);
            if (!repoHome.exists()) {
                repoHome.mkdirs();
            }

            if (resources[0] != null && ResourceUtils.isJarURL(resources[0].getURL())) {
                URL jarUrl = ResourceUtils.extractJarFileURL(resources[0].getURL());
                try {
                    new JahiaArchiveFileHandler(jarUrl.getPath()).unzip("./target/test-repo", new PathFilter() {

                        @Override
                        public boolean accept(String path) {
                            // TODO Auto-generated method stub
                            return path.startsWith("WEB-INF");
                        }
                    });
                } catch (JahiaException e) {
                    logger.error("Unable to extract JAR");
                }
            } else if (resources[0] != null) {
                FileUtils.copyDirectory(
                        new File(StringUtils.substringBefore(resources[0].getURI().getPath(), "org"),
                                "WEB-INF"),
                        new File("./target/test-repo", "WEB-INF"));
            }
        }
    } catch (IOException e) {

    }
}

From source file:org.rifidi.edge.api.service.appmanager.FilePropertyResolver.java

private Properties getProperties(UrlResource resource) throws IOException {
    PropertiesFactoryBean appPropertiesFactoryBean = new PropertiesFactoryBean();
    appPropertiesFactoryBean.setLocation(resource);
    appPropertiesFactoryBean.afterPropertiesSet();
    return (Properties) appPropertiesFactoryBean.getObject();
}