001/**
002 *
003 * Copyright 2022 Florian Schmaus.
004 *
005 * This file is part of smack-examples.
006 *
007 * smack-examples is free software; you can redistribute it and/or modify
008 * it under the terms of the GNU General Public License as published by
009 * the Free Software Foundation; either version 3 of the License, or
010 * (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with this program; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
020 */
021package org.igniterealtime.smack.examples;
022
023import java.io.IOException;
024
025import org.jivesoftware.smack.SmackException;
026import org.jivesoftware.smack.XMPPException;
027import org.jivesoftware.smack.bosh.BOSHConfiguration;
028import org.jivesoftware.smack.bosh.XMPPBOSHConnection;
029import org.jivesoftware.smack.packet.Message;
030
031import org.jxmpp.jid.EntityBareJid;
032import org.jxmpp.jid.impl.JidCreate;
033
034public class BoshConnectionTest {
035
036    public static void main(String[] args) throws XMPPException, SmackException, IOException, InterruptedException {
037        String jidString = args[0];
038        EntityBareJid jid = JidCreate.entityBareFrom(jidString);
039        String pass = args[1];
040
041        // SmackConfiguration.DEBUG = true;
042        BOSHConfiguration config = BOSHConfiguration.builder()
043                        .setUsernameAndPassword(jid.getLocalpart(), pass)
044                        .setXmppDomain(jid.asDomainBareJid())
045                        .useHttps()
046                        .setPort(5443)
047                        .setFile("/bosh")
048                        .build();
049        XMPPBOSHConnection connection = new XMPPBOSHConnection(config);
050
051        connection.connect().login();
052        Message message = connection.getStanzaFactory()
053                        .buildMessageStanza()
054                        .to("flo@geekplace.eu")
055                        .setBody("Hi there 2")
056                        .build();
057        connection.sendStanza(message);
058        connection.disconnect();
059    }
060
061}