Search in sources :

Example 1 with NotConnectedException

use of org.jivesoftware.smack.SmackException.NotConnectedException in project Smack by igniterealtime.

the class Roster method reload.

/**
     * Reloads the entire roster from the server. This is an asynchronous operation,
     * which means the method will return immediately, and the roster will be
     * reloaded at a later point when the server responds to the reload request.
     * @throws NotLoggedInException If not logged in.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public void reload() throws NotLoggedInException, NotConnectedException, InterruptedException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
    RosterPacket packet = new RosterPacket();
    if (rosterStore != null && isRosterVersioningSupported()) {
        packet.setVersion(rosterStore.getRosterVersion());
    }
    rosterState = RosterState.loading;
    connection.sendIqWithResponseCallback(packet, new RosterResultListener(), new ExceptionCallback() {

        @Override
        public void processException(Exception exception) {
            rosterState = RosterState.uninitialized;
            Level logLevel;
            if (exception instanceof NotConnectedException) {
                logLevel = Level.FINE;
            } else {
                logLevel = Level.SEVERE;
            }
            LOGGER.log(logLevel, "Exception reloading roster", exception);
            for (RosterLoadedListener listener : rosterLoadedListeners) {
                listener.onRosterLoadingFailed(exception);
            }
        }
    });
}
Also used : NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) RosterPacket(org.jivesoftware.smack.roster.packet.RosterPacket) Level(java.util.logging.Level) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ExceptionCallback(org.jivesoftware.smack.ExceptionCallback) SmackException(org.jivesoftware.smack.SmackException) FeatureNotSupportedException(org.jivesoftware.smack.SmackException.FeatureNotSupportedException) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException)

Example 2 with NotConnectedException

use of org.jivesoftware.smack.SmackException.NotConnectedException in project Smack by igniterealtime.

the class CloseListener method handleIQRequest.

@Override
public IQ handleIQRequest(IQ iqRequest) {
    Close closeRequest = (Close) iqRequest;
    InBandBytestreamSession ibbSession = this.manager.getSessions().get(closeRequest.getSessionID());
    if (ibbSession == null) {
        try {
            this.manager.replyItemNotFoundPacket(closeRequest);
        } catch (InterruptedException | NotConnectedException e) {
            return null;
        }
    } else {
        try {
            ibbSession.closeByPeer(closeRequest);
        } catch (InterruptedException | NotConnectedException e) {
            return null;
        }
        this.manager.getSessions().remove(closeRequest.getSessionID());
    }
    return null;
}
Also used : NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) Close(org.jivesoftware.smackx.bytestreams.ibb.packet.Close)

Example 3 with NotConnectedException

use of org.jivesoftware.smack.SmackException.NotConnectedException in project Smack by igniterealtime.

the class DataListener method handleIQRequest.

@Override
public IQ handleIQRequest(IQ iqRequest) {
    Data data = (Data) iqRequest;
    InBandBytestreamSession ibbSession = this.manager.getSessions().get(data.getDataPacketExtension().getSessionID());
    try {
        if (ibbSession == null) {
            this.manager.replyItemNotFoundPacket(data);
        } else {
            ibbSession.processIQPacket(data);
        }
    } catch (NotConnectedException | InterruptedException e) {
        return null;
    }
    return null;
}
Also used : NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) Data(org.jivesoftware.smackx.bytestreams.ibb.packet.Data)

Example 4 with NotConnectedException

use of org.jivesoftware.smack.SmackException.NotConnectedException in project Smack by igniterealtime.

the class TransportNegotiator method delayedCheckBestCandidate.

/**
     * Launch a thread that checks, after some time, if any of the candidates
     * offered by the other endpoint is usable. The thread does not check the
     * candidates: it just checks if we have got a valid one and sends an Accept
     * in that case.
     */
private void delayedCheckBestCandidate(final JingleSession js, final Jingle jin) {
    //
    if (resultThread == null && !getRemoteCandidates().isEmpty()) {
        resultThread = new Thread(new Runnable() {

            @Override
            public void run() {
                // Sleep for some time, waiting for the candidates checks
                int totalTime = (CANDIDATES_ACCEPT_PERIOD + TransportResolver.CHECK_TIMEOUT);
                int tries = (int) Math.ceil(totalTime / 1000);
                for (int i = 0; i < tries - 1; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        LOGGER.log(Level.WARNING, "exception", e);
                    }
                    // Once we are in pending state, look for any valid remote
                    // candidate, and send an "accept" if we have one...
                    TransportCandidate bestRemote = getBestRemoteCandidate();
                    if ((bestRemote != null) && ((getNegotiatorState() == JingleNegotiatorState.PENDING))) {
                        // Accepting the remote candidate
                        if (!acceptedRemoteCandidates.contains(bestRemote)) {
                            Jingle jout = new Jingle(JingleActionEnum.CONTENT_ACCEPT);
                            JingleContent content = parentNegotiator.getJingleContent();
                            content.addJingleTransport(getJingleTransport(bestRemote));
                            jout.addContent(content);
                            // Send the packet
                            try {
                                js.sendFormattedJingle(jin, jout);
                            } catch (InterruptedException | NotConnectedException e) {
                                throw new IllegalStateException(e);
                            }
                            acceptedRemoteCandidates.add(bestRemote);
                        }
                        if ((isEstablished()) && (getNegotiatorState() == JingleNegotiatorState.PENDING)) {
                            setNegotiatorState(JingleNegotiatorState.SUCCEEDED);
                            try {
                                triggerTransportEstablished(getAcceptedLocalCandidate(), bestRemote);
                            } catch (InterruptedException | NotConnectedException e) {
                                throw new IllegalStateException(e);
                            }
                            break;
                        }
                    }
                }
                // Once we are in pending state, look for any valid remote
                // candidate, and send an "accept" if we have one...
                TransportCandidate bestRemote = getBestRemoteCandidate();
                if (bestRemote == null) {
                    boolean foundRemoteRelay = false;
                    for (TransportCandidate candidate : remoteCandidates) {
                        if (candidate instanceof ICECandidate) {
                            ICECandidate iceCandidate = (ICECandidate) candidate;
                            if (iceCandidate.getType().equals(Type.relay)) {
                                //TODO Check if the relay is reacheable
                                addValidRemoteCandidate(iceCandidate);
                                foundRemoteRelay = true;
                            }
                        }
                    }
                    // We should accept the Public One if we received it, otherwise, accepts any.
                    if (!foundRemoteRelay) {
                        boolean foundLocalRelay = false;
                        for (TransportCandidate candidate : offeredCandidates) {
                            if (candidate instanceof ICECandidate) {
                                ICECandidate iceCandidate = (ICECandidate) candidate;
                                if (iceCandidate.getType().equals(Type.relay)) {
                                    foundLocalRelay = true;
                                }
                            }
                        }
                        if (foundLocalRelay) {
                            boolean foundRemotePublic = false;
                            for (TransportCandidate candidate : remoteCandidates) {
                                if (candidate instanceof ICECandidate) {
                                    ICECandidate iceCandidate = (ICECandidate) candidate;
                                    if (iceCandidate.getType().equals(ICECandidate.Type.srflx)) {
                                        addValidRemoteCandidate(iceCandidate);
                                        foundRemotePublic = true;
                                    }
                                }
                            }
                            if (!foundRemotePublic) {
                                for (TransportCandidate candidate : remoteCandidates) {
                                    if (candidate instanceof ICECandidate) {
                                        ICECandidate iceCandidate = (ICECandidate) candidate;
                                        addValidRemoteCandidate(iceCandidate);
                                    }
                                }
                            }
                        }
                    }
                }
                for (int i = 0; i < 6; i++) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        LOGGER.log(Level.WARNING, "exception", e);
                    }
                    bestRemote = getBestRemoteCandidate();
                    //State state = getState();
                    if ((bestRemote != null) && ((getNegotiatorState() == JingleNegotiatorState.PENDING))) {
                        if (!acceptedRemoteCandidates.contains(bestRemote)) {
                            Jingle jout = new Jingle(JingleActionEnum.CONTENT_ACCEPT);
                            JingleContent content = parentNegotiator.getJingleContent();
                            content.addJingleTransport(getJingleTransport(bestRemote));
                            jout.addContent(content);
                            // Send the packet
                            try {
                                js.sendFormattedJingle(jin, jout);
                            } catch (InterruptedException | NotConnectedException e) {
                                throw new IllegalStateException(e);
                            }
                            acceptedRemoteCandidates.add(bestRemote);
                        }
                        if (isEstablished()) {
                            setNegotiatorState(JingleNegotiatorState.SUCCEEDED);
                            break;
                        }
                    }
                }
                if (getNegotiatorState() != JingleNegotiatorState.SUCCEEDED) {
                    try {
                        session.terminate("Unable to negotiate session. This may be caused by firewall configuration problems.");
                    } catch (Exception e) {
                        LOGGER.log(Level.WARNING, "exception", e);
                    }
                }
            }
        }, "Waiting for all the transport candidates checks...");
        resultThread.setName("Transport Resolver Result");
        resultThread.start();
    }
}
Also used : NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) SmackException(org.jivesoftware.smack.SmackException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) JingleException(org.jivesoftware.smackx.jingleold.JingleException) XMPPException(org.jivesoftware.smack.XMPPException) Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) JingleTransportCandidate(org.jivesoftware.smackx.jingleold.packet.JingleTransport.JingleTransportCandidate) JingleContent(org.jivesoftware.smackx.jingleold.packet.JingleContent)

Example 5 with NotConnectedException

use of org.jivesoftware.smack.SmackException.NotConnectedException in project Smack by igniterealtime.

the class BasicResolver method resolve.

/**
     * Resolve the IP address.
     * <p/>
     * The BasicResolver takes the IP addresses of the interfaces and uses the
     * first non-loopback, non-linklocal and non-sitelocal address.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
@Override
public synchronized void resolve(JingleSession session) throws XMPPException, NotConnectedException, InterruptedException {
    setResolveInit();
    clearCandidates();
    Enumeration<NetworkInterface> ifaces = null;
    try {
        ifaces = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
    while (ifaces.hasMoreElements()) {
        NetworkInterface iface = ifaces.nextElement();
        Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
        while (iaddresses.hasMoreElements()) {
            InetAddress iaddress = iaddresses.nextElement();
            if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress() && !iaddress.isSiteLocalAddress()) {
                TransportCandidate tr = new TransportCandidate.Fixed(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName(), getFreePort());
                tr.setLocalIp(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName());
                addCandidate(tr);
                setResolveEnd();
                return;
            }
        }
    }
    try {
        ifaces = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
    while (ifaces.hasMoreElements()) {
        NetworkInterface iface = ifaces.nextElement();
        Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
        while (iaddresses.hasMoreElements()) {
            InetAddress iaddress = iaddresses.nextElement();
            if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress()) {
                TransportCandidate tr = new TransportCandidate.Fixed(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName(), getFreePort());
                tr.setLocalIp(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName());
                addCandidate(tr);
                setResolveEnd();
                return;
            }
        }
    }
    try {
        TransportCandidate tr = new TransportCandidate.Fixed(InetAddress.getLocalHost().getHostAddress() != null ? InetAddress.getLocalHost().getHostAddress() : InetAddress.getLocalHost().getHostName(), getFreePort());
        tr.setLocalIp(InetAddress.getLocalHost().getHostAddress() != null ? InetAddress.getLocalHost().getHostAddress() : InetAddress.getLocalHost().getHostName());
        addCandidate(tr);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
    setResolveEnd();
}
Also used : SocketException(java.net.SocketException) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress) SocketException(java.net.SocketException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)22 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)11 XMPPException (org.jivesoftware.smack.XMPPException)11 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)9 SmackException (org.jivesoftware.smack.SmackException)6 IOException (java.io.IOException)5 XMPPConnection (org.jivesoftware.smack.XMPPConnection)5 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)3 KeyManagementException (java.security.KeyManagementException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 LinkedList (java.util.LinkedList)2 ChatManager (org.jivesoftware.smack.ChatManager)2 AlreadyConnectedException (org.jivesoftware.smack.SmackException.AlreadyConnectedException)2 AlreadyLoggedInException (org.jivesoftware.smack.SmackException.AlreadyLoggedInException)2 StreamErrorException (org.jivesoftware.smack.XMPPException.StreamErrorException)2 AndFilter (org.jivesoftware.smack.filter.AndFilter)2 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)2 NotAMucServiceException (org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException)2 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)2 InetAddress (java.net.InetAddress)1