Example usage for javax.naming InitialContext close

List of usage examples for javax.naming InitialContext close

Introduction

In this page you can find the example usage for javax.naming InitialContext close.

Prototype

public void close() throws NamingException 

Source Link

Usage

From source file:org.jboss.as.test.integration.security.loginmodules.RemotingLoginModuleTestCase.java

/**
 * Tests if client access is denied for untrusted clients.
 *
 * @throws Exception/*from  ww  w  .j a  v  a2s.c  o m*/
 */
@Test
public void testNotTrustedClient() throws Exception {
    final Properties env = configureEjbClient(CLIENT_NOT_TRUSTED_NAME);
    InitialContext ctx = new InitialContext(env);
    try {
        ctx.lookup(HELLOBEAN_LOOKUP_NAME);
        fail("The JNDI lookup should fail for untrusted client.");
    } catch (NamingException e) {
        //OK
    }
    ctx.close();
}

From source file:org.jbpm.bpel.integration.jms.IntegrationControl.java

/**
 * Prepares inbound message activities annotated to create a process instance for receiving
 * requests.//from ww w.j a  va2s.  c  o m
 */
public void enableInboundMessageActivities(JbpmContext jbpmContext) throws NamingException, JMSException {
    InitialContext initialContext = new InitialContext();
    try {
        // publish partner link information to JNDI
        BpelProcessDefinition processDefinition = getDeploymentDescriptor().findProcessDefinition(jbpmContext);
        buildPartnerLinkEntries(initialContext, processDefinition);

        // open a jms connection
        openJmsConnection(initialContext);

        try {
            // enable start IMAs
            StartListenersBuilder builder = new StartListenersBuilder(this);
            builder.visit(processDefinition);

            // note: upon creation, start listeners add themselves to this control
            if (startListeners.isEmpty())
                throw new BpelException(processDefinition + " has no start activities");

            // enable outstanding IMAs
            IntegrationSession integrationSession = IntegrationSession.getContextInstance(jbpmContext);
            JmsIntegrationService integrationService = JmsIntegrationService.get(jbpmContext);

            // receive
            for (Iterator i = integrationSession.findReceiveTokens(processDefinition).iterator(); i
                    .hasNext();) {
                Token token = (Token) i.next();
                Receive receive = (Receive) token.getNode();
                integrationService.jmsReceive(receive.getReceiveAction(), token, this, true);
            }

            // pick
            for (Iterator i = integrationSession.findPickTokens(processDefinition).iterator(); i.hasNext();) {
                Token token = (Token) i.next();
                // pick points activity token to begin mark
                Begin begin = (Begin) token.getNode();
                Pick pick = (Pick) begin.getCompositeActivity();
                integrationService.jmsReceive(pick.getOnMessages(), token, this);
            }

            // event
            for (Iterator t = integrationSession.findEventTokens(processDefinition).iterator(); t.hasNext();) {
                Token token = (Token) t.next();
                // scope points events token to itself
                Scope scope = (Scope) token.getNode();
                List onEvents = scope.getOnEvents();
                for (int i = 0, n = onEvents.size(); i < n; i++) {
                    OnEvent onEvent = (OnEvent) onEvents.get(i);
                    integrationService.jmsReceive(onEvent.getReceiveAction(), token, this, false);
                }
            }

            // start message delivery
            jmsConnection.start();
        } catch (JMSException e) {
            jmsConnection.close();
            throw e;
        }
    } finally {
        initialContext.close();
    }
}

From source file:org.jbpm.bpel.tutorial.atm.terminal.AtmTerminal.java

private static FrontEnd createAtmFrontEnd() {
    try {//www  . j  ava  2 s  .  c o  m
        InitialContext jndiContext = new InitialContext();
        AtmFrontEndService service = (AtmFrontEndService) jndiContext.lookup("java:comp/env/service/ATM");
        jndiContext.close();

        return service.getFrontEndPort();
    } catch (NamingException e) {
        log.error("could not retrieve service instance", e);
        return null;
    } catch (ServiceException e) {
        log.error("could not get port proxy", e);
        return null;
    }
}

From source file:org.jbpm.bpel.tutorial.purchase.ejb.InvoiceCallbackMessageBean.java

protected PurchaseOrderService lookupPurchaseOrderService() throws NamingException {
    InitialContext initialContext = new InitialContext();
    try {//from w  w w.  j a v  a  2s  .  c  o m
        return (PurchaseOrderService) initialContext.lookup("java:comp/env/service/PurchaseOrder");
    } finally {
        initialContext.close();
    }
}

From source file:org.nimbustools.ctxbroker.rest.BrokerResource.java

protected static ContextBrokerHomeImpl discoverHome() throws Exception {
    InitialContext ctx = null;
    try {//from w  ww .ja va 2  s. c  o m
        ctx = new InitialContext();
        final ContextBrokerHomeImpl home = (ContextBrokerHomeImpl) ctx
                .lookup(ContextBrokerServiceImpl.CONTEXTUALIZATION_HOME);
        if (home == null) {
            throw new Exception("null from JNDI for ContextBrokerHome (?)");
        }
        return home;
    } finally {
        if (ctx != null) {
            ctx.close();
        }
    }
}

From source file:org.nimbustools.ctxbroker.service.ContextBrokerHomeImpl.java

public static BootstrapFactory discoverBootstrapFactory() throws Exception {

    InitialContext ctx = null;
    try {//w ww  .jav a  2  s .  co m
        ctx = new InitialContext();

        final BootstrapFactory factory = (BootstrapFactory) ctx.lookup(CONTEXTUALIZATION_BOOTSTRAP_FACTORY);

        if (factory == null) {
            throw new Exception("null from JNDI for BootstrapFactory (?)");
        }

        return factory;

    } finally {
        if (ctx != null) {
            ctx.close();
        }
    }
}

From source file:org.nimbustools.ctxbroker.service.ContextBrokerServiceImpl.java

protected static ContextBrokerHome discoverHome() throws Exception {

    InitialContext ctx = null;
    try {//from   w w  w  .jav a  2  s  . c  o  m
        ctx = new InitialContext();

        final ContextBrokerHome home = (ContextBrokerHome) ctx.lookup(CONTEXTUALIZATION_HOME);

        if (home == null) {
            throw new Exception("null from JNDI for ContextBrokerHome (?)");
        }

        return home;

    } finally {
        if (ctx != null) {
            ctx.close();
        }
    }
}

From source file:org.nimbustools.ctxbroker.service.ContextBrokerServiceImpl.java

protected static RestHttp discoverRestHttp() throws Exception {

    InitialContext ctx = null;
    try {/*from   w  ww  .j  a  v a  2 s. c o  m*/
        ctx = new InitialContext();

        final RestHttp rest = (RestHttp) ctx.lookup(REST_HTTP);

        if (rest == null) {
            throw new Exception("null from JNDI for RestHttp (?)");
        }

        return rest;

    } finally {
        if (ctx != null) {
            ctx.close();
        }
    }
}

From source file:org.nimbustools.messaging.gt4_0.common.NimbusMasterContext.java

/**
 * @return TimerManager, never null// w  ww.j a va 2 s  .co  m
 * @throws Exception could not locate
 */
public TimerManager discoverTimerManager() throws Exception {

    InitialContext ctx = null;
    try {
        ctx = new InitialContext();

        final TimerManager timerManager = (TimerManager) ctx.lookup(Constants.DEFAULT_TIMER);

        if (timerManager == null) {
            // should be NameNotFoundException if missing
            throw new Exception("null from JNDI for TimerManager (?)");
        }

        return timerManager;
    } finally {
        if (ctx != null) {
            ctx.close();
        }
    }
}

From source file:org.quartz.impl.jdbcjobstore.JTANonClusteredSemaphore.java

/**
 * Helper method to get the current <code>{@link javax.transaction.Transaction}</code>
 * from the <code>{@link javax.transaction.TransactionManager}</code> in JNDI.
 * /*from  ww w. j  a v  a  2s  .co  m*/
 * @return The current <code>{@link javax.transaction.Transaction}</code>, null if
 * not currently in a transaction.
 */
protected Transaction getTransaction() throws LockException {
    InitialContext ic = null;
    try {
        ic = new InitialContext();
        TransactionManager tm = (TransactionManager) ic.lookup(transactionManagerJNDIName);

        return tm.getTransaction();
    } catch (SystemException e) {
        throw new LockException("Failed to get Transaction from TransactionManager", e);
    } catch (NamingException e) {
        throw new LockException(
                "Failed to find TransactionManager in JNDI under name: " + transactionManagerJNDIName, e);
    } finally {
        if (ic != null) {
            try {
                ic.close();
            } catch (NamingException ignored) {
            }
        }
    }
}