Package org.jivesoftware.smack

Examples of org.jivesoftware.smack.XMPPConnection


        if (room.indexOf('@', 0) != -1) {
            return room;
        }

        XMPPConnection conn = getConnection();
        Iterator<String> iterator = MultiUserChat.getServiceNames(conn).iterator();
        if (!iterator.hasNext()) {
            throw new CamelException("Can not find Multi User Chat service");
        }
        String chatServer = iterator.next();
View Full Code Here


    public void start() throws Exception {
        super.start();
        if (connection == null) {
            if (port > 0) {
                connection = new XMPPConnection(host, port);
            } else {
                connection = new XMPPConnection(host);
            }
        }
        getConnection().addPacketListener(this, filter);
        if (login && !connection.isAuthenticated()) {
            if (user != null) {
View Full Code Here

            connectionConfiguration.setExpiredCertificatesCheckEnabled(false);
            connectionConfiguration.setDebuggerEnabled(true);
            connectionConfiguration.setSASLAuthenticationEnabled(true);
            connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
            XMPPConnection.DEBUG_ENABLED = true;
            XMPPConnection connection = new XMPPConnection(connectionConfiguration);
            connection.connect();

            SASLAuthentication saslAuthentication = connection.getSASLAuthentication();
            //            saslAuthentication.authenticateAnonymously();
            //            saslAuthentication.authenticate("user1@vysper.org", "password1", "test");

            //            if (!saslAuthentication.isAuthenticated()) return;

            connection.login(me + "@vysper.org", "password1");

            connection.getRoster().setSubscriptionMode(Roster.SubscriptionMode.accept_all);

            connection.addPacketListener(new IQListener(), new PacketFilter() {
                public boolean accept(Packet packet) {
                    return packet instanceof IQ;
                }
            });

            connection.addPacketListener(new PresenceListener(), new PacketFilter() {
                public boolean accept(Packet packet) {
                    return packet instanceof Presence;
                }
            });

            Chat chat = null;
            if (to != null) {
                Presence presence = new Presence(Presence.Type.subscribe);
                presence.setFrom(connection.getUser());
                String toEntity = to + "@vysper.org";
                presence.setTo(toEntity);
                connection.sendPacket(presence);

                chat = connection.getChatManager().createChat(toEntity, new MessageListener() {
                    public void processMessage(Chat inchat, Message message) {
                        System.out.println("log received message: " + message.getBody());
                    }
                });
            }

            connection.sendPacket(new Presence(Presence.Type.available, "pommes", 1, Presence.Mode.available));

            Thread.sleep(1000);

            // query server version
            sendIQGetWithTimestamp(connection, new Version());

            // query server time
            sendIQGetWithTimestamp(connection, new Time());

            /*            while (to != null) {
            //                chat.sendMessage("Hello " + to + " at " + new Date());
                            try { Thread.sleep((new Random().nextInt(15)+1)*1000 ); } catch (InterruptedException e) { ; }
                        }*/

            for (int i = 0; i < 10; i++) {
                connection.sendPacket(new Presence(Presence.Type.available, "pommes", 1, Presence.Mode.available));
                try {
                    Thread.sleep((new Random().nextInt(15) + 10) * 1000);
                } catch (InterruptedException e) {
                    ;
                }
                connection.sendPacket(new Presence(Presence.Type.available, "nickes", 1, Presence.Mode.away));
                try {
                    Thread.sleep((new Random().nextInt(15) + 10) * 1000);
                } catch (InterruptedException e) {
                    ;
                }
            }

            for (int i = 0; i < 2000; i++) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    ;
                }
            }

            connection.disconnect();
        } catch (Throwable e) {
            try {
                Thread.sleep(120 * 1000);
            } catch (InterruptedException ie) {
                ;
View Full Code Here

        connectionConfiguration.setKeystorePath("src/main/config/bogus_mina_tls.cert");
        connectionConfiguration.setTruststorePath("src/main/config/bogus_mina_tls.cert");
        connectionConfiguration.setTruststorePassword("boguspw");

        XMPPConnection.DEBUG_ENABLED = true;
        XMPPConnection client = new XMPPConnection(connectionConfiguration);

        client.connect();

        client.login(username, password);
        return client;
    }
View Full Code Here

        connectionConfiguration.setKeystorePath("src/main/config/bogus_mina_tls.cert");
        connectionConfiguration.setTruststorePath("src/main/config/bogus_mina_tls.cert");
        connectionConfiguration.setTruststorePassword("boguspw");

        XMPPConnection.DEBUG_ENABLED = true;
        XMPPConnection client = new XMPPConnection(connectionConfiguration);

        client.connect();

        client.login(username, password);
        return client;
    }
View Full Code Here

        pubsubMgr = new PubSubManager(connection, "pubsub.vysper.org");
        return true;
    }

    private XMPPConnection connect(String username, String password, String host) throws XMPPException {
        XMPPConnection connection = new XMPPConnection(host);
        connection.connect();
        connection.login(username, password);
        return connection;
    }
View Full Code Here

        ConnectionConfiguration configuration = createConnectionConfiguration(host, port, serviceName);
        Assert.notNull(configuration, "'configuration' must not be null");
        Assert.hasText(username, "'username' must not be empty");
        Assert.hasText(password, "'password' must not be empty");

        connection = new XMPPConnection(configuration);
        connection.connect();
        if (StringUtils.hasText(resource)) {
            connection.login(username, password, resource);
        }
        else {
View Full Code Here

        // config.setDebuggerEnabled(true);

        try {
            // SmackConfiguration.setPacketReplyTimeout(1000);
            // XMPPConnection con = new XMPPConnection(config);
            XMPPConnection con = new XMPPConnection("localhost", 61222);
            con.login("amq-user", "amq-pwd");
            Chat chat = con.createChat("test@localhost");
            for (int i = 0; i < 10; i++) {
                System.out.println("Sending message: " + i);
                chat.sendMessage("Hello from Message: " + i);
            }
            System.out.println("Sent all messages!");
View Full Code Here

      if (s != null && !"".equals(s)) {
        this.toUsers.add(s);
      }
    }
        ConnectionConfiguration conf = new ConnectionConfiguration(server, port , service);
        XMPPConnection connection = null;
        try {

           if(server !=null && !server.equals("") && port != 0){
             connection = new XMPPConnection(conf);
           } else {
             connection = new XMPPConnection(service);
           }

           connection.connect();
           System.out.println("Connected to " + connection.getHost());

        } catch (XMPPException ex) {
            Logger.getLogger(JabberWorkItemHandler.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("Failed to connect to " + connection.getHost());
            System.exit(1);

        }

        try{
            connection.login(user, password);
            System.out.println("Logged in as " + connection.getUser());
            Presence presence = new Presence(Presence.Type.available);
            connection.sendPacket(presence);

        } catch (XMPPException ex){
            Logger.getLogger(JabberWorkItemHandler.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("Failed to log in as " + connection.getUser());
            System.exit(1);

        }

        for(String toUser : toUsers){

            ChatManager chatmanager = connection.getChatManager();
            Chat chat = chatmanager.createChat(toUser, null);

            try {
                // google bounces back the default message types, you must use chat
                Message msg = new Message(toUser, Message.Type.chat);
                msg.setBody(text);
                chat.sendMessage(msg);
                System.out.println("Message Sended");
            } catch (XMPPException e) {
                System.out.println("Failed to send message");
                // handle this how?
            }
        }


        connection.disconnect();

        manager.completeWorkItem(workItem.getId(), null);

        
    }
View Full Code Here

    public void start() throws JBIException {
        try {
            if (connection == null) {
                if (port > 0) {
                    connection = new XMPPConnection(host, port);
                }
                else {
                    connection = new XMPPConnection(host);
                }
            }
            if (login && !connection.isAuthenticated()) {
                if (user != null) {
                    AccountManager accountManager = new AccountManager(connection);
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.XMPPConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.