Example usage for javax.naming NoInitialContextException getCause

List of usage examples for javax.naming NoInitialContextException getCause

Introduction

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

Prototype

public Throwable getCause() 

Source Link

Document

Returns the cause of this exception.

Usage

From source file:org.mc4j.ems.impl.jmx.connection.support.providers.JBossConnectionProvider.java

private InitialContext getInitialContext() throws NamingException {
    Properties props = this.connectionSettings.getAdvancedProperties();
    if (!NAMING_CONTEXT_FACTORY_CLASS_NAME.equals(this.connectionSettings.getInitialContextName())) {
        log.warn("Unsupported initial context factory [" + this.connectionSettings.getInitialContextName()
                + "] - only " + NAMING_CONTEXT_FACTORY_CLASS_NAME
                + " is supported for JBoss connections; using that instead...");
    }//  w w w  . j a va  2 s.  co m
    props.put(Context.INITIAL_CONTEXT_FACTORY, NAMING_CONTEXT_FACTORY_CLASS_NAME);
    props.put(Context.PROVIDER_URL, this.connectionSettings.getServerUrl());

    try {
        InitialContext context = new InitialContext(props);
        return context;
    } catch (NoInitialContextException e) {
        // Try to be more helpful, indicating the reason we couldn't make the connection in this
        // common case of missing libraries.
        if (e.getCause() instanceof ClassNotFoundException) {
            throw new ConnectionException(
                    "Necessary classes not found for remote connection, check installation path configuration.",
                    e.getCause());
        }
        throw e;
    }
}