Search in sources :

Example 1 with SaslAuthenticator

use of org.apache.activemq.transport.amqp.client.sasl.SaslAuthenticator in project activemq-artemis by apache.

the class AmqpConnection method connect.

public void connect() throws Exception {
    if (connected.compareAndSet(false, true)) {
        transport.connect();
        final ClientFuture future = new ClientFuture();
        serializer.execute(new Runnable() {

            @Override
            public void run() {
                if (!noContainerID) {
                    getEndpoint().setContainer(safeGetContainerId());
                }
                getEndpoint().setHostname(remoteURI.getHost());
                if (!getDesiredCapabilities().isEmpty()) {
                    getEndpoint().setDesiredCapabilities(getDesiredCapabilities().toArray(new Symbol[0]));
                }
                if (!getOfferedCapabilities().isEmpty()) {
                    getEndpoint().setOfferedCapabilities(getOfferedCapabilities().toArray(new Symbol[0]));
                }
                if (!getOfferedProperties().isEmpty()) {
                    getEndpoint().setProperties(getOfferedProperties());
                }
                if (getIdleTimeout() > 0) {
                    protonTransport.setIdleTimeout(getIdleTimeout());
                }
                protonTransport.setMaxFrameSize(getMaxFrameSize());
                protonTransport.setChannelMax(getChannelMax());
                protonTransport.bind(getEndpoint());
                Sasl sasl = protonTransport.sasl();
                if (sasl != null) {
                    sasl.client();
                }
                authenticator = new SaslAuthenticator(sasl, username, password, authzid, mechanismRestriction);
                ((TransportImpl) protonTransport).setProtocolTracer(new AmqpProtocolTracer(AmqpConnection.this));
                open(future);
                pumpToProtonTransport(future);
            }
        });
        try {
            if (connectTimeout <= 0) {
                future.sync();
            } else {
                future.sync(connectTimeout, TimeUnit.MILLISECONDS);
                if (getEndpoint().getRemoteState() != EndpointState.ACTIVE) {
                    throw new IOException("Failed to connect after configured timeout.");
                }
            }
        } catch (Throwable e) {
            try {
                close();
            } catch (Throwable ignore) {
            }
            throw e;
        }
    }
}
Also used : Sasl(org.apache.qpid.proton.engine.Sasl) ClientFuture(org.apache.activemq.transport.amqp.client.util.ClientFuture) SaslAuthenticator(org.apache.activemq.transport.amqp.client.sasl.SaslAuthenticator) InactivityIOException(org.apache.activemq.transport.InactivityIOException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InactivityIOException (org.apache.activemq.transport.InactivityIOException)1 SaslAuthenticator (org.apache.activemq.transport.amqp.client.sasl.SaslAuthenticator)1 ClientFuture (org.apache.activemq.transport.amqp.client.util.ClientFuture)1 Sasl (org.apache.qpid.proton.engine.Sasl)1