List of usage examples for javax.naming InitialContext doLookup
@SuppressWarnings("unchecked") public static <T> T doLookup(String name) throws NamingException
From source file:service.emailer.Emailer.java
private static <T> T lookup(Class<T> retvalClass, String jndi) { try {/*from www.j ava 2s. c o m*/ return retvalClass.cast(InitialContext.doLookup(jndi)); } catch (NamingException ex) { throw new IllegalArgumentException("failed to lookup instance of " + retvalClass + " at " + jndi, ex); } }
From source file:ips1ap101.ejb.core.BeanLocator.java
private static Object lookup(Class<?> local) { Bitacora.trace(BeanLocator.class, "lookup", local); String key = EAC.JNDI_EJB_LOOKUP_PATTERN; String pattern = EA.getString(key); String name = local.getSimpleName(); String root = StringUtils.removeEnd(name, LOCAL_SUFFIX); String arg0 = root + BEANS_SUFFIX; String arg1 = local.getName(); String jndi = MessageFormat.format(pattern, arg0, arg1); Bitacora.trace(key + "=" + pattern); Bitacora.trace(key + "=" + jndi); try {// www . ja v a2 s .c o m Object object = InitialContext.doLookup(jndi); boolean assignable = object != null && local.isAssignableFrom(object.getClass()); Bitacora.trace(arg0 + "=" + object + ", assignable=" + assignable); return object; } catch (NamingException ex) { return null; } }
From source file:org.jberet.support.io.XmlItemReaderWriterBase.java
/** * Initializes {@link #xmlFactory} field, which may be instantiated or obtained from other part of the application. *///from w w w . j ava 2s . co m protected void initXmlFactory() throws Exception { if (xmlFactoryLookup != null) { xmlFactory = InitialContext.doLookup(xmlFactoryLookup); xmlMapper = (XmlMapper) xmlFactory.getCodec(); } else { initXmlModule(); xmlFactory = new XmlFactory(); xmlMapper = xmlModule == null ? new XmlMapper(xmlFactory) : new XmlMapper(xmlFactory, xmlModule); xmlFactory.setCodec(xmlMapper); } MappingJsonFactoryObjectFactory.configureCustomSerializersAndDeserializers(xmlMapper, null, null, customDataTypeModules, getClass().getClassLoader()); }
From source file:com.tremolosecurity.scale.config.ScaleCommonConfig.java
@PostConstruct public void init() { try {/* w w w . j a v a 2 s .c o m*/ ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logPath = null; try { logPath = InitialContext.doLookup("java:comp/env/scaleLog4jPath"); } catch (NamingException ne) { try { logPath = InitialContext.doLookup("java:/env/scaleLog4jPath"); } catch (NamingException ne2) { logPath = null; } } if (logPath == null) { Properties props = new Properties(); props.put("log4j.rootLogger", "info,console"); //props.put("log4j.appender.console","org.apache.log4j.RollingFileAppender"); //props.put("log4j.appender.console.File","/home/mlb/myvd.log"); props.put("log4j.appender.console", "org.apache.log4j.ConsoleAppender"); props.put("log4j.appender.console.layout", "org.apache.log4j.PatternLayout"); props.put("log4j.appender.console.layout.ConversionPattern", "[%d][%t] %-5p %c{1} - %m%n"); PropertyConfigurator.configure(props); } else { if (logPath.startsWith("WEB-INF/")) { org.apache.log4j.xml.DOMConfigurator.configure(context.getRealPath(logPath)); } else { org.apache.log4j.xml.DOMConfigurator.configure(logPath); } } logger = Logger.getLogger(ScaleCommonConfig.class.getName()); logger.info("Initializing Scale " + version); String configPath = null; try { configPath = InitialContext.doLookup("java:comp/env/scaleConfigPath"); } catch (NamingException ne) { try { configPath = InitialContext.doLookup("java:/env/scaleConfigPath"); } catch (NamingException ne2) { configPath = null; } } if (configPath == null) { configPath = "WEB-INF/scaleConfig.xml"; logger.warn("No configuraiton path found - Loading configuration from '" + configPath + "'"); } else { logger.info("Loading configuration from '" + configPath + "'"); } InputStream in = null; if (configPath.startsWith("WEB-INF")) { in = new ByteArrayInputStream(ScaleCommonConfig .includeEnvironmentVariables(context.getRealPath("/" + configPath)).getBytes("UTF-8")); } else { in = new ByteArrayInputStream( ScaleCommonConfig.includeEnvironmentVariables(configPath).getBytes("UTF-8")); } JAXBContext jc = JAXBContext.newInstance("com.tremolosecurity.scale.config.xml"); Unmarshaller unmarshaller = jc.createUnmarshaller(); Object obj = unmarshaller.unmarshal(in); JAXBElement<ScaleCommonConfigType> scaleConfig = (JAXBElement<ScaleCommonConfigType>) obj; this.scaleConfig = scaleConfig.getValue(); String ksPath = this.scaleConfig.getServiceConfiguration().getKeyStorePath(); String ksPass = this.scaleConfig.getServiceConfiguration().getKeyStorePassword(); in = null; if (ksPath.startsWith("WEB-INF")) { in = context.getResourceAsStream("/" + ksPath); } else { in = new FileInputStream(ksPath); } this.tlsKeys = KeyStore.getInstance("JKS"); this.tlsKeys.load(in, ksPass.toCharArray()); this.sslctx = SSLContexts.custom().loadTrustMaterial(this.tlsKeys) .loadKeyMaterial(this.tlsKeys, ksPass.toCharArray()).build(); } catch (Exception e) { e.printStackTrace(); } }
From source file:ips1ap101.lib.core.web.app.EJBL.java
public static Object lookup(Class<?> interfaz) { Bitacora.trace(EJBL.class, "lookup", interfaz); String key = EAC.JNDI_EJB_LOOKUP_PATTERN; String pattern = EA.getString(key); String base = interfaz.getSimpleName(); String bean = StringUtils.removeEnd(base, "Base") + "Bean"; String jndi = MessageFormat.format(pattern, bean, interfaz.getName()); Bitacora.trace(key + "=" + pattern); Bitacora.trace(key + "=" + jndi); try {//from www.ja va 2 s. c o m Object facade = InitialContext.doLookup(jndi); boolean assignable = facade != null && interfaz.isAssignableFrom(facade.getClass()); Bitacora.trace(bean + "=" + facade); Bitacora.trace(base + "=" + assignable); return facade; } catch (NamingException ex) { throw new RuntimeException(ex); } }
From source file:ips1ap101.lib.core.db.util.DB.java
public static Connection connect(String dataSourceName, boolean autoCommit) { Bitacora.trace(DB.class, "connect", dataSourceName, autoCommit); Connection connection = null; try {//from w w w. j a v a 2 s. c o m DataSource dataSource = (DataSource) InitialContext.doLookup(dataSourceName); connection = dataSource.getConnection(); if (setAutoCommit(connection, autoCommit)) { Bitacora.stamp(connection, dataSourceName); return connection; } } catch (NamingException | SQLException ex) { Bitacora.logFatal(ex); } close(connection); return null; }
From source file:io.hops.hopsworks.api.zeppelin.notebook.repo.HDFSNotebookRepo.java
public HDFSNotebookRepo(ZeppelinConfiguration conf) throws IOException { this.conf = conf; this.hdfsConf = getHadoopConf(); superuser = UserGroupInformation.getLoginUser(); try {/* w ww . ja va 2 s .c o m*/ // ("java:global/hopsworks-common-0.2.0-SNAPSHOT/DistributedFsService"); String applicationName = InitialContext.doLookup("java:app/AppName"); String moduleName = InitialContext.doLookup("java:module/ModuleName"); moduleName = moduleName.replace("api", "common"); dfsService = InitialContext .doLookup("java:global/" + applicationName + "/" + moduleName + "/DistributedFsService"); } catch (NamingException ex) { throw new IOException(ex); } setNotebookDirectory(this.conf.getNotebookDir()); }
From source file:org.jberet.support.io.JacksonCsvItemReaderWriterBase.java
@Override protected void initJsonFactory() throws Exception { if (jsonFactoryLookup != null) { jsonFactory = InitialContext.doLookup(jsonFactoryLookup); } else {/*from w w w. ja v a2s.c o m*/ jsonFactory = new CsvFactory(new CsvMapper()); } }
From source file:com.reversemind.hypergate.server.PayloadProcessor.java
@Override public Payload process(Object payloadObject) { if (payloadObject == null) { LOG.info("ERROR: " + PayloadStatus.ERROR_CLIENT_PAYLOAD); return PayloadBuilder.buildErrorPayload(PayloadStatus.ERROR_CLIENT_PAYLOAD); }/*from w w w . ja v a 2 s. com*/ if (!(payloadObject instanceof Payload)) { LOG.info("ERROR: " + PayloadStatus.ERROR_CLIENT_PAYLOAD); return PayloadBuilder.buildErrorPayload(PayloadStatus.ERROR_CLIENT_PAYLOAD); } Payload payload = ((Payload) payloadObject); LOG.debug("Get from client:" + payload); Class interfaceClass = payload.getInterfaceClass(); Class pojoClass = this.findPOJOClass(interfaceClass); // POJO if (pojoClass != null) { return this.invokeMethod(payload, pojoClass, payload.getMethodName(), payload.getArguments()); } // EJB String jndiName = this.findEjbClass(interfaceClass); if (!StringUtils.isEmpty(jndiName)) { try { // JBoss AS 7 JNDI name // buildingDAO = InitialContext.doLookup("java:global/ttk-house/ttk-house-ejb-2.0-SNAPSHOT/BuildingDAO!ru.ttk.baloo.house.data.service.building.IBuildingDAO"); Object remoteObject = InitialContext.doLookup(jndiName); return this.invokeEjbMethod(payload, remoteObject, payload.getMethodName(), payload.getArguments()); } catch (NamingException e) { e.printStackTrace(); } } return PayloadBuilder.buildErrorPayload(PayloadStatus.ERROR_UNKNOWN); }
From source file:de.tud.inf.db.sparqlytics.bench.LDBCBenchmark.java
@Test public void testQAllCubesRandomly() throws NamingException { Session session = createSession();//from w w w . j a va2 s. co m Repository repository = (Repository) InitialContext.doLookup("ldbc"); for (Cube cube : repository.getCubes()) { session.setCube(cube); testCube(session); } }