Search in sources :

Example 6 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class IMBot method connect.

public synchronized void connect() throws ECFException {
    fireInitBot();
    try {
        Namespace namespace = null;
        if (container == null) {
            container = ContainerFactory.getDefault().createContainer(bot.getContainerFactoryName());
            namespace = container.getConnectNamespace();
        } else
            throw new ContainerConnectException("Already connected");
        targetID = IDFactory.getDefault().createID(namespace, bot.getConnectID());
        firePreConnect();
        IPresenceContainerAdapter presenceAdapter = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
        presenceAdapter.getChatManager().addMessageListener(this);
        String password = bot.getPassword();
        IConnectContext context = (password == null) ? null : ConnectContextFactory.createPasswordConnectContext(password);
        container.connect(targetID, context);
    } catch (ECFException e) {
        if (container != null) {
            if (container.getConnectedID() != null) {
                container.disconnect();
            }
            container.dispose();
        }
        container = null;
        throw e;
    }
}
Also used : IPresenceContainerAdapter(org.eclipse.ecf.presence.IPresenceContainerAdapter) IConnectContext(org.eclipse.ecf.core.security.IConnectContext) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ECFException(org.eclipse.ecf.core.util.ECFException) Namespace(org.eclipse.ecf.core.identity.Namespace)

Example 7 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class ZooDiscoveryContainer method connect.

public void connect(ID id, IConnectContext connectContext) throws ContainerConnectException {
    if (isDisposed)
        throw new ContainerConnectException("Container already disposed!");
    if (this.isConnected)
        throw new ContainerConnectException("Container already connected!");
    this.targetId = id;
    if (this.targetId == null) {
        this.targetId = this.getConnectNamespace().createInstance(new String[] { DefaultDiscoveryConfig.getDefaultTarget() });
    }
    init(this.targetId);
    isConnected = true;
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException)

Example 8 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class ECFConnection method connect.

public synchronized Object connect(ID remote, Object data, int timeout) throws ECFException {
    if (connection != null)
        throw new ECFException("already connected");
    if (timeout > 0)
        SmackConfiguration.setPacketReplyTimeout(timeout);
    Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
    final XMPPID jabberURI = getXMPPID(remote);
    String username = jabberURI.getNodename();
    String hostname = jabberURI.getHostname();
    String hostnameOverride = null;
    // Check for the URI form of "joe@bloggs.org;talk.google.com", which
    // would at this point would have
    // - username = "joe"
    // - hostname = "blogs.org;talk.google.com"
    // - hostnameOverride = null
    // 
    // We need to turn this into:
    // - username = "joe"
    // - hostname = "bloggs.org"
    // - hostnameOverride = "talk.google.com"
    int semiColonIdx = hostname.lastIndexOf(';');
    if (semiColonIdx != -1) {
        hostnameOverride = hostname.substring(semiColonIdx + 1);
        hostname = hostname.substring(0, semiColonIdx);
    }
    if (google && hostnameOverride == null) {
        hostnameOverride = GOOGLE_TALK_HOST;
    }
    final String serviceName = hostname;
    serverPort = jabberURI.getPort();
    serverResource = jabberURI.getResourceName();
    if (serverResource == null || serverResource.equals(XMPPID.PATH_DELIMITER)) {
        serverResource = getClientIdentifier();
        jabberURI.setResourceName(serverResource);
    }
    try {
        ConnectionConfiguration config;
        if (hostnameOverride != null) {
            config = new ConnectionConfiguration(hostnameOverride, XMPP_DEFAULT_PORT, serviceName);
        } else if (serverPort == -1) {
            config = new ConnectionConfiguration(serviceName);
        } else {
            config = new ConnectionConfiguration(serviceName, serverPort);
        }
        config.setSendPresence(true);
        // authentication; handler should provide keystore password:
        if (callbackHandler instanceof javax.security.auth.callback.CallbackHandler) {
            config.setCallbackHandler((javax.security.auth.callback.CallbackHandler) callbackHandler);
        }
        connection = new XMPPConnection(config);
        connection.connect();
        SASLAuthentication.supportSASLMechanism("PLAIN", 0);
        if (google || GOOGLE_TALK_HOST.equals(hostnameOverride)) {
            username = username + "@" + serviceName;
        }
        connection.addPacketListener(packetListener, null);
        connection.addConnectionListener(connectionListener);
        // Login
        connection.login(username, (String) data, serverResource);
        waitForBindResult();
    } catch (final XMPPException e) {
        throw new ContainerConnectException("Login attempt failed", e);
    }
    return jid;
}
Also used : CallbackHandler(org.eclipse.ecf.core.security.CallbackHandler) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ECFException(org.eclipse.ecf.core.util.ECFException) ConnectionConfiguration(org.jivesoftware.smack.ConnectionConfiguration) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) XMPPException(org.jivesoftware.smack.XMPPException) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID)

Example 9 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class XMPPContainer method connect.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.provider.generic.ClientSOContainer#connect(org.eclipse
	 * .ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
	 */
public void connect(ID remote, IConnectContext joinContext) throws ContainerConnectException {
    try {
        getSharedObjectManager().addSharedObject(presenceHelperID, presenceHelper, null);
        super.connect(remote, joinContext);
        XmppPlugin.getDefault().registerService(this);
    } catch (final ContainerConnectException e) {
        disconnect();
        throw e;
    } catch (final SharedObjectAddException e1) {
        disconnect();
        throw new ContainerConnectException(NLS.bind(Messages.XMPPContainer_EXCEPTION_ADDING_SHARED_OBJECT, presenceHelperID), e1);
    }
}
Also used : SharedObjectAddException(org.eclipse.ecf.core.sharedobject.SharedObjectAddException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException)

Example 10 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class ClientSOContainer method connect.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.provider.generic.SOContainer#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
	 */
public void connect(ID targetID, IConnectContext joinContext) throws ContainerConnectException {
    try {
        if (isClosing)
            // $NON-NLS-1$
            throw new IllegalStateException("Container closing");
        if (targetID == null)
            // $NON-NLS-1$
            throw new ContainerConnectException("targetID cannot be null");
        Object response = null;
        synchronized (getConnectLock()) {
            // Throw if already connected
            if (isConnected())
                // $NON-NLS-1$
                throw new IllegalStateException("Container already connected connectedID=" + getConnectedID());
            // Throw if connecting
            if (isConnecting())
                // $NON-NLS-1$
                throw new IllegalStateException("Container connecting");
            // else we're entering connecting state
            // first notify synchonously
            final ISynchAsynchConnection aConnection = createConnection(targetID, joinContext);
            setStateConnecting(aConnection);
            fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID, joinContext));
            final Object connectData = getConnectData(targetID, joinContext);
            final int connectTimeout = getConnectTimeout();
            synchronized (aConnection) {
                try {
                    // Make connect call
                    response = aConnection.connect(targetID, connectData, connectTimeout);
                } catch (final ECFException e) {
                    if (getConnection() != aConnection)
                        disconnect(aConnection);
                    else
                        setStateDisconnected(aConnection);
                    throw e;
                }
                // If not in correct state, disconnect and return
                if (getConnection() != aConnection) {
                    disconnect(aConnection);
                    // $NON-NLS-1$
                    throw new IllegalStateException("Container connect failed because not in correct state");
                }
                ID serverID = null;
                try {
                    serverID = handleConnectResponse(targetID, response);
                } catch (final Exception e) {
                    setStateDisconnected(aConnection);
                    throw e;
                }
                setStateConnected(serverID, aConnection);
                // notify listeners
                fireContainerEvent(new ContainerConnectedEvent(this.getID(), remoteServerID));
                aConnection.start();
            }
        }
    } catch (final ContainerConnectException e) {
        throw e;
    } catch (final ECFException e) {
        final IStatus s = e.getStatus();
        throw new ContainerConnectException(s.getMessage(), s.getException());
    } catch (final Exception e) {
        throw new ContainerConnectException(e.getLocalizedMessage(), e);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ECFException(org.eclipse.ecf.core.util.ECFException) ID(org.eclipse.ecf.core.identity.ID) ECFException(org.eclipse.ecf.core.util.ECFException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ConnectException(java.net.ConnectException)

Aggregations

ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)26 ECFException (org.eclipse.ecf.core.util.ECFException)8 ContainerConnectedEvent (org.eclipse.ecf.core.events.ContainerConnectedEvent)6 ContainerConnectingEvent (org.eclipse.ecf.core.events.ContainerConnectingEvent)6 ID (org.eclipse.ecf.core.identity.ID)6 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)5 Namespace (org.eclipse.ecf.core.identity.Namespace)5 IContainer (org.eclipse.ecf.core.IContainer)4 CallbackHandler (org.eclipse.ecf.core.security.CallbackHandler)3 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 BBException (org.eclipse.ecf.bulletinboard.BBException)2 IBBCredentials (org.eclipse.ecf.bulletinboard.IBBCredentials)2 Callback (org.eclipse.ecf.core.security.Callback)2 IConnectContext (org.eclipse.ecf.core.security.IConnectContext)2 NameCallback (org.eclipse.ecf.core.security.NameCallback)2 ObjectCallback (org.eclipse.ecf.core.security.ObjectCallback)2 SharedObjectAddException (org.eclipse.ecf.core.sharedobject.SharedObjectAddException)2 XMPPRoomID (org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID)2 ConnectException (java.net.ConnectException)1