Java Code Examples for javax.naming.spi.NamingManager#setInitialContextFactoryBuilder()
The following examples show how to use
javax.naming.spi.NamingManager#setInitialContextFactoryBuilder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleNamingContextBuilder.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Register the context builder by registering it with the JNDI NamingManager. * Note that once this has been done, {@code new InitialContext()} will always * return a context from this factory. Use the {@code emptyActivatedContextBuilder()} * static method to get an empty context (for example, in test methods). * @throws IllegalStateException if there's already a naming context builder * registered with the JNDI NamingManager */ public void activate() throws IllegalStateException, NamingException { logger.info("Activating simple JNDI environment"); synchronized (initializationLock) { if (!initialized) { if (NamingManager.hasInitialContextFactoryBuilder()) { throw new IllegalStateException( "Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " + "Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " + "with no reset option. As a consequence, a JNDI provider must only be registered once per JVM."); } NamingManager.setInitialContextFactoryBuilder(this); initialized = true; } } activated = this; }
Example 2
Source File: SimpleNamingContextBuilder.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Register the context builder by registering it with the JNDI NamingManager. * Note that once this has been done, {@code new InitialContext()} will always * return a context from this factory. Use the {@code emptyActivatedContextBuilder()} * static method to get an empty context (for example, in test methods). * @throws IllegalStateException if there's already a naming context builder * registered with the JNDI NamingManager */ public void activate() throws IllegalStateException, NamingException { logger.info("Activating simple JNDI environment"); synchronized (initializationLock) { if (!initialized) { if (NamingManager.hasInitialContextFactoryBuilder()) { throw new IllegalStateException( "Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " + "Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " + "with no reset option. As a consequence, a JNDI provider must only be registered once per JVM."); } NamingManager.setInitialContextFactoryBuilder(this); initialized = true; } } activated = this; }
Example 3
Source File: APPCommunicationServiceBeanTest.java From development with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { // container.enableInterfaceMocking(true); if (!NamingManager.hasInitialContextFactoryBuilder()) { NamingManager .setInitialContextFactoryBuilder(new TestNamingContextFactoryBuilder()); } InitialContext initialContext = new InitialContext(); Properties properties = new Properties(); properties.put("mail.from", "[email protected]"); mailMock = Session.getInstance(properties); initialContext.bind("mail/BSSMail", mailMock); configurationService = mock(APPConfigurationServiceBean.class); commService = spy(new APPCommunicationServiceBean()); commService.configService = configurationService; doNothing().when(commService).transportMail( Matchers.any(MimeMessage.class)); }
Example 4
Source File: TestJNDIInitialization.java From sqlg with MIT License | 6 votes |
@BeforeClass public static void beforeClass() throws Exception { URL sqlProperties = Thread.currentThread().getContextClassLoader().getResource("sqlg.properties"); configuration = new PropertiesConfiguration(sqlProperties); if (!configuration.containsKey("jdbc.url")) { throw new IllegalArgumentException(String.format("SqlGraph configuration requires that the %s be set", "jdbc.url")); } ds = C3P0DataSource.create(configuration).getDatasource(); //change the connection url to be a JNDI one configuration.setProperty("jdbc.url", "jndi:testConnection"); //set up the initial context NamingManager.setInitialContextFactoryBuilder(environment -> { InitialContextFactory mockFactory = mock(InitialContextFactory.class); Context mockContext = mock(Context.class); when(mockFactory.getInitialContext(any())).thenReturn(mockContext); when(mockContext.lookup("testConnection")).thenReturn(ds); return mockFactory; }); }
Example 5
Source File: JndiContext.java From jqm with Apache License 2.0 | 6 votes |
/** * Will create a JNDI Context and register it as the initial context factory builder * * @return the context * @throws NamingException * on any issue during initial context factory builder registration */ static JndiContext createJndiContext() throws NamingException { try { if (!NamingManager.hasInitialContextFactoryBuilder()) { JndiContext ctx = new JndiContext(); NamingManager.setInitialContextFactoryBuilder(ctx); return ctx; } else { return (JndiContext) NamingManager.getInitialContext(null); } } catch (Exception e) { jqmlogger.error("Could not create JNDI context: " + e.getMessage()); NamingException ex = new NamingException("Could not initialize JNDI Context"); ex.setRootCause(e); throw ex; } }
Example 6
Source File: GoldTestBase.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
@Before public void setUp() throws Exception { Locale.setDefault( Locale.US ); TimeZone.setDefault( TimeZone.getTimeZone( "UTC" ) ); // enforce binary compatibility for the xml-files so that comparing them can be faster. ClassicEngineBoot.getInstance().start(); if ( NamingManager.hasInitialContextFactoryBuilder() == false ) { NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() ); } localFontRegistry = new LocalFontRegistry(); localFontRegistry.initialize(); }
Example 7
Source File: SimpleNamingContextBuilder.java From spring-analysis-note with MIT License | 5 votes |
/** * Register the context builder by registering it with the JNDI NamingManager. * Note that once this has been done, {@code new InitialContext()} will always * return a context from this factory. Use the {@code emptyActivatedContextBuilder()} * static method to get an empty context (for example, in test methods). * @throws IllegalStateException if there's already a naming context builder * registered with the JNDI NamingManager */ public void activate() throws IllegalStateException, NamingException { logger.info("Activating simple JNDI environment"); synchronized (initializationLock) { if (!initialized) { Assert.state(!NamingManager.hasInitialContextFactoryBuilder(), "Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " + "Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " + "with no reset option. As a consequence, a JNDI provider must only be registered once per JVM."); NamingManager.setInitialContextFactoryBuilder(this); initialized = true; } } activated = this; }
Example 8
Source File: Prd5276Test.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
@Before public void setUp() throws Exception { ClassicEngineBoot.getInstance().start(); if ( NamingManager.hasInitialContextFactoryBuilder() == false ) { NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() ); } }
Example 9
Source File: DatabaseTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { conn = mockConnection( mock( DatabaseMetaData.class ) ); when( log.getLogLevel() ).thenReturn( LogLevel.NOTHING ); when( dbMetaMock.getDatabaseInterface() ).thenReturn( databaseInterface ); if ( !NamingManager.hasInitialContextFactoryBuilder() ) { // If JNDI is not initialized, use simpleJNDI System.setProperty( Context.INITIAL_CONTEXT_FACTORY, "org.osjava.sj.memory.MemoryContextFactory" ); // pentaho#simple-jndi;1.0.0 System.setProperty( "org.osjava.sj.jndi.shared", "true" ); InitialContextFactoryBuilder simpleBuilder = new SimpleNamingContextBuilder(); NamingManager.setInitialContextFactoryBuilder( simpleBuilder ); } }
Example 10
Source File: Prd4956InlineTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
@Before public void setUp() throws Exception { ClassicEngineBoot.getInstance().start(); if ( NamingManager.hasInitialContextFactoryBuilder() == false ) { NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() ); } }
Example 11
Source File: PooledWithJndiDataSourceServiceIT.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testQueryFallback() throws Exception { PooledWithJndiDataSourceService service = new PooledWithJndiDataSourceService(); NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() ); DataSource ds = service.queryFallback( "SampleData" ); assertThat( ds, is( notNullValue() ) ); assertThat( ds.getConnection(), is( notNullValue() ) ); }
Example 12
Source File: Prd4968Test.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
@Before public void setUp() throws Exception { ClassicEngineBoot.getInstance().start(); if ( NamingManager.hasInitialContextFactoryBuilder() == false ) { NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() ); } }
Example 13
Source File: Pir1421Test.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
@Before public void setUp() throws Exception { ClassicEngineBoot.getInstance().start(); if ( NamingManager.hasInitialContextFactoryBuilder() == false ) { NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() ); } }
Example 14
Source File: SimpleNamingContextBuilder.java From java-technology-stack with MIT License | 5 votes |
/** * Register the context builder by registering it with the JNDI NamingManager. * Note that once this has been done, {@code new InitialContext()} will always * return a context from this factory. Use the {@code emptyActivatedContextBuilder()} * static method to get an empty context (for example, in test methods). * @throws IllegalStateException if there's already a naming context builder * registered with the JNDI NamingManager */ public void activate() throws IllegalStateException, NamingException { logger.info("Activating simple JNDI environment"); synchronized (initializationLock) { if (!initialized) { Assert.state(!NamingManager.hasInitialContextFactoryBuilder(), "Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " + "Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " + "with no reset option. As a consequence, a JNDI provider must only be registered once per JVM."); NamingManager.setInitialContextFactoryBuilder(this); initialized = true; } } activated = this; }
Example 15
Source File: EmptyCellsetTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public void setUp() throws Exception { ClassicEngineBoot.getInstance().start(); if ( NamingManager.hasInitialContextFactoryBuilder() == false ) { NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() ); } }
Example 16
Source File: JndiDataSourceServiceIT.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
protected void setUp() throws Exception { ClassicEngineBoot.getInstance().start(); if ( NamingManager.hasInitialContextFactoryBuilder() == false ) { NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() ); } }
Example 17
Source File: Prd4638Test.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public void setUp() throws Exception { ClassicEngineBoot.getInstance().start(); if ( NamingManager.hasInitialContextFactoryBuilder() == false ) { NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() ); } }
Example 18
Source File: Prd4642Test.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public void setUp() throws Exception { ClassicEngineBoot.getInstance().start(); if ( NamingManager.hasInitialContextFactoryBuilder() == false ) { NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() ); } }
Example 19
Source File: Prd4125Test.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
protected void setUp() throws Exception { ClassicEngineBoot.getInstance().start(); if ( NamingManager.hasInitialContextFactoryBuilder() == false ) { NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() ); } }
Example 20
Source File: BaseAdmUmTest.java From development with Apache License 2.0 | 3 votes |
/** * Tries to register a mocked <code>NamingContextFactoryBuilder</code> to * enable basic JNDI functionality in the test code. * * @throws NamingException * @see {@link TestNamingContext} */ protected static void enableJndiMock() throws NamingException { if (!NamingManager.hasInitialContextFactoryBuilder()) { NamingManager .setInitialContextFactoryBuilder(new TestNamingContextFactoryBuilder(PERSISTENCE)); } }