Search in sources :

Example 16 with XMPPException

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

the class JingleManagerTest method testEqualPayloadsSetSession.

/**
     * This is a simple test where both endpoints have exactly the same payloads
     * and the session is accepted.
     */
public void testEqualPayloadsSetSession() {
    resetCounter();
    try {
        FixedResolver tr0 = new FixedResolver("127.0.0.1", 54213);
        FixedTransportManager ftm0 = new FixedTransportManager(tr0);
        TestMediaManager tmm0 = new TestMediaManager(ftm0);
        tmm0.setPayloads(getTestPayloads1());
        List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
        trl0.add(tmm0);
        FixedResolver tr1 = new FixedResolver("127.0.0.1", 54531);
        FixedTransportManager ftm1 = new FixedTransportManager(tr1);
        TestMediaManager tmm1 = new TestMediaManager(ftm1);
        tmm1.setPayloads(getTestPayloads1());
        List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
        trl1.add(tmm1);
        JingleManager man0 = new JingleManager(getConnection(0), trl0);
        JingleManager man1 = new JingleManager(getConnection(1), trl1);
        man0.addCreationListener(ftm0);
        man1.addCreationListener(ftm1);
        man1.addJingleSessionRequestListener(new JingleSessionRequestListener() {

            /**
                 * Called when a new session request is detected
                 */
            public void sessionRequested(final JingleSessionRequest request) {
                System.out.println("Session request detected, from " + request.getFrom() + ": accepting.");
                try {
                    // We accept the request
                    JingleSession session1 = request.accept();
                    session1.addListener(new JingleSessionListener() {

                        public void sessionClosed(String reason, JingleSession jingleSession) {
                            System.out.println("sessionClosed().");
                        }

                        public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
                            System.out.println("sessionClosedOnError().");
                        }

                        public void sessionDeclined(String reason, JingleSession jingleSession) {
                            System.out.println("sessionDeclined().");
                        }

                        public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) {
                            incCounter();
                            System.out.println("Responder: the session is fully established.");
                            System.out.println("+ Payload Type: " + pt.getId());
                            System.out.println("+ Local IP/port: " + lc.getIp() + ":" + lc.getPort());
                            System.out.println("+ Remote IP/port: " + rc.getIp() + ":" + rc.getPort());
                        }

                        public void sessionMediaReceived(JingleSession jingleSession, String participant) {
                        // Do Nothing
                        }

                        public void sessionRedirected(String redirection, JingleSession jingleSession) {
                        }
                    });
                    session1.startIncoming();
                } catch (Exception e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
            }
        });
        // Session 0 starts a request
        System.out.println("Starting session request with equal payloads, to " + getFullJID(1) + "...");
        JingleSession session0 = man0.createOutgoingJingleSession(getFullJID(1));
        session0.startOutgoing();
        Thread.sleep(20000);
        assertTrue(valCounter() == 1);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
        fail("An error occured with Jingle");
    }
}
Also used : FixedResolver(org.jivesoftware.smackx.jingle.nat.FixedResolver) FixedTransportManager(org.jivesoftware.smackx.jingle.nat.FixedTransportManager) ArrayList(java.util.ArrayList) JingleSessionRequestListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener) PayloadType(org.jivesoftware.smackx.jingle.media.PayloadType) XMPPException(org.jivesoftware.smack.XMPPException) TestMediaManager(org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaManager) JingleMediaManager(org.jivesoftware.smackx.jingle.media.JingleMediaManager) TransportCandidate(org.jivesoftware.smackx.jingle.nat.TransportCandidate) XMPPException(org.jivesoftware.smack.XMPPException) JingleSessionListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionListener)

Example 17 with XMPPException

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

the class JingleManagerTest method testMediaManager.

/**
     * This is a full test in the Jingle API.
     */
public void testMediaManager() {
    resetCounter();
    XMPPTCPConnection x0 = getConnection(0);
    XMPPTCPConnection x1 = getConnection(1);
    FixedResolver tr0 = new FixedResolver("127.0.0.1", 20004);
    FixedTransportManager ftm0 = new FixedTransportManager(tr0);
    FixedResolver tr1 = new FixedResolver("127.0.0.1", 20040);
    FixedTransportManager ftm1 = new FixedTransportManager(tr1);
    try {
        JingleMediaManager jingleMediaManager = new JingleMediaManager(ftm0) {

            // Media Session Implementation
            public JingleMediaSession createMediaSession(final PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local, final JingleSession jingleSession) {
                return new JingleMediaSession(payloadType, remote, local, null, null) {

                    public void initialize() {
                    }

                    public void startTrasmit() {
                        incCounter();
                        System.out.println("Transmit");
                    }

                    public void startReceive() {
                        incCounter();
                        System.out.println("Receive");
                    }

                    public void setTrasmit(boolean active) {
                    }

                    public void stopTrasmit() {
                        incCounter();
                        System.out.println("Stop Transmit");
                    }

                    public void stopReceive() {
                        incCounter();
                        System.out.println("Stop Receive");
                    }
                };
            }

            public List<PayloadType> getPayloads() {
                return getTestPayloads1();
            }

            public PayloadType.Audio getPreferredAudioPayloadType() {
                return (PayloadType.Audio) getTestPayloads1().get(0);
            }
        };
        List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
        trl0.add(jingleMediaManager);
        List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
        trl1.add(jingleMediaManager);
        JingleManager jm0 = new JingleManager(x0, trl0);
        JingleManager jm1 = new JingleManager(x1, trl1);
        jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() {

            public void sessionRequested(final JingleSessionRequest request) {
                try {
                    JingleSession session = request.accept();
                    session.startIncoming();
                } catch (XMPPException e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
            }
        });
        JingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
        js0.startOutgoing();
        Thread.sleep(10000);
        js0.terminate();
        Thread.sleep(3000);
        System.out.println(valCounter());
        assertTrue(valCounter() == 8);
        Thread.sleep(15000);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
}
Also used : FixedResolver(org.jivesoftware.smackx.jingle.nat.FixedResolver) FixedTransportManager(org.jivesoftware.smackx.jingle.nat.FixedTransportManager) ArrayList(java.util.ArrayList) JingleSessionRequestListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener) PayloadType(org.jivesoftware.smackx.jingle.media.PayloadType) XMPPException(org.jivesoftware.smack.XMPPException) JingleMediaSession(org.jivesoftware.smackx.jingle.media.JingleMediaSession) JingleMediaManager(org.jivesoftware.smackx.jingle.media.JingleMediaManager) TransportCandidate(org.jivesoftware.smackx.jingle.nat.TransportCandidate) XMPPException(org.jivesoftware.smack.XMPPException)

Example 18 with XMPPException

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

the class JingleMediaTest method testCompleteJmf.

public void testCompleteJmf() {
    XMPPTCPConnection x0 = getConnection(0);
    XMPPTCPConnection x1 = getConnection(1);
    for (int i = 0; i < 1; i++) try {
        ICETransportManager icetm0 = new ICETransportManager(x0, "jivesoftware.com", 3478);
        ICETransportManager icetm1 = new ICETransportManager(x1, "jivesoftware.com", 3478);
        JingleMediaManager jingleMediaManager0 = new JmfMediaManager(icetm0);
        JingleMediaManager jingleMediaManager1 = new JmfMediaManager(icetm1);
        List<JingleMediaManager> jml0 = new ArrayList<JingleMediaManager>();
        List<JingleMediaManager> jml1 = new ArrayList<JingleMediaManager>();
        jml0.add(jingleMediaManager0);
        jml1.add(jingleMediaManager1);
        final JingleManager jm0 = new JingleManager(x0, jml0);
        final JingleManager jm1 = new JingleManager(x1, jml1);
        jm0.addCreationListener(icetm0);
        jm1.addCreationListener(icetm1);
        JingleSessionRequestListener jingleSessionRequestListener = new JingleSessionRequestListener() {

            public void sessionRequested(final JingleSessionRequest request) {
                try {
                    JingleSession session = request.accept();
                    session.startIncoming();
                //                            session.addStateListener(new JingleSessionStateListener() {
                //                                public void beforeChange(JingleNegotiator.State old, JingleNegotiator.State newOne)
                //                                        throws JingleNegotiator.JingleException {
                //                                    if (newOne instanceof IncomingJingleSession.Active) {
                //                                        throw new JingleNegotiator.JingleException();
                //                                    }
                //                                }
                //
                //                                public void afterChanged(JingleNegotiator.State old, JingleNegotiator.State newOne) {
                //
                //                                }
                //                            });
                } catch (XMPPException e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
            }
        };
        jm1.addJingleSessionRequestListener(jingleSessionRequestListener);
        JingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
        js0.startOutgoing();
        Thread.sleep(20000);
        JingleSession incomingJingleSession = jm1.getSession(js0.getConnection().getUser());
        //JingleSession.removeAllStateListeners();
        Thread.sleep(15000);
        js0.terminate();
        jm1.removeJingleSessionRequestListener(jingleSessionRequestListener);
        Thread.sleep(60000);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
}
Also used : JmfMediaManager(org.jivesoftware.smackx.jingle.mediaimpl.jmf.JmfMediaManager) ICETransportManager(org.jivesoftware.smackx.jingle.nat.ICETransportManager) JingleSessionRequestListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener) XMPPException(org.jivesoftware.smack.XMPPException) JingleMediaManager(org.jivesoftware.smackx.jingle.media.JingleMediaManager) ArrayList(java.util.ArrayList) List(java.util.List) XMPPException(org.jivesoftware.smack.XMPPException)

Example 19 with XMPPException

use of org.jivesoftware.smack.XMPPException in project opennms by OpenNMS.

the class XMPPNotificationManager method sendMessage.

/**
	 * <p>sendMessage</p>
	 *
	 * @param xmppTo a {@link java.lang.String} object.
	 * @param xmppMessage a {@link java.lang.String} object.
	 * @return a boolean.
	 */
public boolean sendMessage(String xmppTo, String xmppMessage) {
    if (!isLoggedIn()) {
        connectToServer();
    }
    try {
        ChatManager cm = ChatManager.getInstanceFor(xmpp);
        cm.createChat(xmppTo, new NullMessageListener()).sendMessage(xmppMessage);
        LOG.debug("XMPP Manager sent message to: {}", xmppTo);
    } catch (XMPPException | NotConnectedException e) {
        LOG.error("XMPP Exception Sending message ", e);
        return false;
    }
    return true;
}
Also used : NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) XMPPException(org.jivesoftware.smack.XMPPException) ChatManager(org.jivesoftware.smack.ChatManager)

Example 20 with XMPPException

use of org.jivesoftware.smack.XMPPException in project opennms by OpenNMS.

the class XMPPNotificationManager method sendGroupChat.

/**
	 * send an xmpp message to a specified Chat Room.
	 *
	 * @param xmppChatRoom
	 *            room to send message to.
	 * @param xmppMessage
	 *            text to be sent in the body of the message
	 * @return true if message is sent, false otherwise
	 */
public boolean sendGroupChat(String xmppChatRoom, String xmppMessage) {
    MultiUserChat groupChat;
    if (rooms.containsKey(xmppChatRoom)) {
        groupChat = rooms.get(xmppChatRoom);
    } else {
        LOG.debug("Adding room: {}", xmppChatRoom);
        groupChat = new MultiUserChat(xmpp, xmppChatRoom);
        rooms.put(xmppChatRoom, groupChat);
    }
    if (!groupChat.isJoined()) {
        LOG.debug("Joining room: {}", xmppChatRoom);
        try {
            groupChat.join(xmppUser);
        } catch (XMPPException | NoResponseException | NotConnectedException e) {
            LOG.error("XMPP Exception joining chat room ", e);
            return false;
        }
    }
    try {
        groupChat.sendMessage(xmppMessage);
        LOG.debug("XMPP Manager sent message to: {}", xmppChatRoom);
    } catch (XMPPException | NotConnectedException e) {
        LOG.error("XMPP Exception sending message to Chat room", e);
        return false;
    }
    return true;
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) 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