List of usage examples for javax.naming Context close
public void close() throws NamingException;
From source file:org.jbpm.bpel.tutorial.invoice.ComputePricePT_Impl.java
protected void initJmsObjects() throws NamingException, JMSException { Context initialContext = new InitialContext(); try {//from ww w .j av a2 s . c o m Context environmentContext = (Context) initialContext.lookup("java:comp/env"); invoiceDestination = (Destination) environmentContext.lookup(INVOICE_DESTINATION_NAME); log.debug("Retrieved destination: " + INVOICE_DESTINATION_NAME); ConnectionFactory jmsConnectionFactory = (ConnectionFactory) environmentContext .lookup(CONNECTION_FACTORY_NAME); jmsConnection = jmsConnectionFactory.createConnection(); log.debug("Created JMS connection: factory=" + CONNECTION_FACTORY_NAME); } finally { initialContext.close(); } }
From source file:org.jbpm.bpel.tutorial.purchase.ejb.ShippingCallbackMessageBean.java
protected PurchaseOrderService lookupPurchaseService() throws NamingException { Context initialContext = new InitialContext(); try {//from w ww . j a va 2s. c o m return (PurchaseOrderService) initialContext.lookup("java:comp/env/service/PurchaseOrder"); } finally { initialContext.close(); } }
From source file:org.jbpm.bpel.tutorial.shipping.ShippingPT_Impl.java
protected void initJmsObjects() throws NamingException, JMSException { Context initialContext = new InitialContext(); try {/*from w w w . java2 s . c o m*/ Context environmentContext = (Context) initialContext.lookup("java:comp/env"); shippingDestination = (Destination) environmentContext.lookup(SHIPPING_DESTINATION_NAME); log.debug("Retrieved destination: " + SHIPPING_DESTINATION_NAME); ConnectionFactory jmsConnectionFactory = (ConnectionFactory) environmentContext .lookup(CONNECTION_FACTORY_NAME); jmsConnection = jmsConnectionFactory.createConnection(); log.debug("Created JMS connection: factory=" + CONNECTION_FACTORY_NAME); } finally { initialContext.close(); } }
From source file:org.jbpm.bpel.tutorial.task.TaskManager_Impl.java
public void init(Object context) throws ServiceException { // jbpm configuration ServletEndpointContext endpointContext = (ServletEndpointContext) context; String configResource = endpointContext.getServletContext().getInitParameter(JBPM_CONFIG_RESOURCE_PARAM); jbpmConfiguration = JbpmConfiguration.getInstance(configResource); // task callback service try {/* w w w .ja va 2 s. co m*/ Context initialContext = new InitialContext(); taskCallbackService = (Service) initialContext.lookup("java:comp/env/service/TaskCallback"); initialContext.close(); } catch (NamingException e) { throw new ServiceException("could not retrieve task callback service", e); } }
From source file:org.jbpm.msg.jms.JmsMessageServiceFactoryImpl.java
public JmsMessageServiceFactoryImpl() { try {//from ww w . j a va2 s . co m Context initial = new InitialContext(); connectionFactory = (ConnectionFactory) initial.lookup(connectionFactoryJndiName); destination = (Destination) initial.lookup(destinationJndiName); initial.close(); } catch (NamingException e) { log.error("jms object lookup problem", e); throw new JbpmException("jms object lookup problem", e); } }
From source file:org.jkcsoft.java.util.JndiHelper.java
public static void safeClose(Context context) { if (context != null) { try {/*from w w w. j a v a2 s .com*/ context.close(); } catch (NamingException e) { log.error("safeClose()", e); } } else { } }
From source file:org.jsecurity.jndi.JndiTemplate.java
/** * Execute the given JNDI context callback implementation. * * @param contextCallback JndiCallback implementation * @return a result object returned by the callback, or <code>null</code> * @throws NamingException thrown by the callback implementation * @see #createInitialContext//ww w . j a v a2 s .co m */ public Object execute(JndiCallback contextCallback) throws NamingException { Context ctx = createInitialContext(); try { return contextCallback.doInContext(ctx); } finally { try { ctx.close(); } catch (NamingException ex) { log.debug("Could not close JNDI InitialContext", ex); } } }
From source file:org.onehippo.forge.resetpassword.services.mail.MailServiceImpl.java
protected Session getSession() { String sessionName = getMailSession(); if (sessionName == null || sessionName.length() <= 0) { sessionName = DEFAULT_MAIL_SESSION; }//w w w. j a v a 2 s .com Context initialContext = null; try { initialContext = new InitialContext(); final Context context = (Context) initialContext.lookup("java:comp/env"); return (Session) context.lookup(sessionName); } catch (final NamingException e) { LOGGER.error("Error creating email session: " + sessionName, e); try { if (initialContext != null) { initialContext.close(); } } catch (final NamingException exception) { if (LOGGER.isDebugEnabled()) { LOGGER.error("Error finding context", exception); } } } return null; }
From source file:org.quartz.utils.JNDIConnectionProvider.java
private void init() { if (!isAlwaysLookup()) { Context ctx = null; try {//from www . j a v a 2s . co m ctx = (props != null) ? new InitialContext(props) : new InitialContext(); datasource = (DataSource) ctx.lookup(url); } catch (Exception e) { getLog().error("Error looking up datasource: " + e.getMessage(), e); } finally { if (ctx != null) { try { ctx.close(); } catch (Exception ignore) { } } } } }
From source file:org.quartz.utils.JNDIConnectionProvider.java
public Connection getConnection() throws SQLException { Context ctx = null; try {//from w ww. j av a2 s .c om Object ds = this.datasource; if (ds == null || isAlwaysLookup()) { ctx = (props != null) ? new InitialContext(props) : new InitialContext(); ds = ctx.lookup(url); if (!isAlwaysLookup()) { this.datasource = ds; } } if (ds == null) { throw new SQLException("There is no object at the JNDI URL '" + url + "'"); } if (ds instanceof XADataSource) { return (((XADataSource) ds).getXAConnection().getConnection()); } else if (ds instanceof DataSource) { return ((DataSource) ds).getConnection(); } else { throw new SQLException("Object at JNDI URL '" + url + "' is not a DataSource."); } } catch (Exception e) { this.datasource = null; throw new SQLException("Could not retrieve datasource via JNDI url '" + url + "' " + e.getClass().getName() + ": " + e.getMessage()); } finally { if (ctx != null) { try { ctx.close(); } catch (Exception ignore) { } } } }