List of usage examples for javax.naming Context lookup
public Object lookup(String name) throws NamingException;
From source file:de.zib.gndms.infra.system.GNDMSystem.java
/** * @see #lookupSystem(javax.naming.Context, javax.naming.Name, de.zib.gndms.infra.GridConfig, boolean) * * @param sharedContext//from w ww . j av a 2s .c om * @param facadeName * @param anySharedConfig * @param debugModeParam * @return * @throws NamingException */ @SuppressWarnings({ "StaticMethodOnlyUsedInOneClass" }) @NotNull public static GNDMSystem lookupSystem(@NotNull Context sharedContext, @NotNull String facadeName, @NotNull GridConfig anySharedConfig, boolean debugModeParam) throws NamingException { try { final SysFactory theFactory = new SysFactory(createLogger(), anySharedConfig, debugModeParam); sharedContext.bind(facadeName, theFactory); return theFactory.getInstance(); } catch (NameAlreadyBoundException ne) { return ((SysFactory) sharedContext.lookup(facadeName)).getInstance(); } }
From source file:org.apache.synapse.transport.jms.JMSOutTransportInfo.java
/** * Get the referenced ConnectionFactory using the properties from the context * * @param context the context to use for lookup * @param props the properties which contains the JNDI name of the factory * @return the connection factory/*from w ww.ja va 2 s .c o m*/ */ private ConnectionFactory getConnectionFactory(Context context, Hashtable props) { try { String conFacJndiName = (String) props.get(JMSConstants.CONFAC_JNDI_NAME_PARAM); if (conFacJndiName != null) { return (ConnectionFactory) context.lookup(conFacJndiName); } else { handleException("Connection Factory JNDI name cannot be determined"); } } catch (NamingException e) { handleException("Connection Factory JNDI name cannot be determined"); } return null; }
From source file:com.sterlingcommerce.xpedx.webchannel.services.XPEDXGetAllReportsAction.java
public void getConnection() throws SQLException { String XCOM_MST_CUST = getCustomerNo(getWCContext().getBuyerOrgCode()); String DBUrl = YFSSystem.getProperty("datasource_url"); String DBName = YFSSystem.getProperty("datasource_name"); //String DBUrl= "t3://localhost:7002"; //String DBName= "SeptJNDI"; Connection connection = null; Statement stmt = null;/*from w w w.j a v a 2 s. c om*/ ResultSet rs = null; XPEDXReportBean rpBean = null; try { Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); ht.put("java.naming.provider.url", DBUrl); Context env = new InitialContext(ht); //InitialContext context = new InitialContext(ht); DataSource dataSource = (DataSource) env.lookup(DBName); connection = dataSource.getConnection(); if (log.isDebugEnabled()) { log.debug("Connection successful.."); } //String schemaName=YFSSystem.getProperty("schemaname"); //String Query="select distinct RPT_CUID, RPT_NAME,RPT_ID,RPT_KIND, RPT_DESC from " + schemaName + ".xpedx_custom_rpt_dtl where XCOM_MST_CUST=" + "'"+ XCOM_MST_CUST +"'"+"AND CUST_ROLE in ("; String Query = "select distinct RPT_CUID, RPT_NAME,RPT_ID,RPT_KIND, RPT_DESC from DH.xpedx_custom_rpt_dtl where XCOM_MST_CUST=" + "'" + XCOM_MST_CUST + "'" + "AND CUST_ROLE in ("; Query = getUserRole(Query); stmt = connection.createStatement(); boolean test = stmt.execute(Query); dataExchangeReportList = new ArrayList<Report>(); if (test == true) { rs = stmt.getResultSet(); while (rs.next()) { Report report = new Report(); report.setCuid(rs.getString("RPT_CUID")); report.setName(rs.getString("RPT_NAME")); report.setKind(rs.getString("RPT_KIND")); report.setId(rs.getInt("RPT_ID")); report.setDescription(rs.getString("RPT_DESC")); dataExchangeReportList.add(report); } } } catch (Exception e) { LOG.debug("Not able to connect to DEV Datasource:->" + e.getMessage()); } finally { stmt.close(); connection.close(); } }
From source file:org.mobicents.charging.server.ratingengine.http.HTTPClientSbb.java
public void setSbbContext(SbbContext context) { this.sbbContext = (SbbContextExt) context; this.tracer = sbbContext.getTracer("CS-RF-HTTP"); try {// www. j ava2 s. c o m Context ctx = (Context) new InitialContext().lookup("java:comp/env"); httpClientAci = (HttpClientActivityContextInterfaceFactory) ctx .lookup("slee/resources/http-client/acifactory"); raSbbInterface = (HttpClientResourceAdaptorSbbInterface) ctx .lookup("slee/resources/http-client/sbbinterface"); httpURLString = (String) ctx.lookup("HTTPURL"); } catch (NamingException ne) { tracer.severe("Could not set SBB context:", ne); } }
From source file:de.zib.gndms.dspace.subspace.service.globus.resource.SubspaceResourceBase.java
public SubspaceResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }//from ww w.ja v a 2s .c om MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/Subspace"; String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration"; logger.debug("Will read configuration from jndi name: " + jndiName); try { Context initialContext = new InitialContext(); this.configuration = (SubspaceResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:com.netcracker.tss.web.servlet.customer.CustomerMMGServiceServlet.java
private TaxiOrderBeanLocal getTaxiOrderBean(HttpServletRequest req) { Context context; try {/*from ww w .j a v a2 s . c o m*/ context = new InitialContext(); TaxiOrderBeanLocalHome taxiOrderBeanLocalHome = (TaxiOrderBeanLocalHome) context .lookup("java:app/tss-ejb/TaxiOrderBean!com.netcracker.ejb.TaxiOrderBeanLocalHome"); return taxiOrderBeanLocalHome.create(); } catch (NamingException ex) { Logger.getLogger(AdminGroupServlet.class.getName()).log(Level.SEVERE, "Can't find taxiOrderBean with name java:app/tss-ejb/TaxiOrderBean!com.netcracker.ejb.TaxiOrderBeanLocalHome ", ex); throw new RuntimeException("Internal server error!");// maybe have // to create // custom // exception? } }
From source file:org.cagrid.caobr.service.globus.resource.CaObrResourceBase.java
public CaObrResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }//w w w . jav a2s .co m MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/CaObr"; String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration"; logger.debug("Will read configuration from jndi name: " + jndiName); try { Context initialContext = new InitialContext(); this.configuration = (CaObrResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:de.iai.ilcd.configuration.ConfigurationService.java
private void migrateDatabaseSchema() { try {/*from ww w .j av a2 s .c o m*/ Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/soda4LCAdbconnection"); Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.setBasePackage("de.iai.ilcd.db.migrations"); flyway.setBaseDir("sql/migrations"); this.logSchemaStatus(flyway); try { flyway.validate(); } catch (ValidationException e) { this.logger.error( "database schema: could not successfully validate database status, database needs to be initialized"); throw new RuntimeException("FATAL ERROR: database schema is not properly initialized", e); } int migrations = flyway.migrate(); if (migrations > 0) { this.logger.info("database schema: successfully migrated"); this.logSchemaStatus(flyway); } } catch (FlywayException e) { this.logger.error("error migrating database schema", e); throw new RuntimeException("FATAL ERROR: database schema is not properly initialized", e); } catch (NamingException e) { this.logger.error("error looking up datasource", e); throw new RuntimeException("FATAL ERROR: could not lookup datasource", e); } }
From source file:de.zib.gndms.GORFX.offer.service.globus.resource.OfferResourceBase.java
public OfferResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }/*from w w w . ja va2s .c om*/ MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/Offer"; String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration"; logger.debug("Will read configuration from jndi name: " + jndiName); try { Context initialContext = new InitialContext(); this.configuration = (OfferResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:org.apache.synapse.config.xml.AbstractDBMediatorFactory.java
/** * Lookup the DataSource on JNDI using the specified properties * @param pool the toplevel 'pool' element that holds DataSource information * @param mediator the mediator to store properties for serialization * @return a DataSource looked up using specified properties *//*from w ww. j av a2 s. c o m*/ private DataSource lookupDataSource(OMElement pool, AbstractDBMediator mediator) { Hashtable props = new Hashtable(); // load the minimum required properties props.put(Context.INITIAL_CONTEXT_FACTORY, (getValue(pool, ICCLASS_Q))); props.put(Context.SECURITY_PRINCIPAL, getValue(pool, USER_Q)); props.put(Context.SECURITY_CREDENTIALS, getValue(pool, PASS_Q)); props.put(Context.PROVIDER_URL, getValue(pool, URL_Q)); String dsName = getValue(pool, DSNAME_Q); //save loaded properties for later mediator.addDataSourceProperty(ICCLASS_Q, getValue(pool, ICCLASS_Q)); mediator.addDataSourceProperty(DSNAME_Q, getValue(pool, DSNAME_Q)); mediator.addDataSourceProperty(URL_Q, getValue(pool, URL_Q)); mediator.addDataSourceProperty(USER_Q, getValue(pool, USER_Q)); mediator.addDataSourceProperty(PASS_Q, getValue(pool, PASS_Q)); try { Context ctx = new InitialContext(props); if (ctx != null) { Object ds = ctx.lookup(dsName); if (ds != null && ds instanceof DataSource) { return (DataSource) ds; } else { handleException("DataSource : " + dsName + " not found when looking up" + " using JNDI properties : " + props); } } else { handleException("Error getting InitialContext using JNDI properties : " + props); } } catch (NamingException e) { handleException("Error looking up DataSource : " + dsName + " using JNDI properties : " + props, e); } return null; }