List of usage examples for javax.naming Context URL_PKG_PREFIXES
String URL_PKG_PREFIXES
To view the source code for javax.naming Context URL_PKG_PREFIXES.
Click Source Link
From source file:org.eclipse.ecr.runtime.jtajca.NuxeoContainer.java
/** * set naming context factory to nuxeo implementation, backup original * settings// w w w . ja va 2s . c om * * @since 5.6 */ protected static void setAsInitialContext() { // Preserve current set system props String key = Context.INITIAL_CONTEXT_FACTORY; parentEnvironment.put(key, System.getProperty(key)); key = Context.URL_PKG_PREFIXES; parentEnvironment.put(key, System.getProperty(key)); System.setProperty(Context.INITIAL_CONTEXT_FACTORY, NamingContextFactory.class.getName()); System.setProperty(Context.URL_PKG_PREFIXES, "org.eclipse.ecr.runtime.jtajca"); }
From source file:org.jboss.as.quickstarts.secured.ejb.remote.client.RemoteEJBClient.java
private void initLookupContextProps() { props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); if (this.useSSLOnRemoteEJBProps) { initSSLParams();//from www .j ava2 s . co m CommandLineArgumentsParserUtils.printSysProps(props); } if (!this.setRemoteEJBProps) { return; } props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); String url = "remote://" + this.host + STR_COLON_SEPARATOR + this.port; props.put(Context.PROVIDER_URL, url); props.put("remote.connections", "default"); props.put("remote.connection.default.host", this.host); props.put("remote.connection.default.port", this.port); props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); if (this.useSSLOnRemoteEJBProps) { props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "true"); props.put("remote.connection.default.connect.options.org.xnio.Options.SSL_ENABLED", "true"); props.put("remote.connection.default.connect.options.org.xnio.Options.SSL_STARTTLS", "true"); props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false"); props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER"); } else { props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false"); props.put("remote.connection.default.connect.options.org.xnio.Options.SSL_ENABLED", "false"); props.put("remote.connection.default.connect.options.org.xnio.Options.SSL_STARTTLS", "false"); props.put("remote.connection.default.username", this.username); props.put("remote.connection.default.password", this.password); } EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(props); ContextSelector<EJBClientContext> sel = new ConfigBasedEJBClientContextSelector(cc); EJBClientContext.setSelector(sel); CommandLineArgumentsParserUtils.printSysProps(props); CommandLineArgumentsParserUtils.printProps(props); }
From source file:com.redhat.lightblue.rest.crud.ITCaseCrudResourceRDBMSTest.java
@Before public void setup() throws Exception { File folder = new File("/tmp"); File[] files = folder.listFiles(new FilenameFilter() { @Override/*from w ww. ja v a 2 s . c om*/ public boolean accept(final File dir, final String name) { return name.startsWith("test.db"); } }); for (final File file : files) { if (!file.delete()) { System.out.println("Failed to remove " + file.getAbsolutePath()); } } mongo.dropDatabase(DB_NAME); mongo.dropDatabase("local"); mongo.dropDatabase("admin"); mongo.dropDatabase("mongo"); mongo.getDB(DB_NAME).dropDatabase(); mongo.getDB("local").dropDatabase(); mongo.getDB("admin").dropDatabase(); mongo.getDB("mongo").dropDatabase(); db.getCollection(MongoMetadata.DEFAULT_METADATA_COLLECTION).remove(new BasicDBObject()); mongo.getDB("mongo").getCollection("metadata").remove(new BasicDBObject()); db.createCollection(MongoMetadata.DEFAULT_METADATA_COLLECTION, null); BasicDBObject index = new BasicDBObject("name", 1); index.put("version.value", 1); db.getCollection(MongoMetadata.DEFAULT_METADATA_COLLECTION).ensureIndex(index, "name", true); if (notRegistered) { notRegistered = false; try { // Create initial context System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); // already tried System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory"); InitialContext ic = new InitialContext(); ic.createSubcontext("java:"); ic.createSubcontext("java:/comp"); ic.createSubcontext("java:/comp/env"); ic.createSubcontext("java:/comp/env/jdbc"); JdbcConnectionPool ds = JdbcConnectionPool.create( "jdbc:h2:file:/tmp/test.db;FILE_LOCK=NO;MVCC=TRUE;DB_CLOSE_ON_EXIT=TRUE", "sa", "sasasa"); ic.bind("java:/mydatasource", ds); } catch (NamingException ex) { throw new IllegalStateException(ex); } } else { Context initCtx = new InitialContext(); DataSource ds = (DataSource) initCtx.lookup("java:/mydatasource"); Connection conn = ds.getConnection(); Statement stmt = conn.createStatement(); stmt.execute("DROP ALL OBJECTS "); stmt.close(); } }
From source file:com.redhat.consulting.eapquickstarts.mutualauth.remoting.ejb.client.RemoteEJBClient.java
private void initLookupContextProps() { iniCtxProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); if (this.useSSLOnRemoteEJBProps) { initSSLParams();/* w w w . j a v a 2 s . c o m*/ CommandLineArgumentsParserUtils.printSysProps(props); } if (!this.setRemoteEJBProps) { return; } props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); props.put("remote.connections", "default"); props.put("remote.connection.default.host", this.host); props.put("remote.connection.default.port", this.port); props.put("remote.connection.default.timeout", DEFAULT_TIMEOUT); props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); if (this.useSSLOnRemoteEJBProps) { props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "true"); props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_STARTTLS", "true"); props.put("remote.connection.default.protocol", "https-remoting"); props.put("remote.connection.default.connect.options.org.xnio.Options.SSL_STARTTLS", "true"); props.put("remote.connection.default.connect.options.org.xnio.Options.SSL_ENABLED", "true"); props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false"); props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER"); } else { props.put("remote.connection.default.protocol", "http-remoting"); props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false"); props.put("remote.connection.default.connect.options.org.xnio.Options.SSL_ENABLED", "false"); props.put("remote.connection.default.connect.options.org.xnio.Options.SSL_STARTTLS", "false"); props.put("remote.connection.default.username", this.username); props.put("remote.connection.default.password", this.password); } final EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(props); final ConfigBasedEJBClientContextSelector sel = new ConfigBasedEJBClientContextSelector(cc); EJBClientContext.setSelector(sel); CommandLineArgumentsParserUtils.printSysProps(props); CommandLineArgumentsParserUtils.printProps(props); }
From source file:org.wso2.extension.siddhi.store.rdbms.util.RDBMSTableTestUtils.java
public static void setupJNDIDatasource(String url, String driverClassName) { try {//from ww w. j av a 2s. c o m System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); InitialContext context = new InitialContext(); context.createSubcontext("java:"); context.createSubcontext("java:comp"); context.createSubcontext("java:comp/env"); context.createSubcontext("java:comp/env/jdbc"); Properties connectionProperties = new Properties(); connectionProperties.setProperty("jdbcUrl", url); connectionProperties.setProperty("dataSource.user", user); connectionProperties.setProperty("dataSource.password", password); connectionProperties.setProperty("driverClassName", driverClassName); connectionProperties.setProperty("poolName", "JNDI_Pool"); HikariConfig config = new HikariConfig(connectionProperties); DataSource testDataSourceJNDI = new HikariDataSource(config); context.bind(JNDI_RESOURCE, testDataSourceJNDI); } catch (NamingException e) { log.error("Error while bind the datasource as JNDI resource." + e.getMessage(), e); } }
From source file:org.jboss.ejb3.locator.client.Ejb3ServiceLocatorImpl.java
/** * Return vendor-specific properties for the naming context * //from w w w . j av a 2 s .c o m * @return */ // TODO Externalize to allow for other vendor implementations private Properties getVendorNamingContextProperties() { Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); return props; }
From source file:org.wso2.carbon.apimgt.hybrid.gateway.usage.publisher.dao.UploadedUsageFileInfoDAOTest.java
private static void initializeDatabase(String configFilePath) { InputStream in;/*w w w .j a va 2 s .c o m*/ try { in = FileUtils.openInputStream(new File(configFilePath)); StAXOMBuilder builder = new StAXOMBuilder(in); String dataSource = builder.getDocumentElement().getFirstChildWithName(new QName("DataSourceName")) .getText(); OMElement databaseElement = builder.getDocumentElement().getFirstChildWithName(new QName("Database")); String databaseURL = databaseElement.getFirstChildWithName(new QName("URL")).getText(); String databaseUser = databaseElement.getFirstChildWithName(new QName("Username")).getText(); String databasePass = databaseElement.getFirstChildWithName(new QName("Password")).getText(); String databaseDriver = databaseElement.getFirstChildWithName(new QName("Driver")).getText(); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(databaseDriver); basicDataSource.setUrl(databaseURL); basicDataSource.setUsername(databaseUser); basicDataSource.setPassword(databasePass); // Create initial context System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); try { InitialContext.doLookup("java:/comp/env/jdbc/WSO2AM_DB"); } catch (NamingException e) { InitialContext ic = new InitialContext(); ic.createSubcontext("java:"); ic.createSubcontext("java:/comp"); ic.createSubcontext("java:/comp/env"); ic.createSubcontext("java:/comp/env/jdbc"); ic.bind("java:/comp/env/jdbc/WSO2AM_DB", basicDataSource); } } catch (XMLStreamException | IOException | NamingException e) { log.error(e); } }
From source file:org.betaconceptframework.astroboa.client.service.AbstractClientServiceWrapper.java
<R> Object connectToRemoteService(Class<R> serviceClass, String jndiName) { //Call this method to actually get the referenced object try {/* w w w .j a v a 2s .co m*/ /* * According to the documentation * https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI * * and to this thread https://community.jboss.org/message/647202#647202 * * JBoss AS7 has changed the procedure for a remote client invocation. * We have to use these JBoss Specific API in order to be able to dynamically provide information * about the server host name or ip and the port. * * Bear in mind that in these properties no username and password is provided. * This means that the JBoss AS7 which hosts the Astroboa must have its * security-realm for the subsystem remoting disabled. * * This code must be reviewed as not only it contains JBoss Specific API but also * remoting subsystem must be active without security */ Properties ejbClientConfigurationProperties = new Properties(); ejbClientConfigurationProperties .put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false"); ejbClientConfigurationProperties.put("remote.connections", "default"); ejbClientConfigurationProperties.put("remote.connection.default.host", serverHostNameOrIp); ejbClientConfigurationProperties.put("remote.connection.default.port", port); ejbClientConfigurationProperties.put( "remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false"); final EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration( ejbClientConfigurationProperties); // EJB client context selection is based on selectors. So let's create a ConfigBasedEJBClientContextSelector which uses our EJBClientConfiguration created in previous step final ContextSelector<EJBClientContext> ejbClientContextSelector = new ConfigBasedEJBClientContextSelector( ejbClientConfiguration); // Now let's setup the EJBClientContext to use this selector final ContextSelector<EJBClientContext> previousSelector = EJBClientContext .setSelector(ejbClientContextSelector); //////////////// //Context environmental properties specific to JBoss Naming Context Properties jndiEnvironmentProperties = new Properties(); //jndiEnvironmentProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); jndiEnvironmentProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); //jndiEnvironmentProperties.put(Context.PROVIDER_URL, "jnp://"+serverHostNameOrIpAndPortDelimitedWithSemiColon); InitialContext context = new InitialContext(jndiEnvironmentProperties); if (StringUtils.isBlank(jndiName)) { jndiName = createJNDIBindingNameForService(serviceClass, false); } try { return context.lookup(jndiName); } catch (Exception e) { logger.warn("Could not connect to local service " + serviceClass.getSimpleName(), e); //try with '#' instead of '!' if (jndiName.contains("!")) { return context.lookup(jndiName.replace("!", "#")); } return null; } } catch (Exception e) { logger.error("", e); return null; } }
From source file:org.miloss.fgsms.bueller.Bueller.java
private String doJmsURL(boolean pooled, String endpoint) { try {//from w w w . ja va 2s . c o m boolean ok = false; String server = endpoint.split("#")[0]; server = server.replace("jms:", "jnp://"); String name = endpoint.split("#")[1]; String msg = ""; String[] info = DBSettingsLoader.GetCredentials(pooled, endpoint); String username = null; String password = null; if (info != null) { username = info[0]; password = info[1]; } else { info = DBSettingsLoader.GetDefaultBuellerCredentials(pooled); if (info != null) { username = info[0]; password = info[1]; } } if (name.startsWith("topic")) { try { Properties properties1 = new Properties(); properties1.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties1.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); //properties1.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099"); properties1.put(Context.PROVIDER_URL, server); InitialContext iniCtx = new InitialContext(properties1); TopicConnectionFactory tcf = (TopicConnectionFactory) iniCtx.lookup("TopicConnectionFactory"); TopicConnection createTopicConnection = null; if (info != null) { createTopicConnection = tcf.createTopicConnection(username, Utility.DE(password)); //Topic topic = (Topic) iniCtx.lookup("/topic/quickstart_jmstopic_topic"); } else { createTopicConnection = tcf.createTopicConnection(); //Topic topic = (Topic) iniCtx.lookup("/topic/quickstart_jmstopic_topic"); } createTopicConnection.start(); createTopicConnection.stop(); createTopicConnection.close(); //Topic topic = (Topic) iniCtx.lookup("//" + name); ok = true; //topic = null; iniCtx.close(); } catch (Exception ex) { System.out.println(ex); msg = ex.getLocalizedMessage(); //return ex.getLocalizedMessage(); } } else if (name.startsWith("queue")) { try { Properties properties1 = new Properties(); properties1.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties1.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); properties1.put(Context.PROVIDER_URL, server); InitialContext iniCtx = new InitialContext(properties1); QueueConnection conn; QueueSession session; Queue que; Object tmp = iniCtx.lookup("ConnectionFactory"); QueueConnectionFactory qcf = (QueueConnectionFactory) tmp; if (info != null) { conn = qcf.createQueueConnection(username, Utility.DE(password)); } else { conn = qcf.createQueueConnection(); } que = (Queue) iniCtx.lookup(name); session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); conn.start(); //System.out.println("Connection Started"); ok = true; conn.stop(); session.close(); iniCtx.close(); } catch (Exception ex) { log.log(Level.WARN, "Could not bind to jms queue", ex); msg = ex.getLocalizedMessage(); } if (ok) { return "OK"; } return "Unable to bind to JMS queue: " + msg; } else { return "Unsupported Protocol"; } } catch (Exception ex) { log.log(Level.WARN, "service " + endpoint + " is offline or an error occured", ex); return "Offline " + ex.getLocalizedMessage(); } return "undeterminable"; }
From source file:org.settings4j.connector.JNDIConnectorTest.java
public static void setTomcatJNDIContextProperties() { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.PROVIDER_URL, "localhost:1099"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); }