Search in sources :

Example 6 with FileSystemXmlApplicationContext

use of org.springframework.context.support.FileSystemXmlApplicationContext in project spring-security by spring-projects.

the class ClientApplication method main.

public static void main(String[] args) {
    String username = System.getProperty("username", "");
    String password = System.getProperty("password", "");
    String nrOfCallsString = System.getProperty("nrOfCalls", "");
    if ("".equals(username) || "".equals(password)) {
        System.out.println("You need to specify the user ID to use, the password to use, and optionally a number of calls " + "using the username, password, and nrOfCalls system properties respectively. eg for user rod, " + "use: -Dusername=rod -Dpassword=koala' for a single call per service and " + "use: -Dusername=rod -Dpassword=koala -DnrOfCalls=10 for ten calls per service.");
        System.exit(-1);
    } else {
        int nrOfCalls = 1;
        if (!"".equals(nrOfCallsString)) {
            nrOfCalls = Integer.parseInt(nrOfCallsString);
        }
        ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext("clientContext.xml");
        ClientApplication client = new ClientApplication(beanFactory);
        client.invokeContactManager(new UsernamePasswordAuthenticationToken(username, password), nrOfCalls);
        System.exit(0);
    }
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Example 7 with FileSystemXmlApplicationContext

use of org.springframework.context.support.FileSystemXmlApplicationContext in project Asqatasun by Asqatasun.

the class Asqatasun method initServices.

/**
     *
     * @param asqatasunHome
     */
private void initServices(String asqatasunHome) {
    ApplicationContext springApplicationContext = new FileSystemXmlApplicationContext(asqatasunHome + "/" + APPLICATION_CONTEXT_FILE_PATH);
    BeanFactory springBeanFactory = springApplicationContext;
    auditService = (AuditService) springBeanFactory.getBean("auditService");
    auditDataService = (AuditDataService) springBeanFactory.getBean("auditDataService");
    webResourceDataService = (WebResourceDataService) springBeanFactory.getBean("webResourceDataService");
    webResourceStatisticsDataService = (WebResourceStatisticsDataService) springBeanFactory.getBean("webResourceStatisticsDataService");
    processResultDataService = (ProcessResultDataService) springBeanFactory.getBean("processResultDataService");
    processRemarkDataService = (ProcessRemarkDataService) springBeanFactory.getBean("processRemarkDataService");
    parameterDataService = (ParameterDataService) springBeanFactory.getBean("parameterDataService");
    parameterElementDataService = (ParameterElementDataService) springBeanFactory.getBean("parameterElementDataService");
    auditService.add(this);
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) BeanFactory(org.springframework.beans.factory.BeanFactory)

Example 8 with FileSystemXmlApplicationContext

use of org.springframework.context.support.FileSystemXmlApplicationContext in project ignite by apache.

the class ClientPropertiesConfigurationSelfTest method testSpringConfig.

/**
     * Validate spring client configuration.
     *
     * @throws Exception In case of any exception.
     */
public void testSpringConfig() throws Exception {
    GridClientConfiguration cfg = new FileSystemXmlApplicationContext(GRID_CLIENT_SPRING_CONFIG.toString()).getBean(GridClientConfiguration.class);
    assertEquals(Arrays.asList("127.0.0.1:11211"), new ArrayList<>(cfg.getServers()));
    assertNull(cfg.getSecurityCredentialsProvider());
    Collection<GridClientDataConfiguration> dataCfgs = cfg.getDataConfigurations();
    assertEquals(1, dataCfgs.size());
    GridClientDataConfiguration dataCfg = dataCfgs.iterator().next();
    assertEquals("partitioned", dataCfg.getName());
    assertNotNull(dataCfg.getPinnedBalancer());
    assertEquals(GridClientRandomBalancer.class, dataCfg.getPinnedBalancer().getClass());
    assertNotNull(dataCfg.getAffinity());
    assertEquals(GridClientPartitionAffinity.class, dataCfg.getAffinity().getClass());
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) GridClientDataConfiguration(org.apache.ignite.internal.client.GridClientDataConfiguration)

Example 9 with FileSystemXmlApplicationContext

use of org.springframework.context.support.FileSystemXmlApplicationContext in project ignite by apache.

the class ClientStartNodeTask method getConfig.

/**
     * Load grid configuration for specified node type.
     *
     * @param type Node type to load configuration for.
     * @return Grid configuration for specified node type.
     */
static IgniteConfiguration getConfig(String type) {
    String path = NODE_CFG.get(type);
    if (path == null)
        throw new IllegalArgumentException("Unsupported node type: " + type);
    URL url = U.resolveIgniteUrl(path);
    BeanFactory ctx = new FileSystemXmlApplicationContext(url.toString());
    return (IgniteConfiguration) ctx.getBean("grid.cfg");
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BeanFactory(org.springframework.beans.factory.BeanFactory) URL(java.net.URL)

Example 10 with FileSystemXmlApplicationContext

use of org.springframework.context.support.FileSystemXmlApplicationContext in project ignite by apache.

the class GridAbstractTest method loadConfiguration.

/**
     * Loads configuration from the given Spring XML file.
     *
     * @param springCfgPath Path to file.
     * @return Grid configuration.
     * @throws IgniteCheckedException If load failed.
     */
@SuppressWarnings("deprecation")
protected IgniteConfiguration loadConfiguration(String springCfgPath) throws IgniteCheckedException {
    URL cfgLocation = U.resolveIgniteUrl(springCfgPath);
    if (cfgLocation == null)
        cfgLocation = U.resolveIgniteUrl(springCfgPath, false);
    assert cfgLocation != null;
    ApplicationContext springCtx;
    try {
        springCtx = new FileSystemXmlApplicationContext(cfgLocation.toString());
    } catch (BeansException e) {
        throw new IgniteCheckedException("Failed to instantiate Spring XML application context.", e);
    }
    Map cfgMap;
    try {
        // Note: Spring is not generics-friendly.
        cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
    } catch (BeansException e) {
        throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
    }
    if (cfgMap == null)
        throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + springCfgPath);
    if (cfgMap.isEmpty())
        throw new IgniteCheckedException("Can't find grid factory configuration in: " + springCfgPath);
    else if (cfgMap.size() > 1)
        throw new IgniteCheckedException("More than one configuration provided for cache load test: " + cfgMap.values());
    IgniteConfiguration cfg = (IgniteConfiguration) cfgMap.values().iterator().next();
    cfg.setNodeId(UUID.randomUUID());
    return cfg;
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) URL(java.net.URL) BeansException(org.springframework.beans.BeansException)

Aggregations

FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)16 ApplicationContext (org.springframework.context.ApplicationContext)10 File (java.io.File)8 Map (java.util.Map)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 BeansException (org.springframework.beans.BeansException)5 MalformedURLException (java.net.MalformedURLException)4 ArrayList (java.util.ArrayList)4 Appender (org.apache.log4j.Appender)4 NullAppender (org.apache.log4j.varia.NullAppender)4 CommandLine (org.apache.commons.cli.CommandLine)3 CommandLineParser (org.apache.commons.cli.CommandLineParser)3 GnuParser (org.apache.commons.cli.GnuParser)3 Options (org.apache.commons.cli.Options)3 ParseException (org.apache.commons.cli.ParseException)3 URL (java.net.URL)2 Collection (java.util.Collection)2 ConsoleAppender (org.apache.log4j.ConsoleAppender)2 RollingFileAppender (org.apache.log4j.RollingFileAppender)2