Example usage for javax.naming NoInitialContextException getMessage

List of usage examples for javax.naming NoInitialContextException getMessage

Introduction

In this page you can find the example usage for javax.naming NoInitialContextException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.settings4j.connector.JNDIConnector.java

/**
 * check if a JNDI context is available and sets the internal Flag setIsJNDIAvailable(Boolean).
 * <p>/*from ww w  .ja v a2 s . com*/
 * If the internal Flag IsJNDIAvailable is <code>False</code> this Connector is disabled.
 * </p>
 *
 * @return true if a JNDI Context could be initialized.
 */
public boolean isJNDIAvailable() {
    if (this.isJNDIAvailable == null) {
        try {
            getJNDIContext().lookup(getContextPathPrefix());
            LOG.debug("JNDI Context is available.");
            this.isJNDIAvailable = Boolean.TRUE;
        } catch (final NoInitialContextException e) {
            LOG.info("No JNDI Context available! JNDIConnector will be disabled: {}", e.getMessage());
            this.isJNDIAvailable = Boolean.FALSE;
        } catch (final NamingException e) {
            logInfoButExceptionDebug(String.format("JNDI Context is available but %s", e.getMessage()), e);
            this.isJNDIAvailable = Boolean.TRUE;
        }
    }

    return this.isJNDIAvailable.booleanValue();
}

From source file:org.settings4j.connector.JNDIConnector.java

private Object lookupInContext(final String key, final boolean withPrefix) {
    if (!isJNDIAvailable()) {
        return null;
    }/*from  www. j  av a 2 s  .c  o m*/
    final String normalizedKey = normalizeKey(key, withPrefix);
    InitialContext ctx = null;
    Object result = null;
    try {
        ctx = getJNDIContext();
        result = ctx.lookup(normalizedKey);
    } catch (final NoInitialContextException e) {
        logInfoButExceptionDebug(String.format("Maybe no JNDI-Context available. %s", e.getMessage()), e);
    } catch (final NamingException e) {
        LOG.debug("cannot lookup key: {} ({})", key, normalizedKey, e);
        if (withPrefix) {
            result = lookupInContext(key, false);
        }
    } finally {
        closeQuietly(ctx);
    }
    return result;
}

From source file:org.settings4j.connector.JNDIConnector.java

/**
 * @param key the JNDI-Key (will NOT be normalized).
 * @param value the JNDI-Value.//w ww  .  j  a v a  2s . com
 * @return Constants.SETTING_NOT_POSSIBLE if the JNDI Context ist readonly.
 */
public int rebindToContext(final String key, final Object value) {
    // don't do a check, but use the result if a check was done.
    if (BooleanUtils.isFalse(this.isJNDIAvailable)) {
        // only if isJNDIAvailable() was called an evaluated to false.
        return Constants.SETTING_NOT_POSSIBLE;
    }

    LOG.debug("Try to rebind Key '{}' with value: {}", key, value);

    InitialContext ctx = null;
    int result = Constants.SETTING_NOT_POSSIBLE;
    try {
        ctx = getJNDIContext();
        createParentContext(ctx, key);
        ctx.rebind(key, value);
        result = Constants.SETTING_SUCCESS;
    } catch (final NoInitialContextException e) {
        logInfoButExceptionDebug(String.format("Maybe no JNDI-Context available. %s", e.getMessage()), e);
    } catch (final NamingException e) {
        // the JNDI-Context from TOMCAT is readonly
        // if you try to write it, The following Exception will be thrown:
        // javax.naming.NamingException: Context is read only
        logInfoButExceptionDebug(String.format("cannot bind key: '%s'. %s", key, e.getMessage()), e);
    } finally {
        closeQuietly(ctx);
    }
    return result;
}