Example usage for javax.naming NamingException toString

List of usage examples for javax.naming NamingException toString

Introduction

In this page you can find the example usage for javax.naming NamingException toString.

Prototype

public String toString() 

Source Link

Document

Generates the string representation of this exception.

Usage

From source file:org.mobicents.slee.service.interop.InteropSbb.java

/**
 * implements javax.slee.Sbb Please refer to JSLEE v1.1 Specification, Early
 * Draft Review Page 54 for further information. <br>
 * The SLEE invokes this method after a new instance of the SBB abstract
 * class is created. During this method, an SBB entity has not been assigned
 * to the SBB object. The SBB object can take advantage of this method to
 * allocate and initialize state or connect to resources that are to be held
 * by the SBB object during its lifetime. Such state and resources cannot be
 * specific to an SBB entity because the SBB object might be reused during
 * its lifetime to serve multiple SBB entities. <br>
 * This method indicates a transition from state "DOES NOT EXIST" to
 * "POOLED" (see page 52)/* w  w  w  .  ja va2 s.co m*/
 */
public void setSbbContext(SbbContext sbbContext) {
    this.sbbContext = sbbContext;
    try {
        Context ctx = (Context) new InitialContext().lookup("java:comp/env");

        audioFilePath = System.getProperty("jboss.server.data.dir") + "/JavaOne2008.wav";

        msProvider = (MsProvider) ctx.lookup("slee/resources/media/1.0/provider");

        mediaAcif = (MediaRaActivityContextInterfaceFactory) ctx.lookup("slee/resources/media/1.0/acifactory");

        ttsActivityContextInterfaceFactory = (TTSActivityContextInterfaceFactory) ctx
                .lookup("slee/resources/ttsRA/0.1/acifactory");

        ttsProvider = (TTSProvider) ctx.lookup("slee/resources/ttsRA/0.1/provider");

    } catch (NamingException ne) {
        logger.error("Could not set SBB context: " + ne.toString(), ne);
    }
}

From source file:org.openadaptor.auxil.connector.jndi.JNDIReadConnector.java

/**
 * Establish an external JNDI connection.
 * <p/>//ww  w. j  ava  2  s  .c o  m
 * If already connected, do nothing.
 *
 * @throws ConnectionException if an AuthenticationException or NamingException occurs
 */
public void connect() {
    try {
        _ctxt = jndiConnection.connect();
    } catch (AuthenticationException ae) {
        log.warn("Failed JNDI authentication for principal: " + jndiConnection.getSecurityPrincipal());
        throw new ConnectionException("Failed to Authenticate JNDI connection - " + ae.toString(), ae, this);
    } catch (NamingException ne) {
        log.warn(ne.getMessage());
        throw new ConnectionException("Failed to establish JNDI connection - " + ne.toString(), ne, this);
    }
    log.info(getId() + " connected");
}

From source file:org.openiam.idm.srvc.auth.spi.AbstractLoginModule.java

public LdapContext connect(String userName, String password, ManagedSysDto managedSys) throws NamingException {

    if (keystore != null && !keystore.isEmpty()) {
        System.setProperty("javax.net.ssl.trustStore", keystore);
        System.setProperty("javax.net.ssl.keyStorePassword", keystorePasswd);
    }/*w ww .  j  av a2 s  .  co m*/

    if (managedSys == null) {
        log.debug("ManagedSys is null");
        return null;
    }

    String hostUrl = managedSys.getHostUrl();
    if (managedSys.getPort() > 0) {
        hostUrl = hostUrl + ":" + String.valueOf(managedSys.getPort());
    }

    log.debug("connect: Connecting to target system: " + managedSys.getId());
    log.debug("connect: Managed System object : " + managedSys);

    log.info(" directory login = " + managedSys.getUserId());
    log.info(" directory login passwrd= *****");
    log.info(" javax.net.ssl.trustStore= " + System.getProperty("javax.net.ssl.trustStore"));
    log.info(" javax.net.ssl.keyStorePassword= " + System.getProperty("javax.net.ssl.keyStorePassword"));

    Hashtable<String, String> envDC = new Hashtable();
    envDC.put(Context.PROVIDER_URL, hostUrl);
    envDC.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    envDC.put(Context.SECURITY_AUTHENTICATION, "simple"); // simple
    envDC.put(Context.SECURITY_PRINCIPAL, userName);
    envDC.put(Context.SECURITY_CREDENTIALS, password);

    // Connections Pool configuration
    envDC.put("com.sun.jndi.ldap.connect.pool", "true");
    // Here is an example of a command line that sets the maximum pool size to 20, the preferred pool size to 10, and the idle timeout to 5 minutes for pooled connections.
    envDC.put("com.sun.jndi.ldap.connect.pool.prefsize", "10");
    envDC.put("com.sun.jndi.ldap.connect.pool.maxsize", "20");
    envDC.put("com.sun.jndi.ldap.connect.pool.timeout", "300000");

    LdapContext ldapContext = null;
    try {
        ldapContext = (LdapContext) new LdapCtxFactory().getInitialContext((Hashtable) envDC);

    } catch (CommunicationException ce) {
        log.error("Throw communication exception.", ce);

    } catch (NamingException ne) {
        log.error(ne.toString(), ne);

    } catch (Throwable e) {
        log.error(e.toString(), e);
    }

    return ldapContext;
}

From source file:org.openiam.spml2.spi.ldap.LdapConnectorImpl.java

public ResponseType testConnection(ManagedSys managedSys) {
    ResponseType response = new ResponseType();
    response.setStatus(StatusCodeType.SUCCESS);

    ConnectionMgr conMgr = ConnectionFactory.create(ConnectionManagerConstant.LDAP_CONNECTION);

    try {//from  w  w w . j a  va2 s  .c o m

        LdapContext ldapctx = conMgr.connect(managedSys);
    } catch (NamingException ne) {
        log.error(ne);
        // return a response object - even if it fails so that it can be logged.
        response.setStatus(StatusCodeType.FAILURE);
        response.setError(ErrorCode.DIRECTORY_ERROR);
        response.addErrorMessage(ne.toString());

    } finally {
        /* close the connection to the directory */
        try {
            if (conMgr != null) {
                conMgr.close();
            }
        } catch (NamingException n) {
            log.error(n);
        }

    }

    return response;
}

From source file:org.openiam.spml2.spi.ldap.LdapConnectorImpl.java

public ResponseType setPassword(SetPasswordRequestType reqType) {
    log.debug("setPassword request called..");

    ConnectionMgr conMgr = null;/*from   w  ww .  jav a2 s .com*/

    String requestID = reqType.getRequestID();
    /* PSO - Provisioning Service Object -
       *     -  ID must uniquely specify an object on the target or in the target's namespace
       *     -  Try to make the PSO ID immutable so that there is consistency across changes. */
    PSOIdentifierType psoID = reqType.getPsoID();
    /* targetID -  */
    String targetID = psoID.getTargetID();
    /* ContainerID - May specify the container in which this object should be created
       *      ie. ou=Development, org=Example */
    PSOIdentifierType containerID = psoID.getContainerID();

    /* A) Use the targetID to look up the connection information under managed systems */
    ManagedSys managedSys = managedSysService.getManagedSys(targetID);

    try {
        log.debug("managedSys found for targetID=" + targetID + " " + " Name=" + managedSys.getName());
        conMgr = ConnectionFactory.create(ConnectionManagerConstant.LDAP_CONNECTION);
        LdapContext ldapctx = conMgr.connect(managedSys);

        log.debug("Ldapcontext = " + ldapctx);

        String ldapName = psoID.getID();

        ModificationItem[] mods = new ModificationItem[1];
        mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
                new BasicAttribute("userPassword", reqType.getPassword()));
        ldapctx.modifyAttributes(ldapName, mods);

        // check if the request contains additional attributes
        List<ExtensibleObject> extObjList = reqType.getAny();
        if (extObjList != null && extObjList.size() > 0) {
            ExtensibleObject obj = extObjList.get(0);
            if (obj != null) {
                List<ExtensibleAttribute> attrList = obj.getAttributes();
                if (attrList != null && attrList.size() > 0) {
                    mods = new ModificationItem[attrList.size()];
                    for (ExtensibleAttribute a : attrList) {
                        mods[0] = new ModificationItem(a.getOperation(),
                                new BasicAttribute(a.getName(), a.getValue()));
                    }
                    ldapctx.modifyAttributes(ldapName, mods);
                }
            }
        }

    } catch (NamingException ne) {
        log.error(ne.getMessage(), ne);

        ResponseType resp = new ResponseType();
        resp.setStatus(StatusCodeType.FAILURE);
        resp.setError(ErrorCode.NO_SUCH_IDENTIFIER);
        return resp;
    } catch (Exception ne) {
        log.error(ne.getMessage(), ne);

        ResponseType resp = new ResponseType();
        resp.setStatus(StatusCodeType.FAILURE);
        resp.setError(ErrorCode.OTHER_ERROR);
        resp.addErrorMessage(ne.toString());
        return resp;

    } finally {
        /* close the connection to the directory */
        try {
            if (conMgr != null) {
                conMgr.close();
            }

        } catch (NamingException n) {
            log.error(n);
        }

    }

    ResponseType respType = new ResponseType();
    respType.setStatus(StatusCodeType.SUCCESS);
    return respType;

}

From source file:org.zanata.util.CleanDocumentStorageRule.java

public static String getDocumentStoragePath() {
    if (storagePath == null) {
        final Properties env = new Properties();

        // env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                org.jboss.naming.remote.client.InitialContextFactory.class.getName());
        long portOffset = Integer.parseInt(PropertiesHolder.getProperty("cargo.port.offset", "0"));
        String rmiPort = System.getenv("JBOSS_REMOTING_PORT");
        int rmiPortNum = rmiPort != null ? parseInt(rmiPort) : 4547;
        long realRmiPort = portOffset + rmiPortNum;
        String remoteUrl = "remote://localhost:" + realRmiPort;
        env.put(Context.PROVIDER_URL, remoteUrl);
        InitialContext remoteContext = null;
        try {// ww w .  j  av a  2  s.  c  o  m
            remoteContext = new InitialContext(env);
            storagePath = (String) remoteContext.lookup("zanata/files/document-storage-directory");
        } catch (NamingException e) {
            // wildfly uses 'http-remoting:' not 'remote:'
            String httpPort = System.getenv("JBOSS_HTTP_PORT");
            int httpPortNum = httpPort != null ? parseInt(httpPort) : 8180;
            long realHttpPort = httpPortNum + portOffset;
            String httpRemotingUrl = "http-remoting://localhost:" + realHttpPort;
            log.warn("Unable to access {}: {}; trying {}", remoteUrl, e.toString(), httpRemotingUrl);
            try {
                env.put(Context.PROVIDER_URL, httpRemotingUrl);
                remoteContext = new InitialContext(env);
                storagePath = (String) remoteContext.lookup("zanata/files/document-storage-directory");
            } catch (NamingException e1) {
                // fall back option:
                log.warn("Unable to access {}: {}", httpRemotingUrl, e.toString());
                URL testClassRoot = Thread.currentThread().getContextClassLoader()
                        .getResource("setup.properties");
                File targetDir = new File(testClassRoot.getPath()).getParentFile();
                storagePath = new File(targetDir, "zanata-documents").getAbsolutePath();
            }
        }
    }
    return storagePath;
}

From source file:uk.co.modularaudio.util.pooling.sql.JNDIConnectionFactory.java

/**
 * <P>/* w w  w.j  ava2s  . c  o m*/
 * Initialise the factory by attempting to get the classes required for the
 * driver.
 * </P>
 *
 * @exception FactoryProductionException
 */
@Override
public void init() throws FactoryProductionException {
    try {
        final InitialContext ic = new InitialContext();
        ds = (DataSource) ic.lookup(icString);

        // Test creating a connection
        final Connection c = ds.getConnection();
        c.close();
    } catch (final NamingException ne) {
        throw new FactoryProductionException(ne.toString());
    } catch (final SQLException sqle) {
        throw new FactoryProductionException(sqle.toString());
    }
}