Example usage for javax.naming Context PROVIDER_URL

List of usage examples for javax.naming Context PROVIDER_URL

Introduction

In this page you can find the example usage for javax.naming Context PROVIDER_URL.

Prototype

String PROVIDER_URL

To view the source code for javax.naming Context PROVIDER_URL.

Click Source Link

Document

Constant that holds the name of the environment property for specifying configuration information for the service provider to use.

Usage

From source file:org.mule.object.JndiObjectFactory.java

public void initialise() throws InitialisationException {
    if (_context == null) {
        Hashtable props = new Hashtable();

        if (initialFactory != null) {
            props.put(Context.INITIAL_CONTEXT_FACTORY, initialFactory);
        } else if (properties == null || !properties.containsKey(Context.INITIAL_CONTEXT_FACTORY)) {
            throw new InitialisationException(CoreMessages.objectIsNull("jndiInitialFactory"), this);
        }/*from   w  w  w .  j ava2  s . c  om*/

        if (url != null) {
            props.put(Context.PROVIDER_URL, url);
        }

        if (properties != null) {
            props.putAll(properties);
        }

        try {
            _context = new InitialContext(props);
        } catch (NamingException e) {
            throw new InitialisationException(e, this);
        }
    }
}

From source file:org.aludratest.service.jms.impl.JmsServiceImpl.java

@Override
public void configure(Preferences preferences) {
    ValidatingPreferencesWrapper prefs = new ValidatingPreferencesWrapper(preferences);
    providerUrl = prefs.getRequiredStringValue("providerUrl");

    String initialContextFactory = prefs.getRequiredStringValue("initialContextFactory");
    String connectionFactoryName = prefs.getRequiredStringValue("connectionFactoryJndiName");

    String userName = prefs.getStringValue("jmsUser");
    String password = prefs.getStringValue("jmsPassword");

    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
    env.put(Context.PROVIDER_URL, providerUrl);
    if (!StringUtils.isEmpty(userName)) {
        env.put(Context.SECURITY_PRINCIPAL, userName);
    }//from  w  w  w .ja v  a2  s .  c  o  m
    if (!StringUtils.isEmpty(password)) {
        env.put(Context.SECURITY_CREDENTIALS, password);
    }

    try {
        initialContext = new InitialContext(env);
        connectionFactory = (ConnectionFactory) initialContext.lookup(connectionFactoryName);
        if (connectionFactory == null) {
            throw new ConfigurationException("The connection factory could not be found.");
        }

    } catch (NamingException e) {
        throw new TechnicalException("Could not retrieve objects from JNDI context", e);
    }

    action = new JmsActionImpl(connectionFactory, initialContext, userName, password);
}

From source file:org.betaconceptframework.astroboa.test.AstroboaTestContext.java

private AstroboaTestContext() {

    try {//from ww  w.jav  a  2s .co m

        System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");

        System.setProperty(Context.PROVIDER_URL, "localhost");

        System.setProperty("org.betaconceptframework.astroboa.configuration.dir",
                new ClassPathResource("/").getFile().getAbsolutePath());

        removeRepositoryResources(TestConstants.TEST_REPOSITORY_ID);
        removeRepositoryResources(TestConstants.TEST_IDENTITY_STORE_REPOSITORY_ID);
        removeRepositoryResources(TestConstants.TEST_CLONE_REPOSITORY_ID);

        //Initialize Spring - Order is SIGNIFICANT. Spring context must be initialized at the end
        applicationContext = new ClassPathXmlApplicationContext(getConfigLocations());

    } catch (Exception e) {
        throw new CmsException(e);
    }
}

From source file:org.exist.messaging.JmsMessageSender.java

@Override
public NodeImpl send(JmsMessagingConfiguration config, MessagingMetadata metadata, Item content)
        throws XPathException {

    // JMS specific checks
    config.validateContent();/* w  ww  . j ava  2s .  c  om*/

    // Retrieve relevant values
    String initialContextFactory = config.getInitalContextProperty(Context.INITIAL_CONTEXT_FACTORY);
    String providerURL = config.getInitalContextProperty(Context.PROVIDER_URL);
    String connectionFactory = config.getConnectionFactory();
    String destination = config.getDestination();

    // TODO split up, use more exceptions, add better reporting
    try {
        Properties props = new Properties();
        props.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
        props.setProperty(Context.PROVIDER_URL, providerURL);
        javax.naming.Context context = new InitialContext(props);

        // Setup connection
        ConnectionFactory cf = (ConnectionFactory) context.lookup(connectionFactory);
        Connection connection = cf.createConnection();

        // Lookup queue
        Destination dest = (Destination) context.lookup(destination);

        // Create session
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        // Create message producer
        MessageProducer producer = session.createProducer(dest);

        // Create message
        Message message = createMessage(session, content, metadata, xqcontext);

        // Write properties
        Map<String, String> kvs = metadata.getValueMap();
        for (String key : kvs.keySet()) {
            message.setStringProperty(key, kvs.get(key));
        }

        // Send message
        producer.send(message);

        // Close connection
        // TODO keep connection open for re-use, efficiency
        connection.close();

        return createReport(message, xqcontext);

    } catch (Throwable ex) {
        LOG.error(ex);
        throw new XPathException(ex);
    }
}

From source file:es.udl.asic.user.OpenLdapDirectoryProvider.java

public void init() {
    try {//from   ww  w. j  a  va 2 s  .c om
        M_log.info("init()");
    } catch (Throwable t) {
        M_log.warn("init(): ", t);
    }

    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, getLdapHost() + ":" + getLdapPort());
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_CREDENTIALS, "secret");
}

From source file:org.apache.servicemix.jms.JmsSpringTest.java

protected AbstractXmlApplicationContext createBeanFactory() {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, SpringInitialContextFactory.class.getName());
    System.setProperty(Context.PROVIDER_URL, "org/apache/servicemix/jms/jndi.xml");
    return new ClassPathXmlApplicationContext("org/apache/servicemix/jms/spring.xml");
}

From source file:org.projectforge.ldap.LdapConnector.java

private Hashtable<String, String> createEnv(final String user, final String password) {
    // Set up the environment for creating the initial context
    final Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, ldapConfig.getCompleteServerUrl());
    final String authentication = ldapConfig.getAuthentication();
    if (StringUtils.isNotBlank(authentication) == true) {
        env.put(Context.SECURITY_AUTHENTICATION, ldapConfig.getAuthentication());
        if ("none".equals(authentication) == false || user != null || password != null) {
            env.put(Context.SECURITY_PRINCIPAL, user);
            env.put(Context.SECURITY_CREDENTIALS, password);
        }//from  w  w w  . ja v a2s  . c om
    }
    if (ldapConfig != null && StringUtils.isNotBlank(ldapConfig.getSslCertificateFile()) == true) {
        env.put("java.naming.ldap.factory.socket", "org.projectforge.ldap.MySSLSocketFactory");
    }
    log.info("Trying to connect the LDAP server: url=[" + ldapConfig.getCompleteServerUrl()
            + "], authentication=[" + ldapConfig.getAuthentication() + "], principal=[" + user + "]");
    return env;
}

From source file:org.apache.jackrabbit.ocm.spring.RepositoryUtil.java

/**
 * Unregister a repository// www  . j  a  va 2s .  c  o m
 *
 * @param repositoryName The repository unique name
 *
 * @throws RepositoryException when it is not possible to unregister the repository
 */
public static void unRegisterRepository(String repositoryName) throws RepositoryException {
    try {
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
        env.put(Context.PROVIDER_URL, "localhost");
        InitialContext ctx = new InitialContext(env);

        RegistryHelper.unregisterRepository(ctx, repositoryName);
    } catch (Exception e) {
        throw new RepositoryException("Impossible to unregister the respository : " + repositoryName, e);
    }

}

From source file:org.jkcsoft.java.util.JndiHelper.java

public static Context getContext(String url, String contextFactoryName) throws NamingException {
    log.debug("Getting initial context from jndi url [" + url + "]");
    Context ctx = null;/*from   w  ww  .jav a 2s . c o  m*/
    Hashtable properties = new Hashtable();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, contextFactoryName);

    properties.put(Context.PROVIDER_URL, url);

    try {
        // Creating the JNDI directory context (with LDAP context
        // factory), performs an LDAP bind to the LDAP provider thereby
        // authenticating the username/pw.
        ctx = new InitialContext(properties);
    } catch (NamingException ex) {
        throw ex;
    }

    return ctx;
}

From source file:de.escidoc.core.admin.common.util.spring.RemoteJndiLocator.java

/**
 * Set the JNDI properties.//from   w  w  w  .j a va  2 s  . c  om
 * 
 * @throws WebserverSystemException
 *             Thrown in case of an internal error.
 */
private void setInitialContextJndiProperties() throws WebserverSystemException {
    Properties properties = new Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    properties.setProperty(Context.URL_PKG_PREFIXES, "org.jnp.interfaces:org.jboss.naming");
    properties.setProperty(Context.PROVIDER_URL, jndiUrl);
    this.setJndiEnvironment(properties);
}