Example usage for org.springframework.mock.jndi SimpleNamingContextBuilder emptyActivatedContextBuilder

List of usage examples for org.springframework.mock.jndi SimpleNamingContextBuilder emptyActivatedContextBuilder

Introduction

In this page you can find the example usage for org.springframework.mock.jndi SimpleNamingContextBuilder emptyActivatedContextBuilder.

Prototype

public static SimpleNamingContextBuilder emptyActivatedContextBuilder() throws NamingException 

Source Link

Document

If no SimpleNamingContextBuilder is already configuring JNDI, create and activate one.

Usage

From source file:gov.nih.nci.cabig.caaers.CaaersContextLoader.java

public synchronized static ApplicationContext getApplicationContext() {
    if (acLoadFailure == null && applicationContext == null) {
        try {// w ww  . j  av  a2s  . c o  m
            SimpleNamingContextBuilder.emptyActivatedContextBuilder();
        } catch (NamingException e) {
            throw new RuntimeException("", e);
        }

        try {
            log.debug("Initializing test version of deployed application context");
            applicationContext = new ClassPathXmlApplicationContext(getConfigLocations());
        } catch (RuntimeException e) {
            acLoadFailure = e;
            throw e;
        }
    } else if (acLoadFailure != null) {
        throw new CaaersSystemException(
                "Application context loading already failed.  Will not retry.  " + "Original cause attached.",
                acLoadFailure);
    }
    return applicationContext;
}

From source file:com.joel1di1.spring.jndi.initializer.JndiInitializer.java

/**
 * Bind target into the JNDI (via spring naming context) tree
 * /*from   ww w. j a  v a  2  s  .com*/
 * @throws NamingException
 */
public void init() throws NamingException {
    if (builder == null) {
        builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
    }
    builder.bind(jndiName, target);
}

From source file:almira.weblogic.JndiInjectorTest.java

@Before
public void setUp() throws NamingException, IOException {
    SimpleNamingContextBuilder.emptyActivatedContextBuilder();
    ic = new InitialContext();
    injector = new JndiInjector(ic);
}

From source file:com.iterranux.droolsjbpmAtomikosIntegration.TransactionManagerJNDIRegistrator.java

@PostConstruct
public void init() {
    log.debug("Registering TX to JNDI.");
    try {// w  w w  . j  a  v  a2  s .c  o  m
        SimpleNamingContextBuilder.emptyActivatedContextBuilder();
        Context context = new InitialContext();

        context.bind(userTransactionLookup, userTransaction);
        context.bind(transactionManagerLookup, transactionManager);

    } catch (NamingException e) {
        log.error("JNDI Registration of the Transasction Manager failed.", e);
    }

}

From source file:example.app.config.support.NamingContextBuilderFactoryBean.java

@Override
public void afterPropertiesSet() throws Exception {
    SimpleNamingContextBuilder namingContextBuilder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();

    for (Map.Entry<String, Object> boundObject : boundObjects.entrySet()) {
        namingContextBuilder.bind(boundObject.getKey(), boundObject.getValue());
    }//from  w  ww. j av  a2 s .c o  m
}

From source file:com.spring.jca.tuxedo.ApplicationConfig.java

ResourceAdapterFactoryBean tuxedoCSResourceAdapter() {
    // http://stackoverflow.com/questions/5682732/how-does-an-application-that-uses-springs-simplenamingcontextbuilder-know-to-se
    try {//from   www . jav  a2 s .c  om
        SimpleNamingContextBuilder.emptyActivatedContextBuilder();
    } catch (NamingException e) {
        System.out.println("Simple Naming context builder error: " + e.getMessage());
    }

    TuxedoClientSideResourceAdapter ra = new TuxedoClientSideResourceAdapter();
    ra.setTraceLevel("100000");

    ra.setDebugAdapter(true);
    ra.setDebugBuffer(true);
    ra.setDebugJatmi(true);
    ra.setDebugRouting(true);
    ra.setDebugSession(true);
    ra.setDebugXa(true);
    ra.setDebugConfig(true);
    ra.setDebugPdu(true);
    ra.setDebugPerf(true);
    ra.setDebugSec(true);
    ra.setDebugNet(true);

    ra.setXaAffinity("true");
    ra.setAutoTran(true);

    ra.setSpCredentialPolicy("LOCAL");
    ra.setRapAllowAnonymous(false);

    ra.setLocalAccessPointSpec("//INV000000121176.ads.sfa.se:7001/domainId=INV000000121176");
    ra.setRemoteAccessPointSpec("//vsgtu702.sfa.se:47022/domainId=tr703tu");

    ra.setImpResourceName("levereraPerson");

    ra.setFieldTable32Classes("se.fk.silk.tuxedo.SampleFldTbl");

    ResourceAdapterFactoryBean fc = new ResourceAdapterFactoryBean();
    fc.setResourceAdapter(ra);

    SimpleTaskWorkManager stwm = new SimpleTaskWorkManager();
    fc.setWorkManager(stwm);
    fc.setBootstrapContext(new SimpleBootstrapContext(stwm));

    return fc;
}

From source file:com.agiletec.ConfigTestUtils.java

protected SimpleNamingContextBuilder createNamingContext() {
    SimpleNamingContextBuilder builder = null;
    try {/*  www. jav  a 2s .c  o  m*/
        builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
        InputStream in = new FileInputStream("target/test/conf/contextTestParams.properties");
        Properties testConfig = new Properties();
        testConfig.load(in);
        in.close();

        builder.bind("java:comp/env/logName", testConfig.getProperty("logName"));
        builder.bind("java:comp/env/logFilePrefix", testConfig.getProperty("logFilePrefix"));
        builder.bind("java:comp/env/logLevel", testConfig.getProperty("logLevel"));
        builder.bind("java:comp/env/logFileSize", testConfig.getProperty("logFileSize"));
        builder.bind("java:comp/env/logFilesCount", testConfig.getProperty("logFilesCount"));

        builder.bind("java:comp/env/configVersion", testConfig.getProperty("configVersion"));

        builder.bind("java:comp/env/applicationBaseURL", testConfig.getProperty("applicationBaseURL"));
        builder.bind("java:comp/env/resourceRootURL", testConfig.getProperty("resourceRootURL"));
        builder.bind("java:comp/env/protectedResourceRootURL",
                testConfig.getProperty("protectedResourceRootURL"));
        builder.bind("java:comp/env/resourceDiskRootFolder", testConfig.getProperty("resourceDiskRootFolder"));
        builder.bind("java:comp/env/protectedResourceDiskRootFolder",
                testConfig.getProperty("protectedResourceDiskRootFolder"));

        builder.bind("java:comp/env/indexDiskRootFolder", testConfig.getProperty("indexDiskRootFolder"));

        Iterator<Entry<Object, Object>> configIter = testConfig.entrySet().iterator();
        while (configIter.hasNext()) {
            Entry<Object, Object> entry = configIter.next();
            builder.bind("java:comp/env/" + (String) entry.getKey(), (String) entry.getValue());
        }

        this.createDatasources(builder, testConfig);
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException("Error on creation naming context", t);
    }
    return builder;
}

From source file:edu.cmu.hcii.stepgreen.data.SpringWiringTest.java

@BeforeClass
public static void setUp() throws NamingException {
    DataSource dataSource = mock(DataSource.class);

    SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
    builder.bind("java:comp/env/jdbc/app-energy-labeler", dataSource);
}

From source file:com.spring.jca.tuxedo.ApplicationConfig.java

@Bean
public ResourceAdapterFactoryBean tuxedoResourceAdapter() {
    try {/*w  ww. j  a  va2s  . c o  m*/
        SimpleNamingContextBuilder.emptyActivatedContextBuilder();
    } catch (NamingException e) {
        System.out.println("Simple Naming context builder error: " + e.getMessage());
    }

    TuxedoResourceAdapter ra = new TuxedoResourceAdapter();
    ra.setTraceLevel("100000");

    ra.setDebugAdapter(true);
    ra.setDebugBuffer(true);
    ra.setDebugJatmi(true);
    ra.setDebugRouting(true);
    ra.setDebugSession(true);
    ra.setDebugXa(true);
    ra.setDebugConfig(true);
    ra.setDebugPdu(true);
    ra.setDebugPerf(true);
    ra.setDebugSec(true);
    ra.setDebugNet(true);

    ra.setXaAffinity("true");

    ra.setDmconfig("C:\\Users\\40042466\\workspace\\Silk Tuxedo\\configuration\\runtime\\dmconfig.xml");

    ResourceAdapterFactoryBean fc = new ResourceAdapterFactoryBean();
    fc.setResourceAdapter(ra);

    SimpleTaskWorkManager stwm = new SimpleTaskWorkManager();
    fc.setWorkManager(stwm);
    fc.setBootstrapContext(new SimpleBootstrapContext(stwm));

    return fc;
}

From source file:org.ow2.authzforce.upgrader.test.UpgradedDataLoadTest.java

/**
 * Test parameters from testng.xml are ignored when executing with maven surefire plugin, so we use default values for all.
 * /*from  ww  w.  ja v a2 s.co m*/
 * WARNING: the BeforeTest-annotated method must be in the test class, not in a super class although the same method logic is used in other test class
 * 
 * @param serverRootDir
 * 
 * @param domainSyncIntervalSec
 * @throws Exception
 */
@Parameters({ "server.root.dir", "org.ow2.authzforce.domains.sync.interval" })
@BeforeTest
public void beforeTest(String serverRootDir, @Optional("-1") int domainSyncIntervalSec) throws Exception {
    System.out.println("Testing data in directory: " + serverRootDir);
    final File targetDir = new File("target");
    // set catalina.base property in server's logback.xml
    System.setProperty("catalina.base", targetDir.toURI().toString());

    final File confDir = new File(serverRootDir + "/conf");
    final String confURI = confDir.toURI().toString();
    final File dataDir = new File(serverRootDir + "/data");
    final String dataURI = dataDir.toURI().toString();

    // Set some server properties via JNDI
    try {
        final SimpleNamingContextBuilder jndiCtxFactoryBuilder = SimpleNamingContextBuilder
                .emptyActivatedContextBuilder();
        jndiCtxFactoryBuilder.bind("java:comp/env/org.ow2.authzforce.config.dir", confURI);
        jndiCtxFactoryBuilder.bind("java:comp/env/org.ow2.authzforce.data.dir", dataURI);
        jndiCtxFactoryBuilder.bind("java:comp/env/org.ow2.authzforce.uuid.gen.randomMulticastAddressBased",
                Boolean.TRUE);
        jndiCtxFactoryBuilder.bind("java:comp/env/org.ow2.authzforce.domains.sync.interval", new Integer(-1));
    } catch (NamingException ex) {
        throw new RuntimeException("Error setting property via JNDI", ex);
    }

    /*
     * Workaround for: http://stackoverflow.com/questions/10184602/accessing -spring-context-in-testngs -beforetest https://jira.spring.io/browse/SPR-4072
     * https://jira.spring.io/browse/SPR-5404 (duplicate of previous issue) springTestContextPrepareTestInstance() happens in
     * 
     * @BeforeClass before no access to Autowired beans by default in
     * 
     * @BeforeTest
     */
    super.springTestContextPrepareTestInstance();
    testDomainId = domainsResourceBean.getDomains(null).getLinks().get(0).getHref();
    testDomain = domainsResourceBean.getDomainResource(testDomainId);
}