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;
}
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations