Example usage for javax.naming InitialContext lookup

List of usage examples for javax.naming InitialContext lookup

Introduction

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

Prototype

public Object lookup(Name name) throws NamingException 

Source Link

Usage

From source file:org.pepstock.jem.junit.test.springbatch.java.RestToBeExecutedAndContext.java

/**
 * /*from  w w w.j  ava 2  s  . c  om*/
 * @param stepContribution
 * @param chunkContext
 */
@ToBeExecuted
public void exec(StepContribution stepContribution, ChunkContext chunkContext) {

    if (stepContribution == null || chunkContext == null) {
        throw new RuntimeException("StepContribution or ChuckContext is null");
    }

    try {
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.pepstock.jem.node.tasks.jndi.JemContextFactory");

        InitialContext context = new InitialContext(env);
        RestClient rest = (RestClient) context.lookup("JUNIT-REST-RESOURCE");
        System.err.println();
        System.err.println("*** REST XML");
        get(rest, MediaType.APPLICATION_XML);
        get(rest, MediaType.APPLICATION_JSON);
        get(rest, MediaType.APPLICATION_XML);
        get(rest, MediaType.APPLICATION_JSON);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    try {
        System.err.println();
        System.err.println("*** REST XML");
        get(restC, MediaType.APPLICATION_XML);
        get(restC, MediaType.APPLICATION_JSON);
        get(restC, MediaType.APPLICATION_XML);
        get(restC, MediaType.APPLICATION_JSON);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

From source file:io.apiman.gateway.engine.policies.auth.JDBCIdentityValidator.java

/**
 * Lookup the datasource from JNDI.//from  ww w.j  a  va  2 s.  co m
 * @param ctx
 * @param path
 */
private DataSource lookupDS(InitialContext ctx, String path) {
    try {
        return (DataSource) ctx.lookup(path);
    } catch (NamingException e) {
        return null;
    }
}

From source file:org.atricore.idbus.idojos.dbsessionstore.DataSourceSessionStore.java

/**
 * Lazy load the datasource instace used by this store.
 *
 * @throws SSOSessionException/*from   w w  w.jav a 2 s .  c om*/
 */
protected DataSource getDataSource() throws SSOSessionException {
    if (_datasource == null) {

        synchronized (this) {

            if (_datasource == null) {
                try {
                    if (logger.isDebugEnabled())
                        logger.debug("[getDatasource() : ]" + _dsJndiName);

                    InitialContext ic = new InitialContext();
                    _datasource = (DataSource) ic.lookup(_dsJndiName);

                } catch (NamingException ne) {
                    logger.error("Error during DB connection lookup", ne);
                    throw new SSOSessionException("Error During Lookup\n" + ne.getMessage());
                }
            }
        }

    }

    return _datasource;
}

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

protected PurchaseOrderService lookupPurchaseOrderService() throws NamingException {
    InitialContext initialContext = new InitialContext();
    try {/*w  ww .  j a v  a2s  . c  om*/
        return (PurchaseOrderService) initialContext.lookup("java:comp/env/service/PurchaseOrder");
    } finally {
        initialContext.close();
    }
}

From source file:org.pepstock.jem.jbpm.tasks.utilities.Copy.java

@Override
public int execute(Map<String, Object> parameters) throws Exception {
    // new initial context to access by JNDI to COMMAND DataDescription
    InitialContext ic = ContextUtils.getContext();
    // gets inputstream
    Object input = (Object) ic.lookup(INPUT_DATA_DESCRIPTION_NAME);
    // gets outputstream
    Object output = (Object) ic.lookup(OUTPUT_DATA_DESCRIPTION_NAME);
    // defines the streams
    InputStream istream = null;/*from   w  w  w . j  a v a 2  s.c  o m*/
    OutputStream ostream = null;
    // checks if object is a inputstream otherwise error
    if (input instanceof InputStream) {
        istream = (InputStream) input;
    } else {
        throw new MessageException(JBpmMessage.JEMM017E, INPUT_DATA_DESCRIPTION_NAME,
                input.getClass().getName());
    }
    // checks if object is a outputstream otherwise error
    if (output instanceof OutputStream) {
        ostream = (OutputStream) output;
    } else {
        IOUtils.closeQuietly(istream);
        throw new MessageException(JBpmMessage.JEMM016E, OUTPUT_DATA_DESCRIPTION_NAME,
                output.getClass().getName());
    }
    // copy
    int bytes = IOUtils.copy(istream, ostream);
    IOUtils.closeQuietly(istream);
    IOUtils.closeQuietly(ostream);
    LogAppl.getInstance().emit(JBpmMessage.JEMM062I, bytes);
    // returns OK!!!
    return Result.SUCCESS;
}

From source file:org.jasig.cas.util.AbstractConfigurationFilter.java

protected final String loadFromContext(final InitialContext context, final String path) {
    try {// www .j  a  v a  2  s  .c  o  m
        return (String) context.lookup(path);
    } catch (final NamingException e) {
        return null;
    }
}

From source file:org.pepstock.jem.junit.test.springbatch.java.RestRunnableAndContext.java

@Override
public void run() {
    try {// w w  w  .  j  a  v a  2s  . co  m

        if (stepContribution == null || chunkContext == null) {
            throw new RuntimeException("StepContribution or ChuckContext is null");
        }

        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.pepstock.jem.node.tasks.jndi.JemContextFactory");

        InitialContext context = new InitialContext(env);
        RestClient rest = (RestClient) context.lookup("JUNIT-REST-RESOURCE");
        System.err.println();
        System.err.println("*** REST XML");
        get(rest, MediaType.APPLICATION_XML);
        get(rest, MediaType.APPLICATION_JSON);
        get(rest, MediaType.APPLICATION_XML);
        get(rest, MediaType.APPLICATION_JSON);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    try {
        System.err.println();
        System.err.println("*** REST XML");
        get(restC, MediaType.APPLICATION_XML);
        get(restC, MediaType.APPLICATION_JSON);
        get(restC, MediaType.APPLICATION_XML);
        get(restC, MediaType.APPLICATION_JSON);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

From source file:org.tolven.web.servlet.PortletChartServlet.java

@Override
public void init(ServletConfig config) {
    try {// ww w.  java  2s  .  c  o m
        InitialContext ctx = new InitialContext();
        if (snapshotBean == null) {
            snapshotBean = (SnapshotLocal) ctx.lookup("tolven/SnapshotBean/local");
        }
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.pepstock.jem.junit.test.springbatch.java.RestToBeExecutedAndContextAnnotated.java

/**
 * /*from w w w.j  a  v a2s .c o  m*/
 */
@ToBeExecuted
public void exec() {

    if (stepContribution == null || chunkContext == null) {
        throw new RuntimeException("StepContribution or ChuckContext is null");
    }

    try {
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.pepstock.jem.node.tasks.jndi.JemContextFactory");

        InitialContext context = new InitialContext(env);
        RestClient rest = (RestClient) context.lookup("JUNIT-REST-RESOURCE");
        System.err.println();
        System.err.println("*** REST XML");
        get(rest, MediaType.APPLICATION_XML);
        get(rest, MediaType.APPLICATION_JSON);
        get(rest, MediaType.APPLICATION_XML);
        get(rest, MediaType.APPLICATION_JSON);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    try {
        System.err.println();
        System.err.println("*** REST XML");
        get(restC, MediaType.APPLICATION_XML);
        get(restC, MediaType.APPLICATION_JSON);
        get(restC, MediaType.APPLICATION_XML);
        get(restC, MediaType.APPLICATION_JSON);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

From source file:com.francetelecom.clara.cloud.commons.toggles.PaasJndiStateRepository.java

@Override
public FeatureState getFeatureState(Feature feature) {
    try {//from w w  w. j  a va2  s  . co  m
        InitialContext jndiContext = getInitialContext();
        String value = (String) jndiContext.lookup(feature.name());
        if (!(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false"))) {
            return null;
        }
        boolean enabled = Boolean.valueOf(value);
        List<String> users = getFeatureUsers(feature);
        FeatureState featureState = new FeatureState(feature, enabled, users);
        return featureState;
    } catch (NameNotFoundException e) {
        logger.warn("state of feature " + feature.name() + " is not already defined in jndi");
    } catch (NamingException e) {
        if (ExceptionUtils.indexOfType(e, NameNotFoundException.class) != -1) {
            logger.warn("state of feature " + feature.name() + " is not already defined in jndi");
        } else {
            logger.error("unable to read state of feature " + feature.name(), e);
        }
    } catch (ClassCastException e) {
        logger.error("unable to read state of feature " + feature.name(), e);
    }
    // By default return null (no feature state found or invalid)
    return null;
}