Search in sources :

Example 46 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class JingleSession method setupListeners.

/**
     * Setup the listeners that act on events coming from the lower level negotiators.
     */
public void setupListeners() {
    JingleMediaListener jingleMediaListener = new JingleMediaListener() {

        @Override
        public void mediaClosed(PayloadType cand) {
        }

        @Override
        public void mediaEstablished(PayloadType pt) throws NotConnectedException, InterruptedException {
            if (isFullyEstablished()) {
                Jingle jout = new Jingle(JingleActionEnum.SESSION_ACCEPT);
                // Build up a response packet from each media manager.
                for (ContentNegotiator contentNegotiator : contentNegotiators) {
                    if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED)
                        jout.addContent(contentNegotiator.getJingleContent());
                }
                // Send the "accept" and wait for the ACK
                addExpectedId(jout.getStanzaId());
                sendStanza(jout);
            //triggerSessionEstablished();
            }
        }
    };
    JingleTransportListener jingleTransportListener = new JingleTransportListener() {

        @Override
        public void transportEstablished(TransportCandidate local, TransportCandidate remote) throws NotConnectedException, InterruptedException {
            if (isFullyEstablished()) {
                // CHECKSTYLE:OFF
                // Indicate that this session is active.
                setSessionState(JingleSessionStateActive.getInstance());
                for (ContentNegotiator contentNegotiator : contentNegotiators) {
                    // CHECKSTYLE:ON
                    if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED)
                        contentNegotiator.triggerContentEstablished();
                }
                if (getSessionState().equals(JingleSessionStatePending.getInstance())) {
                    Jingle jout = new Jingle(JingleActionEnum.SESSION_ACCEPT);
                    // Build up a response packet from each media manager.
                    for (ContentNegotiator contentNegotiator : contentNegotiators) {
                        if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED)
                            jout.addContent(contentNegotiator.getJingleContent());
                    }
                    // Send the "accept" and wait for the ACK
                    addExpectedId(jout.getStanzaId());
                    sendStanza(jout);
                }
            }
        }

        @Override
        public void transportClosed(TransportCandidate cand) {
        }

        @Override
        public void transportClosedOnError(XMPPException e) {
        }
    };
    addMediaListener(jingleMediaListener);
    addTransportListener(jingleTransportListener);
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) TransportCandidate(org.jivesoftware.smackx.jingleold.nat.TransportCandidate) JingleMediaListener(org.jivesoftware.smackx.jingleold.listeners.JingleMediaListener) XMPPException(org.jivesoftware.smack.XMPPException) PayloadType(org.jivesoftware.smackx.jingleold.media.PayloadType) JingleTransportListener(org.jivesoftware.smackx.jingleold.listeners.JingleTransportListener)

Example 47 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class JingleSession method startOutgoing.

/**
     * This is the starting point for intitiating a new session.
     * 
     * @throws IllegalStateException
     * @throws SmackException 
     * @throws InterruptedException 
     */
public void startOutgoing() throws IllegalStateException, SmackException, InterruptedException {
    updatePacketListener();
    setSessionState(JingleSessionStatePending.getInstance());
    Jingle jingle = new Jingle(JingleActionEnum.SESSION_INITIATE);
    // Create a content negotiator for each media manager on the session.
    for (JingleMediaManager mediaManager : getMediaManagers()) {
        ContentNegotiator contentNeg = new ContentNegotiator(this, ContentNegotiator.INITIATOR, mediaManager.getName());
        // Create the media negotiator for this content description.
        contentNeg.setMediaNegotiator(new MediaNegotiator(this, mediaManager, mediaManager.getPayloads(), contentNeg));
        JingleTransportManager transportManager = mediaManager.getTransportManager();
        TransportResolver resolver = null;
        try {
            resolver = transportManager.getResolver(this);
        } catch (XMPPException e) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
        if (resolver.getType().equals(TransportResolver.Type.rawupd)) {
            contentNeg.setTransportNegotiator(new TransportNegotiator.RawUdp(this, resolver, contentNeg));
        }
        if (resolver.getType().equals(TransportResolver.Type.ice)) {
            contentNeg.setTransportNegotiator(new TransportNegotiator.Ice(this, resolver, contentNeg));
        }
        addContentNegotiator(contentNeg);
    }
    // Give each of the content negotiators a chance to return a portion of the structure to make the Jingle packet.
    for (ContentNegotiator contentNegotiator : contentNegotiators) {
        jingle.addContent(contentNegotiator.getJingleContent());
    }
    // Save the session-initiate packet ID, so that we can respond to it.
    sessionInitPacketID = jingle.getStanzaId();
    sendStanza(jingle);
    // Now setup to track the media negotiators, so that we know when (if) to send a session-accept.
    setupListeners();
// Give each of the content negotiators a chance to start 
// and return a portion of the structure to make the Jingle packet.
// Don't do this anymore.  The problem is that the other side might not be ready.
// Later when we receive our first jingle packet from the other side we'll fire-up the negotiators
// before processing it.  (See receivePacketAndRespond() above.
//        for (ContentNegotiator contentNegotiator : contentNegotiators) {
//            contentNegotiator.start();
//        }
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) TransportNegotiator(org.jivesoftware.smackx.jingleold.nat.TransportNegotiator) JingleMediaManager(org.jivesoftware.smackx.jingleold.media.JingleMediaManager) TransportResolver(org.jivesoftware.smackx.jingleold.nat.TransportResolver) MediaNegotiator(org.jivesoftware.smackx.jingleold.media.MediaNegotiator) XMPPException(org.jivesoftware.smack.XMPPException) JingleTransportManager(org.jivesoftware.smackx.jingleold.nat.JingleTransportManager)

Example 48 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Openfire by igniterealtime.

the class XMPPPresenceHandler method handlePresenceMode.

/**
	 * Handles incoming presence stanzas that relate to presence status / mode
	 * changes. Ignores others.
	 * 
	 * @param presence
	 *            the stanza
	 */
private void handlePresenceMode(final org.jivesoftware.smack.packet.Presence presence) {
    if (!session.getBuddyManager().isActivated()) {
        session.getBuddyManager().storePendingStatus(session.getTransport().convertIDToJID(presence.getFrom()), ((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
    } else {
        // TODO: Need to handle resources and priorities!
        try {
            final XMPPBuddy xmppBuddy = session.getBuddyManager().getBuddy(session.getTransport().convertIDToJID(presence.getFrom()));
            Log.debug("XMPP: Presence changed detected type " + presence.getType() + " and mode " + presence.getMode() + " for " + presence.getFrom());
            xmppBuddy.setPresenceAndStatus(((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
            if (JiveGlobals.getBooleanProperty("plugin.gateway." + session.getTransport().getType() + ".avatars", true)) {
                PacketExtension pe = presence.getExtension("x", NameSpace.VCARD_TEMP_X_UPDATE);
                if (pe != null) {
                    DefaultPacketExtension dpe = (DefaultPacketExtension) pe;
                    String hash = dpe.getValue("photo");
                    final String from = presence.getFrom();
                    if (hash != null) {
                        Avatar curAvatar = xmppBuddy.getAvatar();
                        if (curAvatar == null || !curAvatar.getLegacyIdentifier().equals(hash)) {
                            new Thread() {

                                @Override
                                public void run() {
                                    VCard vcard = new VCard();
                                    try {
                                        vcard.load(session.conn, from);
                                        xmppBuddy.setAvatar(new Avatar(xmppBuddy.getJID(), from, vcard.getAvatar()));
                                    } catch (XMPPException e) {
                                        Log.debug("XMPP: Failed to load XMPP avatar: ", e);
                                    } catch (IllegalArgumentException e) {
                                        Log.debug("XMPP: Got null avatar, ignoring.");
                                    }
                                }
                            }.start();
                        }
                    }
                }
            }
        } catch (NotFoundException e) {
            Log.debug("XMPP: Received presence notification for contact that's not in the buddy manager of user " + session.getJID() + ". GTalk is known to do this occasionally: " + presence.getFrom());
        // We cannot add this buddy to the buddy manager, as that would result into an auto-accept of the contact sending the data.
        }
    }
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) NotFoundException(org.jivesoftware.util.NotFoundException) XMPPException(org.jivesoftware.smack.XMPPException) VCard(org.jivesoftware.smackx.packet.VCard) Avatar(net.sf.kraken.avatars.Avatar)

Example 49 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class PrivacyTest method testDenyActiveList.

/**
     * Check when a client denies the use of the active list.
     */
public void testDenyActiveList() {
    try {
        PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(getConnection(0));
        PrivacyClient client = new PrivacyClient(privacyManager);
        privacyManager.addListener(client);
        privacyManager.declineActiveList();
        Thread.sleep(500);
        try {
            // The list should not exist and an error will be raised
            privacyManager.getActiveList();
        } catch (XMPPException xmppException) {
            assertEquals(404, xmppException.getXMPPError().getCode());
        }
        assertEquals(null, null);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : XMPPException(org.jivesoftware.smack.XMPPException) PrivacyListManager(org.jivesoftware.smack.PrivacyListManager) XMPPException(org.jivesoftware.smack.XMPPException)

Example 50 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class PrivacyTest method testRemoveList.

/**
     * Check when a client add a new list and then remove it.
     */
public void testRemoveList() {
    try {
        String listName = "testRemoveList";
        PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(getConnection(0));
        PrivacyClient client = new PrivacyClient(privacyManager);
        privacyManager.addListener(client);
        // Add the list that will be set as the Default
        ArrayList<PrivacyItem> items = new ArrayList<PrivacyItem>();
        PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid.name(), true, 1);
        item.setValue(getConnection(0).getUser());
        items.add(item);
        privacyManager.createPrivacyList(listName, items);
        Thread.sleep(500);
        // Set the Default list
        privacyManager.setDefaultListName(listName);
        Thread.sleep(500);
        privacyManager.deletePrivacyList(listName);
        Thread.sleep(500);
        try {
            // The list should not exist and an error will be raised
            privacyManager.getPrivacyList(listName);
        } catch (XMPPException xmppException) {
            assertEquals(404, xmppException.getXMPPError().getCode());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) XMPPException(org.jivesoftware.smack.XMPPException) PrivacyListManager(org.jivesoftware.smack.PrivacyListManager) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

XMPPException (org.jivesoftware.smack.XMPPException)52 ArrayList (java.util.ArrayList)15 JingleSessionRequestListener (org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener)13 JingleMediaManager (org.jivesoftware.smackx.jingle.media.JingleMediaManager)13 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)9 IOException (java.io.IOException)8 SmackException (org.jivesoftware.smack.SmackException)7 PayloadType (org.jivesoftware.smackx.jingle.media.PayloadType)6 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)5 Message (org.jivesoftware.smack.packet.Message)5 FixedResolver (org.jivesoftware.smackx.jingle.nat.FixedResolver)5 FixedTransportManager (org.jivesoftware.smackx.jingle.nat.FixedTransportManager)5 TransportCandidate (org.jivesoftware.smackx.jingle.nat.TransportCandidate)5 TCPConnection (org.jivesoftware.smack.TCPConnection)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)4 Form (org.jivesoftware.smackx.Form)4 JingleSessionListener (org.jivesoftware.smackx.jingle.listeners.JingleSessionListener)4 JmfMediaManager (org.jivesoftware.smackx.jingle.mediaimpl.jmf.JmfMediaManager)4 ICETransportManager (org.jivesoftware.smackx.jingle.nat.ICETransportManager)4 SocketException (java.net.SocketException)3