private static Map<String, DataSource> getJndiDataSourcesAt(String jndiPrefix) throws NamingException { final InitialContext initialContext = new InitialContext(); final Map<String, DataSource> dataSources = new LinkedHashMap<String, DataSource>(2); try { for (final NameClassPair nameClassPair : Collections.list(initialContext.list(jndiPrefix))) { // note: il ne suffit pas de tester // (DataSource.class.isAssignableFrom(Class.forName(nameClassPair.getClassName()))) // car nameClassPair.getClassName() vaut "javax.naming.LinkRef" sous jboss 5.1.0.GA // par exemple, donc on fait le lookup pour voir final String jndiName; if (nameClassPair.getName().startsWith("java:")) { // pour glassfish v3 jndiName = nameClassPair.getName(); } else { jndiName = jndiPrefix + '/' + nameClassPair.getName(); } final Object value = initialContext.lookup(jndiName); if (value instanceof DataSource) { dataSources.put(jndiName, (DataSource) value); } } } catch (final NamingException e) { // le préfixe ("comp/env/jdbc", "/jdbc" ou "java:global/jdbc", etc) n'existe pas dans jndi, // (dans glassfish 3.0.1, c'est une NamingException et non une NameNotFoundException) return dataSources; } initialContext.close(); return dataSources; }
protected void setUp() throws Exception { InitialContext ctx = getInitialContext(); // JNDI name of service interface (in application-client.xml) String serviceRefName = "service/Hello"; // lookup service interface in environment context service = (HelloWorldService) ctx.lookup("java:comp/env/" + serviceRefName); }
public DigitalLibraryServer() { try { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces"); properties.put(Context.PROVIDER_URL, "localhost"); InitialContext jndi = new InitialContext(properties); ConnectionFactory conFactory = (ConnectionFactory) jndi.lookup("XAConnectionFactory"); connection = conFactory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { counterTopic = (Topic) jndi.lookup("counterTopic"); } catch (NamingException NE1) { System.out.println("NamingException: " + NE1 + " : Continuing anyway..."); } if (null == counterTopic) { counterTopic = session.createTopic("counterTopic"); jndi.bind("counterTopic", counterTopic); } consumer = session.createConsumer(counterTopic); consumer.setMessageListener(this); System.out.println("Server started waiting for client requests"); connection.start(); } catch (NamingException NE) { System.out.println("Naming Exception: " + NE); } catch (JMSException JMSE) { System.out.println("JMS Exception: " + JMSE); JMSE.printStackTrace(); } }
public String doSpellingSuggestion(java.lang.String key, java.lang.String phrase) throws RemoteException { System.out.println("GoogleServletImpl.doSpellingSuggestion() " + " called with " + phrase); if (!gotInit) { throw new RuntimeException("Got business method before init()"); } String returnValue = "spelling suggestion from web"; if (phrase.equals("forwardejb")) { System.out.println("Forwarding spelling suggestion to ejbendpoint"); Service genericServiceWithWSDL = null; try { InitialContext ic = new InitialContext(); Service service = (Service) ic.lookup("java:comp/env/service/EjbDIIReference"); doDynamicProxyTest(service); GoogleSearchPort ejbPort = (GoogleSearchPort) service.getPort(GoogleSearchPort.class); returnValue = ejbPort.doSpellingSuggestion(key, phrase); } catch (Exception e) { e.printStackTrace(); throw new RemoteException(e.getMessage(), e); } } System.out.println("GoogleServletImpl returning " + returnValue); return returnValue; }
/** Add the objects passed to the constructor to the JNDI Context addresses specified */ public void setup() { try { InitialContext ic = new InitialContext(); for (Iterator i = this.objectsToCreate.keySet().iterator(); i.hasNext(); ) { String name = (String) i.next(); try { Name fullName = new CompositeName(name); Context currentContext = ic; while (fullName.size() > 1) { // Make contexts that are not already present try { currentContext = currentContext.createSubcontext(fullName.get(0)); } catch (NamingException err) { currentContext = (Context) currentContext.lookup(fullName.get(0)); } fullName = fullName.getSuffix(1); } ic.bind(name, this.objectsToCreate.get(name)); Logger.log(Logger.FULL_DEBUG, JNDI_RESOURCES, "ContainerJNDIManager.BoundResource", name); } catch (NamingException err) { Logger.log( Logger.ERROR, JNDI_RESOURCES, "ContainerJNDIManager.ErrorBindingResource", name, err); } } Logger.log( Logger.DEBUG, JNDI_RESOURCES, "ContainerJNDIManager.SetupComplete", "" + this.objectsToCreate.size()); } catch (NamingException err) { Logger.log( Logger.ERROR, JNDI_RESOURCES, "ContainerJNDIManager.ErrorGettingInitialContext", err); } }
public static Connection getConnection() throws IOException, ClassNotFoundException, SQLException, NamingException { if (connection == null || connection.isClosed()) { InputStream in = JDBCConnection.class.getClassLoader().getResourceAsStream("jdbc.dev.properties"); // InputStream in = // JDBCConnection.class.getClassLoader().getResourceAsStream("/MavenWebAppSample2/webapp/jdbc.dev.properties"); // InputStream in = null; if (in != null) { logger.info("Using jdbc.dev.properties"); Properties prop = new Properties(); prop.load(in); in.close(); String url = prop.getProperty("url"); String user = prop.getProperty("user"); String pass = prop.getProperty("pass"); String driver = prop.getProperty("driver"); // Dev mode Class.forName(driver); connection = java.sql.DriverManager.getConnection(url, user, pass); } else { logger.info("Using data source"); // Cloud mode InitialContext ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/DefaultDB"); connection = ds.getConnection(); } } return connection; }
public static void main(String[] args) throws Exception { int expectedCount = Integer.parseInt(args[0]); SimpleReporterAdapter stat = new SimpleReporterAdapter(); String testSuite = "rar-accesibility"; InitialContext ic = new InitialContext(); Object objRef = ic.lookup("java:comp/env/ejb/SimpleSessionHome"); SimpleSessionHome simpleSessionHome = (SimpleSessionHome) javax.rmi.PortableRemoteObject.narrow(objRef, SimpleSessionHome.class); stat.addDescription("Running rar_accessibility connector test "); SimpleSession bean = simpleSessionHome.create(); try { if (bean.test1(expectedCount)) { stat.addStatus(testSuite + " test : ", stat.PASS); } else { stat.addStatus(testSuite + " test : ", stat.FAIL); } } catch (Exception e) { e.printStackTrace(); } stat.printSummary(); }
private boolean loadTomcatParameters() { InitialContext initCtx = null; try { initCtx = new InitialContext(); NamingContext envCtx = (NamingContext) initCtx.lookup("java:comp/env"); try { CommandRunner.setServerSettingFromTomcatConfig( "app_output_dir", (String) envCtx.lookup("app_output_dir")); } catch (NamingException e) { File rootFolder = new File(ApplicationSettings.WEBAPP_ROOT_DIRECTORY); String appHome = rootFolder.getParentFile().getParentFile().getParent(); CommandRunner.setServerSettingFromTomcatConfig("app_output_dir", appHome); } try { CommandRunner.setServerSettingFromTomcatConfig( "is_test_version", (String) envCtx.lookup("is_test_version")); } catch (NameNotFoundException e) { // Absent is_test_version variable in context.xml CommandRunner.setServerSettingFromTomcatConfig("is_test_version", "false"); } CommandRunner.setServerSettingFromTomcatConfig( "backend_url", (String) envCtx.lookup("backend_url")); return true; } catch (Throwable e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. return false; } }
@Override public void setUp() throws SetupException { InitialContext initContext = null; try { initContext = new InitialContext(); String openid = (String) initContext.lookup("java:global/zanata/security/auth-policy-names/openid"); if (openid != null) { dbAuthType = "OPENID"; } else { dbAuthType = "OTHER"; } } catch (NameNotFoundException e) { dbAuthType = "OTHER"; } catch (NamingException e) { throw new SetupException(e); } finally { if (initContext != null) { try { initContext.close(); } catch (NamingException e) { e.printStackTrace(); } } } }
@Override public int getCountOfImeisRecorded(String userAdmin) throws MSMApplicationException { IMEIManager imeiManager = null; int qtde = 0; try { InitialContext initialContext = new InitialContext(); imeiManager = (IMEIManager) initialContext.lookup("ndg-core/IMEIManagerBean/remote"); } catch (NamingException e) { e.printStackTrace(); } ArrayList<Object> queryResult = listAllUsers(userAdmin, null).getQueryResult(); ArrayList<UserVO> listUsers = new ArrayList<UserVO>(); for (Iterator iterator = queryResult.iterator(); iterator.hasNext(); ) { UserVO object = (UserVO) iterator.next(); listUsers.add(object); } for (UserVO userVO : listUsers) { qtde += imeiManager.findImeiByUser(userVO.getUsername(), null, true).getQueryResult().size(); } return qtde; }
@BeforeClass public void setup() throws Exception { InitialContext context = new InitialContext(Util.getInitProperties()); orderService = (OrderService) context.lookup(Util.ORDER_SERVICE_NAME); customerService = (CustomerService) context.lookup(Util.CUSTOMER_SERVICE_NAME); catalogService = (CatalogService) context.lookup(Util.CATALOG_SERVICE_NAME); }
public static EJBObject getRemoteEJBConnection(String url, String jndiName, String factory) throws NamingException, RemoteException { EJBObject object = null; EBWLogger.logDebug( "com.tcs.ebw.ejb.EjbConnection ", " entering into the getRemoteEJBConnection method "); if (remoteEjbMap == null) { remoteEjbMap = new LinkedHashMap(); } if (!remoteEjbMap.containsKey(jndiName)) { Properties prop = new Properties(); prop.put("java.naming.factory.initial", factory); prop.put("java.naming.provider.url", url); InitialContext ctx = new InitialContext(prop); Object obj = ctx.lookup(jndiName); EJBHome home = (EJBHome) PortableRemoteObject.narrow(obj, EJBHome.class); Class homeintf = home.getEJBMetaData().getHomeInterfaceClass(); object = (EJBObject) invoke(homeintf, home, "create"); if (object != null) remoteEjbMap.put(jndiName, object); } else object = (EJBObject) remoteEjbMap.get(jndiName); EBWLogger.logDebug("com.tcs.ebw.ejb.EjbConnection ", " The connection object is " + object); return object; }
public static EJBObject getLocalEJBConnection(String url, String jndiName, String factory) throws NamingException, RemoteException { EJBObject object = null; EBWLogger.logDebug( "com.tcs.ebw.ejb.EjbConnection ", " entering into the getLocalEJBConnection method "); if (localEjbMap == null) { localEjbMap = new LinkedHashMap(); } if (!localEjbMap.containsKey(jndiName)) { // System.out.println("key not found in hashmap "); Properties prop = new Properties(); prop.put("java.naming.factory.initial", factory); prop.put("java.naming.provider.url", url); InitialContext ctx = new InitialContext(prop); EJBHome home = (EJBHome) ctx.lookup(jndiName); Class homeintf = home.getEJBMetaData().getHomeInterfaceClass(); object = (EJBObject) invoke(homeintf, home, "create"); if (object != null) localEjbMap.put(jndiName, object); } else object = (EJBObject) localEjbMap.get(jndiName); EBWLogger.logDebug("com.tcs.ebw.ejb.EjbConnection ", " The connection object is " + object); return object; }
protected DataSource getDataSourceFromJNDI(String name) { final DataSource dataSource; InitialContext ctx = null; try { ctx = new InitialContext(); Object wathever = ctx.lookup(name); if (wathever == null) { throw new IllegalArgumentException("JNDI name " + name + " is not bound"); } else if (!(wathever instanceof DataSource)) { throw new IllegalArgumentException( "JNDI name " + name + " was found but is not a DataSource"); } else { dataSource = (DataSource) wathever; if (log.isDebugEnabled()) { log.debug("Datasource found via JNDI lookup via name: '" + name + "'."); } return dataSource; } } catch (NamingException e) { throw new IllegalArgumentException("Could not lookup datasource " + name, e); } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { log.warn("Failed to close naming context.", e); } } } }
public void statefulTest() throws Exception { InitialContext ctx = new InitialContext(); StatefulTestLocal test = (StatefulTestLocal) ctx.lookup("initial-ejb3-test/StatefulTestBean/local"); test.setState("hello world"); if (!test.getState().equals("hello world")) throw new Exception("state was not retained"); }
public static void main(String[] args) { try { // Create and start connection InitialContext ctx = new InitialContext(); QueueConnectionFactory f = (QueueConnectionFactory) ctx.lookup("myQueueConnectionFactory"); QueueConnection con = f.createQueueConnection(); con.start(); // 2) create queue session QueueSession ses = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); // 3) get the Queue object Queue t = (Queue) ctx.lookup("myQueue"); // 4)create QueueSender object QueueSender sender = ses.createSender(t); // 5) create TextMessage object TextMessage msg = ses.createTextMessage(); // 6) write message BufferedReader b = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Enter Msg, end to terminate:"); String s = b.readLine(); if (s.equals("end")) break; msg.setText(s); // 7) send message sender.send(msg); System.out.println("Message successfully sent."); } // 8) connection close con.close(); } catch (Exception e) { System.out.println(e); } }
/** * Provides a lazy load when created with a target EPR. This method performs actual lookup for the * connection factory and destination */ private void loadConnectionFactoryFromProperties() { if (properties != null) { // This condition passes only when the JMSOutTransportInfo is created from an EPR InitialContext context = null; try { // It's a little expensive to do this for each and every outgoing request, but // the user can avoid this by defining a connection factory for JMS sender // TODO: See if this can be further optimized by caching the destination by EPR context = new InitialContext(properties); } catch (NamingException e) { handleException("Could not get an initial context using " + properties, e); } if (destination == null) { destination = getDestination(context, targetEPR); replyDestination = getReplyDestination(context, targetEPR); } connectionFactory = getConnectionFactory(context, properties); if (context != null) { try { context.close(); } catch (NamingException e) { log.warn("Error while cleaning up the InitialContext", e); } } } }
/** * Deletes an exclusion to the database. * * @param id Exclusion ID * @throws StatusException Throws a status exception if the delete fails. */ private void delete(String id) throws StatusException { InitialContext initialContext = null; Context context = null; DataSource ds = null; Connection conn = null; PreparedStatement pStmt = null; try { initialContext = new InitialContext(); context = (Context) initialContext.lookup("java:comp/env"); ds = (DataSource) context.lookup("jdbc/OpenSQM"); conn = ds.getConnection(); // Add the question pStmt = conn.prepareStatement(EXCLUSION_DELETE_SQL); pStmt.setString(1, id); pStmt.executeUpdate(); pStmt.close(); } catch (Exception e) { e.printStackTrace(); throw new StatusException("800", e.toString()); } finally { try { conn.close(); } catch (Exception e2) { } } }
@Override public boolean login(String jndiName, String userName, String password, String workspace) throws RemoteException { Repository repository = null; try { repository = RepositoryManager.getRepository(jndiName); } catch (Exception e) { e.printStackTrace(); try { InitialContext context = new InitialContext(); repository = (Repository) context.lookup(jndiName); } catch (Exception ex) { throw new RemoteException(e.getMessage() + " or " + ex.getMessage()); } } try { Session session; if (userName != null && userName.length() > 0) { SimpleCredentials creds = new SimpleCredentials(userName, password.toCharArray()); session = repository.login(creds, workspace); } else { session = repository.login(workspace); } this.getThreadLocalRequest().getSession().setAttribute("session", session); return true; } catch (Exception e) { throw new RemoteException(e.getMessage()); } }
/** * - We first create a {@link Context}, do a lookup and then stop the server. - Next we do the * lookup and it's expected to fail, since the server is down. - We restart the server and use the * same previously created {@link Context} and do the lookup again. The lookup is expected to * succeed * * @throws Exception */ @Test public void testReconnect() throws Exception { Properties env = new Properties(); env.put( Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName()); env.put(Context.PROVIDER_URL, "remote://localhost:7999"); env.put("jboss.naming.client.ejb.context", "false"); final InitialContext context = new InitialContext(env); assertEquals("TestValue", context.lookup("test")); // now stop the server stopServer(); logger.info("Stopped server"); // lookup again, should fail since server is stopped try { context.lookup("test"); fail("Lookup was expected to fail when server was down"); } catch (NamingException ne) { // expected } // now restart the server startServer(); // now lookup again, this should succeed (internally a reconnect to the restarted server should // happen) final String lookupValueAfterServerRestart = (String) context.lookup("test"); assertEquals( "Unexpected lookup value after server was restarted", "TestValue", lookupValueAfterServerRestart); }
@Override public void evaluate() throws Throwable { InitialContext initialContext; try { System.setProperty( Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); initialContext = new InitialContext(new Hashtable<String, Object>()); initialContext.createSubcontext("java:"); } catch (NamingException e) { throw new RuntimeException(e); } try { parent.evaluate(); for (EntityManager e : createdEntityManagers) { if (e.getTransaction().isActive()) { e.getTransaction().rollback(); throw new AssertionError("EntityManager " + e + " left an open transaction"); } } } finally { initialContext.destroySubcontext("java:"); initialContext.close(); try { for (EntityManager e : createdEntityManagers) { e.close(); } } finally { createdEntityManagers.clear(); for (EntityManagerFactory emf : usedPersistenceUnits) { clearTables(emf); } } } }
/** * Init the Derby Datasource in JNDI. * * @param context the naming context * @param name the dabase name in the context * @param datasourceName the datasource Name * @param user * @param password * @return <code>true</code> if initialized, <code>false</code> otherwise */ public static boolean initDerbyDatasource( final InitialContext context, final String name, final String datasourceName, final String user, final String password) { boolean init = true; try { context.createSubcontext("java:"); context.createSubcontext("java:/comp"); context.createSubcontext("java:/comp/env"); context.createSubcontext("java:/comp/env/jdbc"); // Construct DataSource final EmbeddedConnectionPoolDataSource40 datasource = new EmbeddedConnectionPoolDataSource40(); datasource.setDatabaseName(datasourceName); datasource.setUser("user"); datasource.setPassword("password"); LOGGER.info("Datasource created"); validateDerbyConnection(datasource); context.bind("java:/comp/env/jdbc/" + name, datasource); } catch (NamingException e) { LOGGER.error("Naming Exception", e); init = false; } return init; }
/** Remove the objects under administration from the JNDI Context, and then destroy the objects */ public void tearDown() { try { InitialContext ic = new InitialContext(); for (Iterator i = this.objectsToCreate.keySet().iterator(); i.hasNext(); ) { String name = (String) i.next(); try { ic.unbind(name); } catch (NamingException err) { Logger.log( Logger.ERROR, JNDI_RESOURCES, "ContainerJNDIManager.ErrorUnbindingResource", name, err); } Object unboundObject = this.objectsToCreate.get(name); if (unboundObject instanceof WinstoneDataSource) ((WinstoneDataSource) unboundObject).destroy(); Logger.log(Logger.FULL_DEBUG, JNDI_RESOURCES, "ContainerJNDIManager.UnboundResource", name); } Logger.log( Logger.DEBUG, JNDI_RESOURCES, "ContainerJNDIManager.TeardownComplete", "" + this.objectsToCreate.size()); } catch (NamingException err) { Logger.log( Logger.ERROR, JNDI_RESOURCES, "ContainerJNDIManager.ErrorGettingInitialContext", err); } }
private void init() { if (this.config == null || !this.config.containsKey(DS_JNDI_NAME) || !this.config.containsKey(PRINCIPAL_QUERY) || !this.config.containsKey(ROLES_QUERY) || !this.config.containsKey(USER_ROLES_QUERY)) { throw new IllegalArgumentException( "All properties must be given (" + DS_JNDI_NAME + "," + USER_ROLES_QUERY + "," + ROLES_QUERY + "," + USER_ROLES_QUERY + ")"); } String jndiName = this.config.getProperty(DS_JNDI_NAME, "java:/DefaultDS"); try { InitialContext ctx = new InitialContext(); ds = (DataSource) ctx.lookup(jndiName); } catch (Exception e) { throw new IllegalStateException( "Can get data source for DB usergroup callback, JNDI name: " + jndiName, e); } }
/** Validate the stateful bean is not clustered by having failover not work */ public void testStatefulBean() throws Exception { // Connect to the server0 JNDI InitialContext ctx = getInitialContext(0); DisableClusteredAnnotationRemote stateful = null; try { stateful = (DisableClusteredAnnotationRemote) ctx.lookup("DisableClusteredAnnotationStateful/remote"); } catch (NameNotFoundException nnfe) { fail(nnfe.getMessage()); } NodeAnswer node1 = stateful.getNodeState(); getLog().debug("Node 1 ID: " + node1); // Now we switch to the other node, simulating a failure on node 1 // stateful.setUpFailover("once"); try { stateful.getNodeState(); fail("GenericClusteringException did not propagate"); } catch (Exception good) { } }
@GET @Path("dead-messages") public String listDeadMessageQueue() throws NamingException, JMSException { InitialContext ctx = new InitialContext(); ctx.lookup("jms/mq.sys.dmq"); return "bla"; }
/** Generates secret key. Initializes MAC(s). */ private void setupKeyAndMac() { /* * Lets see if an encoded key was given to the application, if so use * it and skip the code to generate it. */ try { InitialContext context = new InitialContext(); String encodedKeyArray = (String) context.lookup("java:comp/env/jsf/ClientSideSecretKey"); byte[] keyArray = DatatypeConverter.parseBase64Binary(encodedKeyArray); sk = new SecretKeySpec(keyArray, KEY_ALGORITHM); } catch (NamingException exception) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.log(Level.FINEST, "Unable to find the encoded key.", exception); } } if (sk == null) { try { KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM); kg.init(KEY_LENGTH); // 256 if you're using the Unlimited Policy Files sk = kg.generateKey(); // System.out.print("SecretKey: " + // DatatypeConverter.printBase64Binary(sk.getEncoded())); } catch (Exception e) { throw new FacesException(e); } } }
public void testSFSBCollocation() throws Exception { InitialContext ctx = new InitialContext(); StatefulTestLocal local = (StatefulTestLocal) ctx.lookup("initial-ejb3-test/StatefulTestBean/local"); StatefulTestRemote remote = (StatefulTestRemote) ctx.lookup("initial-ejb3-test/StatefulTestBean/remote"); if (local.getObject() != StatefulTestBean.obj) throw new RuntimeException("Local call not equal"); if (local.getObject() == remote.getObject()) throw new RuntimeException("Remote should not be equal"); Map map = remote.getObject(); map.put("hello", "world"); Object obj = local.echo(map); if (obj != map) throw new RuntimeException("argument and return should be the same"); map = (Map) obj; if (!map.containsKey("hello")) throw new RuntimeException("not good return"); obj = remote.echo(map); if (obj == map) throw new RuntimeException("argument and return should not be the same"); map = (Map) obj; if (!map.containsKey("hello")) throw new RuntimeException("not good return"); }
public void init(List serviceList, ServerConfig serverConfig, MBeanServer mbeanServer) { System.setProperty("java.io.tmpdir", serverConfig.getCachedir()); try { this.serviceList = serviceList; this.serverConfig = serverConfig; this.mbeanServer = mbeanServer; fsManager.init(); } catch (Exception e) { log.error("Unable to initialie file system: " + fsManager, e); } try { registry = LocateRegistry.createRegistry(Integer.parseInt(serverConfig.getRmiregistryport())); ic = new InitialContext(); Context subctx = null; try { subctx = (Context) ic.lookup("java:"); } catch (Exception ex) { log.error("initializing the java context", ex); // ex.printStackTrace(); } if (subctx == null) { ic.createSubcontext("java:"); } remoteBindingInterface = new RemoteBindingObject(ic); Object jndilookupobj = UnicastRemoteObject.exportObject( remoteBindingInterface, Integer.parseInt(serverConfig.getRmiregistryport())); registry.rebind("RemoteBindingObject", (Remote) jndilookupobj); } catch (Exception ex) { log.error("error in registring to the remote binding object", ex); // e1.printStackTrace(); } log.info("initialized"); }
static Map<String, DataSource> getJndiDataSources() throws NamingException { final Map<String, DataSource> dataSources = new LinkedHashMap<String, DataSource>(2); final String datasourcesParameter = Parameters.getParameter(Parameter.DATASOURCES); if (datasourcesParameter == null) { dataSources.putAll(getJndiDataSourcesAt("java:comp/env/jdbc")); // pour jboss sans jboss-env.xml ou sans resource-ref dans web.xml : dataSources.putAll(getJndiDataSourcesAt("java:/jdbc")); // pour JavaEE 6 : // (voir par exemple // http://smokeandice.blogspot.com/2009/12/datasourcedefinition-hidden-gem-from.html) dataSources.putAll(getJndiDataSourcesAt("java:global/jdbc")); // pour WebLogic 10 et WebSphere 7, cf issue 68 dataSources.putAll(getJndiDataSourcesAt("jdbc")); } else if (datasourcesParameter.trim().length() != 0) { // NOPMD final InitialContext initialContext = new InitialContext(); for (final String datasource : datasourcesParameter.split(",")) { final String jndiName = datasource.trim(); // ici, on n'ajoute pas java:/comp/env // et on suppose qu'il n'en faut pas ou que cela a été ajouté dans le paramétrage final DataSource dataSource = (DataSource) initialContext.lookup(jndiName); dataSources.put(jndiName, dataSource); } initialContext.close(); } return Collections.unmodifiableMap(dataSources); }