001/** 002 * 003 * Copyright 2022 Florian Schmaus. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smack.full; 018 019import java.io.IOException; 020 021import org.jivesoftware.smack.SmackException; 022import org.jivesoftware.smack.XMPPException; 023import org.jivesoftware.smack.bosh.BOSHConfiguration; 024import org.jivesoftware.smack.bosh.XMPPBOSHConnection; 025import org.jivesoftware.smack.packet.Message; 026 027import org.jxmpp.jid.EntityBareJid; 028import org.jxmpp.jid.impl.JidCreate; 029 030public class BoshConnectionTest { 031 032 public static void main(String[] args) throws XMPPException, SmackException, IOException, InterruptedException { 033 String jidString = args[0]; 034 EntityBareJid jid = JidCreate.entityBareFrom(jidString); 035 String pass = args[1]; 036 037 // SmackConfiguration.DEBUG = true; 038 BOSHConfiguration config = BOSHConfiguration.builder() 039 .setUsernameAndPassword(jid.getLocalpart(), pass) 040 .setXmppDomain(jid.asDomainBareJid()) 041 .useHttps() 042 .setPort(5443) 043 .setFile("/bosh") 044 .build(); 045 XMPPBOSHConnection connection = new XMPPBOSHConnection(config); 046 047 connection.connect().login(); 048 Message message = connection.getStanzaFactory() 049 .buildMessageStanza() 050 .to("flo@geekplace.eu") 051 .setBody("Hi there 2") 052 .build(); 053 connection.sendStanza(message); 054 connection.disconnect(); 055 } 056 057}