Java Code Examples for javax.naming.spi.NamingManager#hasInitialContextFactoryBuilder()

The following examples show how to use javax.naming.spi.NamingManager#hasInitialContextFactoryBuilder() . 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: APPCommunicationServiceBeanTest.java    From development with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: Prd5295IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  ClassicEngineBoot.getInstance().start();
  if ( NamingManager.hasInitialContextFactoryBuilder() == false ) {
    NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() );
  }
}
 
Example 3
Source File: Prd4313Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setUp() throws Exception {
  final PrintStream out = System.out;
  final PrintStream err = System.err;
  ClassicEngineBoot.getInstance().start();
  if ( NamingManager.hasInitialContextFactoryBuilder() == false ) {
    NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() );
  }
  System.setOut( out );
  System.setErr( err );
}
 
Example 4
Source File: GoldTestBase.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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 5
Source File: DatabaseTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: Prd4968Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  ClassicEngineBoot.getInstance().start();
  if ( NamingManager.hasInitialContextFactoryBuilder() == false ) {
    NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() );
  }
}
 
Example 7
Source File: Prd5276Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  ClassicEngineBoot.getInstance().start();
  if ( NamingManager.hasInitialContextFactoryBuilder() == false ) {
    NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() );
  }
}
 
Example 8
Source File: InitialContext.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Retrieves a context for resolving <code>name</code>.
 * If the first component of <code>name</code> name is a URL string,
 * then attempt to find a URL context for it. If none is found, or if
 * the first component of <code>name</code> is not a URL string,
 * then return <code>getDefaultInitCtx()</code>.
 *<p>
 * When creating a subclass of InitialContext, use this method as
 * follows.
 * Define a new method that uses this method to get an initial
 * context of the desired subclass.
 * <blockquote><pre>
 * protected XXXContext getURLOrDefaultInitXXXCtx(Name name)
 * throws NamingException {
 *  Context answer = getURLOrDefaultInitCtx(name);
 *  if (!(answer instanceof XXXContext)) {
 *    if (answer == null) {
 *      throw new NoInitialContextException();
 *    } else {
 *      throw new NotContextException("Not an XXXContext");
 *    }
 *  }
 *  return (XXXContext)answer;
 * }
 * </pre></blockquote>
 * When providing implementations for the new methods in the subclass,
 * use this newly defined method to get the initial context.
 * <blockquote><pre>
 * public Object XXXMethod1(Name name, ...) {
 *  throws NamingException {
 *    return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...);
 * }
 * </pre></blockquote>
 *
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 *
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(Name name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    if (name.size() > 0) {
        String first = name.get(0);
        String scheme = getURLScheme(first);
        if (scheme != null) {
            Context ctx = NamingManager.getURLContext(scheme, myProps);
            if (ctx != null) {
                return ctx;
            }
        }
    }
    return getDefaultInitCtx();
}
 
Example 9
Source File: Prd4637Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void setUp() throws Exception {
  ClassicEngineBoot.getInstance().start();
  if ( NamingManager.hasInitialContextFactoryBuilder() == false ) {
    NamingManager.setInitialContextFactoryBuilder( new DebugJndiContextFactoryBuilder() );
  }
}
 
Example 10
Source File: InitialContext.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Retrieves a context for resolving <code>name</code>.
 * If the first component of <code>name</code> name is a URL string,
 * then attempt to find a URL context for it. If none is found, or if
 * the first component of <code>name</code> is not a URL string,
 * then return <code>getDefaultInitCtx()</code>.
 *<p>
 * When creating a subclass of InitialContext, use this method as
 * follows.
 * Define a new method that uses this method to get an initial
 * context of the desired subclass.
 * <blockquote><pre>
 * protected XXXContext getURLOrDefaultInitXXXCtx(Name name)
 * throws NamingException {
 *  Context answer = getURLOrDefaultInitCtx(name);
 *  if (!(answer instanceof XXXContext)) {
 *    if (answer == null) {
 *      throw new NoInitialContextException();
 *    } else {
 *      throw new NotContextException("Not an XXXContext");
 *    }
 *  }
 *  return (XXXContext)answer;
 * }
 * </pre></blockquote>
 * When providing implementations for the new methods in the subclass,
 * use this newly defined method to get the initial context.
 * <blockquote><pre>
 * public Object XXXMethod1(Name name, ...) {
 *  throws NamingException {
 *    return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...);
 * }
 * </pre></blockquote>
 *
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 *
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(Name name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    if (name.size() > 0) {
        String first = name.get(0);
        String scheme = getURLScheme(first);
        if (scheme != null) {
            Context ctx = NamingManager.getURLContext(scheme, myProps);
            if (ctx != null) {
                return ctx;
            }
        }
    }
    return getDefaultInitCtx();
}
 
Example 11
Source File: InitialContext.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Retrieves a context for resolving <code>name</code>.
 * If the first component of <code>name</code> name is a URL string,
 * then attempt to find a URL context for it. If none is found, or if
 * the first component of <code>name</code> is not a URL string,
 * then return <code>getDefaultInitCtx()</code>.
 *<p>
 * When creating a subclass of InitialContext, use this method as
 * follows.
 * Define a new method that uses this method to get an initial
 * context of the desired subclass.
 * <blockquote><pre>
 * protected XXXContext getURLOrDefaultInitXXXCtx(Name name)
 * throws NamingException {
 *  Context answer = getURLOrDefaultInitCtx(name);
 *  if (!(answer instanceof XXXContext)) {
 *    if (answer == null) {
 *      throw new NoInitialContextException();
 *    } else {
 *      throw new NotContextException("Not an XXXContext");
 *    }
 *  }
 *  return (XXXContext)answer;
 * }
 * </pre></blockquote>
 * When providing implementations for the new methods in the subclass,
 * use this newly defined method to get the initial context.
 * <blockquote><pre>
 * public Object XXXMethod1(Name name, ...) {
 *  throws NamingException {
 *    return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...);
 * }
 * </pre></blockquote>
 *
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 *
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(Name name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    if (name.size() > 0) {
        String first = name.get(0);
        String scheme = getURLScheme(first);
        if (scheme != null) {
            Context ctx = NamingManager.getURLContext(scheme, myProps);
            if (ctx != null) {
                return ctx;
            }
        }
    }
    return getDefaultInitCtx();
}
 
Example 12
Source File: InitialContext.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Retrieves a context for resolving <code>name</code>.
 * If the first component of <code>name</code> name is a URL string,
 * then attempt to find a URL context for it. If none is found, or if
 * the first component of <code>name</code> is not a URL string,
 * then return <code>getDefaultInitCtx()</code>.
 *<p>
 * When creating a subclass of InitialContext, use this method as
 * follows.
 * Define a new method that uses this method to get an initial
 * context of the desired subclass.
 * <blockquote><pre>
 * protected XXXContext getURLOrDefaultInitXXXCtx(Name name)
 * throws NamingException {
 *  Context answer = getURLOrDefaultInitCtx(name);
 *  if (!(answer instanceof XXXContext)) {
 *    if (answer == null) {
 *      throw new NoInitialContextException();
 *    } else {
 *      throw new NotContextException("Not an XXXContext");
 *    }
 *  }
 *  return (XXXContext)answer;
 * }
 * </pre></blockquote>
 * When providing implementations for the new methods in the subclass,
 * use this newly defined method to get the initial context.
 * <blockquote><pre>
 * public Object XXXMethod1(Name name, ...) {
 *  throws NamingException {
 *    return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...);
 * }
 * </pre></blockquote>
 *
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 *
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(Name name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    if (name.size() > 0) {
        String first = name.get(0);
        String scheme = getURLScheme(first);
        if (scheme != null) {
            Context ctx = NamingManager.getURLContext(scheme, myProps);
            if (ctx != null) {
                return ctx;
            }
        }
    }
    return getDefaultInitCtx();
}
 
Example 13
Source File: InitialContext.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Retrieves a context for resolving <code>name</code>.
 * If the first component of <code>name</code> name is a URL string,
 * then attempt to find a URL context for it. If none is found, or if
 * the first component of <code>name</code> is not a URL string,
 * then return <code>getDefaultInitCtx()</code>.
 *<p>
 * When creating a subclass of InitialContext, use this method as
 * follows.
 * Define a new method that uses this method to get an initial
 * context of the desired subclass.
 * <blockquote><pre>
 * protected XXXContext getURLOrDefaultInitXXXCtx(Name name)
 * throws NamingException {
 *  Context answer = getURLOrDefaultInitCtx(name);
 *  if (!(answer instanceof XXXContext)) {
 *    if (answer == null) {
 *      throw new NoInitialContextException();
 *    } else {
 *      throw new NotContextException("Not an XXXContext");
 *    }
 *  }
 *  return (XXXContext)answer;
 * }
 * </pre></blockquote>
 * When providing implementations for the new methods in the subclass,
 * use this newly defined method to get the initial context.
 * <blockquote><pre>
 * public Object XXXMethod1(Name name, ...) {
 *  throws NamingException {
 *    return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...);
 * }
 * </pre></blockquote>
 *
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 *
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(Name name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    if (name.size() > 0) {
        String first = name.get(0);
        String scheme = getURLScheme(first);
        if (scheme != null) {
            Context ctx = NamingManager.getURLContext(scheme, myProps);
            if (ctx != null) {
                return ctx;
            }
        }
    }
    return getDefaultInitCtx();
}
 
Example 14
Source File: InitialContext.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Retrieves a context for resolving <code>name</code>.
 * If the first component of <code>name</code> name is a URL string,
 * then attempt to find a URL context for it. If none is found, or if
 * the first component of <code>name</code> is not a URL string,
 * then return <code>getDefaultInitCtx()</code>.
 *<p>
 * When creating a subclass of InitialContext, use this method as
 * follows.
 * Define a new method that uses this method to get an initial
 * context of the desired subclass.
 * <blockquote><pre>
 * protected XXXContext getURLOrDefaultInitXXXCtx(Name name)
 * throws NamingException {
 *  Context answer = getURLOrDefaultInitCtx(name);
 *  if (!(answer instanceof XXXContext)) {
 *    if (answer == null) {
 *      throw new NoInitialContextException();
 *    } else {
 *      throw new NotContextException("Not an XXXContext");
 *    }
 *  }
 *  return (XXXContext)answer;
 * }
 * </pre></blockquote>
 * When providing implementations for the new methods in the subclass,
 * use this newly defined method to get the initial context.
 * <blockquote><pre>
 * public Object XXXMethod1(Name name, ...) {
 *  throws NamingException {
 *    return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...);
 * }
 * </pre></blockquote>
 *
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 *
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(Name name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    if (name.size() > 0) {
        String first = name.get(0);
        String scheme = getURLScheme(first);
        if (scheme != null) {
            Context ctx = NamingManager.getURLContext(scheme, myProps);
            if (ctx != null) {
                return ctx;
            }
        }
    }
    return getDefaultInitCtx();
}
 
Example 15
Source File: InitialContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Retrieves a context for resolving the string name <code>name</code>.
 * If <code>name</code> name is a URL string, then attempt
 * to find a URL context for it. If none is found, or if
 * <code>name</code> is not a URL string, then return
 * <code>getDefaultInitCtx()</code>.
 *<p>
 * See getURLOrDefaultInitCtx(Name) for description
 * of how a subclass should use this method.
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(String name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    String scheme = getURLScheme(name);
    if (scheme != null) {
        Context ctx = NamingManager.getURLContext(scheme, myProps);
        if (ctx != null) {
            return ctx;
        }
    }
    return getDefaultInitCtx();
}
 
Example 16
Source File: InitialContext.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Retrieves a context for resolving the string name <code>name</code>.
 * If <code>name</code> name is a URL string, then attempt
 * to find a URL context for it. If none is found, or if
 * <code>name</code> is not a URL string, then return
 * <code>getDefaultInitCtx()</code>.
 *<p>
 * See getURLOrDefaultInitCtx(Name) for description
 * of how a subclass should use this method.
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(String name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    String scheme = getURLScheme(name);
    if (scheme != null) {
        Context ctx = NamingManager.getURLContext(scheme, myProps);
        if (ctx != null) {
            return ctx;
        }
    }
    return getDefaultInitCtx();
}
 
Example 17
Source File: InitialContext.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Retrieves a context for resolving the string name <code>name</code>.
 * If <code>name</code> name is a URL string, then attempt
 * to find a URL context for it. If none is found, or if
 * <code>name</code> is not a URL string, then return
 * <code>getDefaultInitCtx()</code>.
 *<p>
 * See getURLOrDefaultInitCtx(Name) for description
 * of how a subclass should use this method.
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(String name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    String scheme = getURLScheme(name);
    if (scheme != null) {
        Context ctx = NamingManager.getURLContext(scheme, myProps);
        if (ctx != null) {
            return ctx;
        }
    }
    return getDefaultInitCtx();
}
 
Example 18
Source File: InitialContext.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Retrieves a context for resolving the string name <code>name</code>.
 * If <code>name</code> name is a URL string, then attempt
 * to find a URL context for it. If none is found, or if
 * <code>name</code> is not a URL string, then return
 * <code>getDefaultInitCtx()</code>.
 *<p>
 * See getURLOrDefaultInitCtx(Name) for description
 * of how a subclass should use this method.
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(String name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    String scheme = getURLScheme(name);
    if (scheme != null) {
        Context ctx = NamingManager.getURLContext(scheme, myProps);
        if (ctx != null) {
            return ctx;
        }
    }
    return getDefaultInitCtx();
}
 
Example 19
Source File: InitialContext.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieves a context for resolving the string name <code>name</code>.
 * If <code>name</code> name is a URL string, then attempt
 * to find a URL context for it. If none is found, or if
 * <code>name</code> is not a URL string, then return
 * <code>getDefaultInitCtx()</code>.
 *<p>
 * See getURLOrDefaultInitCtx(Name) for description
 * of how a subclass should use this method.
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(String name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    String scheme = getURLScheme(name);
    if (scheme != null) {
        Context ctx = NamingManager.getURLContext(scheme, myProps);
        if (ctx != null) {
            return ctx;
        }
    }
    return getDefaultInitCtx();
}
 
Example 20
Source File: BaseAdmUmTest.java    From development with Apache License 2.0 3 votes vote down vote up
/**
 * 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));
    }
}