Search in sources :

Example 16 with ECFException

use of org.eclipse.ecf.core.util.ECFException in project ecf by eclipse.

the class HttpClient method connect.

public Object connect(ID remote, Object data, int timeout) throws ECFException {
    try {
        trace("connect(" + remote + "," + data + "," + timeout + ")");
        if (socket != null) {
            throw new ECFException("Already connected to " + getURL(null));
        }
        final URL url = new URL(remote.getName());
        /*
			 * // Get socket factory and create/connect socket SocketFactory fact =
			 * SocketFactory.getSocketFactory(); if(fact == null) { fact =
			 * SocketFactory.getDefaultSocketFactory(); }
			 */
        final int port = url.getPort() != -1 ? url.getPort() : DEFAULT_PORT;
        // socket = fact.createSocket(url.getHost(), port, timeout);
        socket = new Socket(url.getHost(), port);
    } catch (final IOException e) {
        throw new ECFException(e);
    }
    return null;
}
Also used : ECFException(org.eclipse.ecf.core.util.ECFException) IOException(java.io.IOException) URL(java.net.URL) Socket(java.net.Socket)

Example 17 with ECFException

use of org.eclipse.ecf.core.util.ECFException in project ecf by eclipse.

the class XMPPUserSearchManager method search.

/**
 * Specific implementation for XMPP
 *
 * @see IUserSearchManager#search(ICriteria).
 */
public ISearch search(ICriteria criteria) throws UserSearchException {
    ResultList resultList = new ResultList();
    try {
        // initialize the form by chance it is null
        if (form == null)
            form = manager.getSearchForm(ecfConnection.getXMPPConnection(), SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
        /*
			 * For XMPP criterion is considered. The XMPP server will deal with
			 * the search.
			 */
        List criterions = criteria.getCriterions();
        // add the fields for the search dynamically
        // consider just the fields used on the search
        // fields checked by user
        String[] fields = getUserPropertiesFields();
        for (int i = 0; i < fields.length; i++) {
            Iterator criterionsIterator = criterions.iterator();
            // the partial result is added to the result list
            while (criterionsIterator.hasNext()) {
                ICriterion criterion = (ICriterion) criterionsIterator.next();
                if (criterion.equals(fields[i])) {
                    Form answerForm = form.createAnswerForm();
                    answerForm.setAnswer(fields[i], true);
                    answerForm.setAnswer(SEARCH_ACTION, criterion.toExpression());
                    ReportedData data = manager.sendSearchForm(ecfConnection.getXMPPConnection(), answerForm, SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
                    // create a result list from ReportedData
                    IResultList partialResultList = createResultList(data);
                    resultList.addAll(partialResultList.getResults());
                }
            }
        }
        return new XMPPSearch(resultList);
    } catch (final XMPPException e) {
        String message = null;
        if (e.getXMPPError() != null && e.getXMPPError().getCode() == 404) {
            message = Messages.XMPPContainer_UNRECOGONIZED_SEARCH_SERVICE;
        } else {
            message = e.getLocalizedMessage();
        }
        throw new UserSearchException(message, e, criteria);
    } catch (ECFException e) {
        throw new UserSearchException(e, criteria);
    }
}
Also used : IResultList(org.eclipse.ecf.presence.search.IResultList) ResultList(org.eclipse.ecf.presence.search.ResultList) Form(org.jivesoftware.smackx.Form) IResultList(org.eclipse.ecf.presence.search.IResultList) ECFException(org.eclipse.ecf.core.util.ECFException) Iterator(java.util.Iterator) IResultList(org.eclipse.ecf.presence.search.IResultList) List(java.util.List) ResultList(org.eclipse.ecf.presence.search.ResultList) XMPPException(org.jivesoftware.smack.XMPPException) ICriterion(org.eclipse.ecf.presence.search.ICriterion) UserSearchException(org.eclipse.ecf.presence.search.UserSearchException) ReportedData(org.jivesoftware.smackx.ReportedData)

Example 18 with ECFException

use of org.eclipse.ecf.core.util.ECFException 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 19 with ECFException

use of org.eclipse.ecf.core.util.ECFException in project ecf by eclipse.

the class SSLClient method connect.

public synchronized Object connect(ID remote, Object data, int timeout) throws ECFException {
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    debug("connect(" + remote + "," + data + "," + timeout + ")");
    if (socket != null)
        // $NON-NLS-1$
        throw new ECFException("Already connected");
    // parse URI
    URI anURI = null;
    try {
        anURI = new URI(remote.getName());
    } catch (final URISyntaxException e) {
        // $NON-NLS-1$
        throw new ECFException("Invalid URI for remoteID=" + remote, e);
    }
    ConnectResultMessage res = null;
    try {
        final Socket s = createSocket(anURI.getHost(), anURI.getPort(), timeout);
        // Set socket options
        setSocketOptions(s);
        // Now we've got a connection so set our socket
        setSocket(s);
        outputStream = new ObjectOutputStream(s.getOutputStream());
        outputStream.flush();
        inputStream = ProviderPlugin.getDefault().createObjectInputStream(s.getInputStream());
        // $NON-NLS-1$
        debug("connect;" + anURI);
        // send connect data and get synchronous response
        send(new ConnectRequestMessage(anURI, (Serializable) data));
        res = (ConnectResultMessage) readObject();
    } catch (final Exception e) {
        // $NON-NLS-1$
        throw new ECFException("Exception during connection to " + remote.getName(), e);
    }
    // $NON-NLS-1$
    debug("connect;rcv:" + res);
    // Setup threads
    setupThreads();
    // Return results.
    final Object ret = res.getData();
    // $NON-NLS-1$
    debug("connect;returning:" + ret);
    return ret;
}
Also used : ECFException(org.eclipse.ecf.core.util.ECFException) ECFException(org.eclipse.ecf.core.util.ECFException)

Example 20 with ECFException

use of org.eclipse.ecf.core.util.ECFException 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

ECFException (org.eclipse.ecf.core.util.ECFException)42 IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)9 Iterator (java.util.Iterator)5 IStatus (org.eclipse.core.runtime.IStatus)5 ID (org.eclipse.ecf.core.identity.ID)5 Status (org.eclipse.core.runtime.Status)4 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)4 IOException (java.io.IOException)3 IContainer (org.eclipse.ecf.core.IContainer)3 Action (org.eclipse.jface.action.Action)3 IAction (org.eclipse.jface.action.IAction)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 TimeoutException (java.util.concurrent.TimeoutException)2 Namespace (org.eclipse.ecf.core.identity.Namespace)2 IConnectContext (org.eclipse.ecf.core.security.IConnectContext)2 IUser (org.eclipse.ecf.core.user.IUser)2 IChatRoomInfo (org.eclipse.ecf.presence.chatroom.IChatRoomInfo)2 IEcho (org.eclipse.ecf.tests.remoteservice.rpc.common.IEcho)2