Search in sources :

Example 31 with NameAlreadyBoundException

use of javax.naming.NameAlreadyBoundException in project tomcat by apache.

the class NamingContextListener method createNamingContext.

/**
 * Create and initialize the JNDI naming context.
 */
private void createNamingContext() throws NamingException {
    // Creating the comp subcontext
    if (container instanceof Server) {
        compCtx = namingContext;
        envCtx = namingContext;
    } else {
        compCtx = namingContext.createSubcontext("comp");
        envCtx = compCtx.createSubcontext("env");
    }
    int i;
    if (log.isDebugEnabled()) {
        log.debug("Creating JNDI naming context");
    }
    if (namingResources == null) {
        namingResources = new NamingResourcesImpl();
        namingResources.setContainer(container);
    }
    // Resource links
    ContextResourceLink[] resourceLinks = namingResources.findResourceLinks();
    for (i = 0; i < resourceLinks.length; i++) {
        addResourceLink(resourceLinks[i]);
    }
    // Resources
    ContextResource[] resources = namingResources.findResources();
    for (i = 0; i < resources.length; i++) {
        addResource(resources[i]);
    }
    // Resources Env
    ContextResourceEnvRef[] resourceEnvRefs = namingResources.findResourceEnvRefs();
    for (i = 0; i < resourceEnvRefs.length; i++) {
        addResourceEnvRef(resourceEnvRefs[i]);
    }
    // Environment entries
    ContextEnvironment[] contextEnvironments = namingResources.findEnvironments();
    for (i = 0; i < contextEnvironments.length; i++) {
        addEnvironment(contextEnvironments[i]);
    }
    // EJB references
    ContextEjb[] ejbs = namingResources.findEjbs();
    for (i = 0; i < ejbs.length; i++) {
        addEjb(ejbs[i]);
    }
    // Message Destination References
    MessageDestinationRef[] mdrs = namingResources.findMessageDestinationRefs();
    for (i = 0; i < mdrs.length; i++) {
        addMessageDestinationRef(mdrs[i]);
    }
    // WebServices references
    ContextService[] services = namingResources.findServices();
    for (i = 0; i < services.length; i++) {
        addService(services[i]);
    }
    // Binding a User Transaction reference
    if (container instanceof Context) {
        try {
            Reference ref = new TransactionRef();
            compCtx.bind("UserTransaction", ref);
            ContextTransaction transaction = namingResources.getTransaction();
            if (transaction != null) {
                Iterator<String> params = transaction.listProperties();
                while (params.hasNext()) {
                    String paramName = params.next();
                    String paramValue = (String) transaction.getProperty(paramName);
                    StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
                    ref.add(refAddr);
                }
            }
        } catch (NameAlreadyBoundException e) {
        // Ignore because UserTransaction was obviously
        // added via ResourceLink
        } catch (NamingException e) {
            log.error(sm.getString("naming.bindFailed", e));
        }
    }
    // Binding the resources directory context
    if (container instanceof Context) {
        try {
            compCtx.bind("Resources", ((Context) container).getResources());
        } catch (NamingException e) {
            log.error(sm.getString("naming.bindFailed", e));
        }
    }
}
Also used : ContextService(org.apache.tomcat.util.descriptor.web.ContextService) Server(org.apache.catalina.Server) MessageDestinationRef(org.apache.tomcat.util.descriptor.web.MessageDestinationRef) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NamingException(javax.naming.NamingException) ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) NamingContext(org.apache.naming.NamingContext) Context(org.apache.catalina.Context) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) Reference(javax.naming.Reference) ContextTransaction(org.apache.tomcat.util.descriptor.web.ContextTransaction) ContextEjb(org.apache.tomcat.util.descriptor.web.ContextEjb) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource) StringRefAddr(javax.naming.StringRefAddr) TransactionRef(org.apache.naming.TransactionRef) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ContextResourceEnvRef(org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)

Example 32 with NameAlreadyBoundException

use of javax.naming.NameAlreadyBoundException in project databus by linkedin.

the class JmxShutdownThread method doStart.

protected void doStart() {
    _controlLock.lock();
    try {
        // Bind and start to accept incoming connections.
        int portNum = getContainerStaticConfig().getHttpPort();
        _tcpChannelGroup = new DefaultChannelGroup();
        _httpChannelGroup = new DefaultChannelGroup();
        _httpServerChannel = _httpBootstrap.bind(new InetSocketAddress(portNum));
        InetSocketAddress actualAddress = (InetSocketAddress) _httpServerChannel.getLocalAddress();
        _containerPort = actualAddress.getPort();
        // persist the port number (file name should be unique for the container)
        File portNumFile = new File(getHttpPortFileName());
        portNumFile.deleteOnExit();
        try {
            FileWriter portNumFileW = new FileWriter(portNumFile);
            portNumFileW.write(Integer.toString(_containerPort));
            portNumFileW.close();
            LOG.info("Saving port number in " + portNumFile.getAbsolutePath());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        _httpChannelGroup.add(_httpServerChannel);
        LOG.info("Serving container " + getContainerStaticConfig().getId() + " HTTP listener on port " + _containerPort);
        if (_containerStaticConfig.getTcp().isEnabled()) {
            int tcpPortNum = _containerStaticConfig.getTcp().getPort();
            _tcpServerChannel = _tcpBootstrap.bind(new InetSocketAddress(tcpPortNum));
            _tcpChannelGroup.add(_tcpServerChannel);
            LOG.info("Serving container " + getContainerStaticConfig().getId() + " TCP listener on port " + tcpPortNum);
        }
        _nettyShutdownThread = new NettyShutdownThread();
        Runtime.getRuntime().addShutdownHook(_nettyShutdownThread);
        // Start the producer thread after 5 seconds
        if (null != _jmxConnServer && _containerStaticConfig.getJmx().isRmiEnabled()) {
            try {
                _jmxShutdownThread = new JmxShutdownThread(_jmxConnServer);
                Runtime.getRuntime().addShutdownHook(_jmxShutdownThread);
                _jmxConnServer.start();
                LOG.info("JMX server listening on port " + _containerStaticConfig.getJmx().getJmxServicePort());
            } catch (IOException ioe) {
                if (ioe.getCause() != null && ioe.getCause() instanceof NameAlreadyBoundException) {
                    LOG.warn("Unable to bind JMX server connector. Likely cause is that the previous instance was not cleanly shutdown: killed in Eclipse?");
                    if (_jmxConnServer.isActive()) {
                        LOG.warn("JMX server connector seems to be running anyway. ");
                    } else {
                        LOG.warn("Unable to determine if JMX server connector is running");
                    }
                } else {
                    LOG.error("Unable to start JMX server connector", ioe);
                }
            }
        }
        _globalStatsThread.start();
    } catch (RuntimeException ex) {
        LOG.error("Got runtime exception :" + ex, ex);
        throw ex;
    } finally {
        _controlLock.unlock();
    }
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) InetSocketAddress(java.net.InetSocketAddress) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Example 33 with NameAlreadyBoundException

use of javax.naming.NameAlreadyBoundException in project midpoint by Evolveum.

the class ConnIdUtil method lookForKnownCause.

private static Exception lookForKnownCause(Throwable ex, OperationResult parentResult) {
    if (ex.getClass().getPackage().equals(SchemaException.class.getPackage())) {
        // Common midPoint exceptions, pass through
        // Those may get here from the inner calls of handle() methods from the connector.
        parentResult.recordFatalError(ex.getMessage(), ex);
        return (Exception) ex;
    }
    if (ex instanceof FileNotFoundException) {
        // fix MID-2711 consider FileNotFoundException as CommunicationException
        Exception newEx = new com.evolveum.midpoint.util.exception.CommunicationException(createMessageFromAllExceptions(null, ex));
        parentResult.recordFatalError("File not found: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof NameAlreadyBoundException) {
        // This is thrown by LDAP connector and may be also throw by similar
        // connectors
        Exception newEx = new ObjectAlreadyExistsException(createMessageFromAllExceptions(null, ex));
        parentResult.recordFatalError("Object already exists: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof javax.naming.CommunicationException) {
        // This is thrown by LDAP connector and may be also throw by similar
        // connectors
        Exception newEx = new CommunicationException(createMessageFromAllExceptions("Communication error", ex));
        parentResult.recordFatalError("Communication error: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof ServiceUnavailableException) {
        // In some cases (e.g. JDK 1.6.0_31) this is thrown by LDAP connector and may be also throw by similar
        // connectors
        Exception newEx = new CommunicationException(createMessageFromAllExceptions("Communication error", ex));
        parentResult.recordFatalError("Communication error: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof SchemaViolationException) {
        // This is thrown by LDAP connector and may be also throw by similar
        // connectors
        Exception newEx = new SchemaException(createMessageFromAllExceptions("Schema violation", ex));
        parentResult.recordFatalError("Schema violation: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof javax.naming.directory.InvalidAttributeValueException) {
        // This is thrown by LDAP connector and may be also throw by similar
        // connectors
        javax.naming.directory.InvalidAttributeValueException e = (javax.naming.directory.InvalidAttributeValueException) ex;
        Exception newEx;
        if (e.getExplanation().contains("unique attribute conflict")) {
            newEx = new ObjectAlreadyExistsException(createMessageFromAllExceptions("Invalid attribute", ex));
        } else {
            newEx = new SchemaException(createMessageFromAllExceptions("Invalid attribute", ex));
        }
        parentResult.recordFatalError("Invalid attribute: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof ConnectException) {
        // Buried deep in many exceptions, usually connection refused or
        // similar errors
        // Note: needs to be after javax.naming.CommunicationException as the
        // javax.naming exception has more info (e.g. hostname)
        Exception newEx = new CommunicationException(createMessageFromAllExceptions("Connect error", ex));
        parentResult.recordFatalError("Connect error: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof SQLSyntaxErrorException) {
        // Buried deep in many exceptions, usually DB schema problems of
        // DB-based connectors
        Exception newEx = new SchemaException(createMessageFromAllExceptions("DB syntax error", ex));
        parentResult.recordFatalError("DB syntax error: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof SQLException) {
        // Buried deep in many exceptions, usually DB connection problems
        Exception newEx = new GenericFrameworkException(createMessageFromAllExceptions("DB error", ex));
        parentResult.recordFatalError("DB error: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof NoPermissionException) {
        Exception newEx = new SecurityViolationException(createMessageFromAllExceptions(null, ex));
        parentResult.recordFatalError("Object not found: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof AttributeInUseException) {
        Exception newEx = new SchemaException(createMessageFromAllExceptions(null, ex));
        parentResult.recordFatalError("Attribute in use: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof NoSuchAttributeException) {
        Exception newEx = new SchemaException(createMessageFromAllExceptions(null, ex));
        parentResult.recordFatalError("No such attribute: " + ex.getMessage(), newEx);
        return newEx;
    } else if (ex instanceof ConnectorException && !ex.getClass().equals(ConnectorException.class)) {
        // we have non generic connector exception
        Exception newEx = processConnectorException((ConnectorException) ex, parentResult);
        if (newEx != null) {
            return newEx;
        }
    }
    if (ex.getCause() == null) {
        // found nothing
        return null;
    } else {
        // Otherwise go one level deeper ...
        return lookForKnownCause(ex.getCause(), parentResult);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) SQLException(java.sql.SQLException) FileNotFoundException(java.io.FileNotFoundException) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AttributeInUseException(javax.naming.directory.AttributeInUseException) NoSuchAttributeException(javax.naming.directory.NoSuchAttributeException) RemoteWrappedException(org.identityconnectors.framework.impl.api.remote.RemoteWrappedException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) FileNotFoundException(java.io.FileNotFoundException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) SystemException(com.evolveum.midpoint.util.exception.SystemException) SchemaViolationException(javax.naming.directory.SchemaViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) NoPermissionException(javax.naming.NoPermissionException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) SQLException(java.sql.SQLException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ConnectException(java.net.ConnectException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NoSuchAttributeException(javax.naming.directory.NoSuchAttributeException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NoPermissionException(javax.naming.NoPermissionException) SchemaViolationException(javax.naming.directory.SchemaViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) ConnectException(java.net.ConnectException) AttributeInUseException(javax.naming.directory.AttributeInUseException)

Aggregations

NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)33 InitialContext (javax.naming.InitialContext)17 Context (javax.naming.Context)16 NamingException (javax.naming.NamingException)15 NameNotFoundException (javax.naming.NameNotFoundException)12 Reference (javax.naming.Reference)8 File (java.io.File)6 OperationNotSupportedException (javax.naming.OperationNotSupportedException)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 BeanContext (org.apache.openejb.BeanContext)5 InvalidNameException (javax.naming.InvalidNameException)4 LinkRef (javax.naming.LinkRef)4 Name (javax.naming.Name)4 AppContext (org.apache.openejb.AppContext)4 Properties (java.util.Properties)3 CreationalContext (javax.enterprise.context.spi.CreationalContext)3 Referenceable (javax.naming.Referenceable)3 DataSource (javax.sql.DataSource)3 InvalidObjectException (java.io.InvalidObjectException)2