XMPP Server Test

本文介绍了一个使用Java实现的XMPP客户端测试程序,该程序能够与主流XMPP服务器如tigase和Openfire建立连接,并进行注册及登录操作。程序通过线程并发方式模拟多个用户连接。
XMPP的Client
可以和tigase server .openfire 等主流XMPP服务器连接,
需要用到smack 包




/**
* TestXMPPClient
* @author Charles
* @email chs.garea@gmail.com
*
* */

package com.gareatech.testxmpp;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Registration;

/**
* @param arg[0] XMPP Server
* @param arg[1] Thread Number
* @param arg[2] Debug Mode 1,
* TestXMPPClient 192.168.10.106 10 1
* */
public class TestXMPPClient {
public static void main(String[] arg) throws InterruptedException {
boolean Debug = false;
String XMPPserver = "192.168.10.106";
int number = 0;

switch (arg.length)
{
case 2:
XMPPserver = arg[0];
number = Integer.parseInt(arg[1]);
break;
case 3:
XMPPserver = arg[0];
number = Integer.parseInt(arg[1]);
if(arg[2].equals("1"))
Debug = true;
break;
default:
System.out.println("Wrong Paramenters");
return;
}

System.out.println("server:"+XMPPserver+"\nnumber:"+number+"\nDebug:"+Debug);

for( int i = 0; i<number; i++)
{

new MitiSay(i+"",XMPPserver,Debug).start();
Thread.sleep(1000);
}

}
}

/**
* 线程
*
* */

class MitiSay extends Thread {

private String XMPPServer;

private boolean DebugFlag ;

public MitiSay(String threadName) {
super(threadName);
this.XMPPServer = "192.168.10.106";
this.DebugFlag = false;
}

public MitiSay(String threadName,String XMPPserver) {
super(threadName);
this.XMPPServer = XMPPserver;
this.DebugFlag = false;
}

public MitiSay(String threadName,String XMPPserver,boolean DebugFlag) {
super(threadName);
this.XMPPServer = XMPPserver;
this.DebugFlag = DebugFlag;
}
public void run() {
System.out.println("线程"+getName() + " 开始!");

XMPPConnection.DEBUG_ENABLED = DebugFlag;
ConnectionConfiguration connectionConfig = new ConnectionConfiguration("192.168.10.106", 5222, "pc-201012031249");

connectionConfig.setSecurityMode(SecurityMode.required);
connectionConfig.setSASLAuthenticationEnabled(false);
connectionConfig.setCompressionEnabled(false);
//connectionConfig.setSelfSignedCertificateEnabled(true);

try {

/** Connection **/
XMPPConnection connection = new XMPPConnection(connectionConfig);
PacketFilter packetFilter = new AndFilter();
PacketListener packetListener = new PacketListener() {
@Override
public void processPacket(Packet packet) {
// TODO Auto-generated method stub
System.out.println("Thread"+getName()+"Get Message:"+packet.toXML());

if (packet instanceof IQ) {
IQ response = (IQ) packet;
if (response.getType() == IQ.Type.ERROR) {
if (!response.getError().toString().contains("409")) {

}
} else if (response.getType() == IQ.Type.RESULT) {

}
}
}
};

connection.addPacketListener(packetListener, packetFilter);
connection.connect();


System.out.println("connect! Next-> Register!");

/** Registration **/
final String newUsername = newRandomUUID();
final String newPassword = newRandomUUID();

Registration registration = new Registration();

registration.setType(IQ.Type.SET);
registration.setTo(XMPPServer);

Map paramenter = new HashMap();
paramenter.put("username", newUsername);
paramenter.put("password", newPassword);
paramenter.put("name", "new");
paramenter.put("email", "mail@mail.com");

registration.setAttributes(paramenter);

connection.sendPacket(registration);

System.out.println("registration! Next -> Login");


/** login **/
//connection.login("admin", "tigase");
connection.login(newUsername, newPassword);
System.out.println("Logged!!"+newUsername+"\n"+newPassword);

while (true)
{
Thread.sleep(500000000);
}


} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


System.out.println(getName() + " 线程运行结束!");
}

/**
*
* newRandomUUID: 获取一随机数
*/
private static String newRandomUUID() {
String uuidRaw = UUID.randomUUID().toString();
return uuidRaw.replaceAll("-", "");
}
}

[root@yfw ~]# cd /opt/openfire [root@yfw openfire]# sudo mkdir -p /opt/openfire/conf [root@yfw openfire]# sudo chown -R openfire:openfire /opt/openfire/conf [root@yfw openfire]# sudo chmod -R 755 /opt/openfire/conf [root@yfw openfire]# sudo rm -f /opt/openfire/conf/*.xml [root@yfw openfire]# sudo rm -f /opt/openfire/conf/*.xml [root@yfw openfire]# sudo -u openfire tee /opt/openfire/conf/openfire.xml > /dev/null << 'EOF' > <?xml version="1.0" encoding="UTF-8"?> > <jive> > <adminConsole> > <port>9090</port> > <securePort>9091</securePort> > </adminConsole> > <locale>en_US</locale> > <setup>true</setup> > </jive> > EOF [root@yfw openfire]# sudo chown openfire:openfire /opt/openfire/conf/openfire.xml [root@yfw openfire]# sudo chmod 644 /opt/openfire/conf/openfire.xml [root@yfw openfire]# sudo mkdir -p /opt/openfire/logs [root@yfw openfire]# sudo chown -R openfire:openfire /opt/openfire/logs [root@yfw openfire]# sudo chmod -R 755 /opt/openfire/logs [root@yfw openfire]# sudo su - openfire Last login: Sat Nov 15 17:35:21 CST 2025 on pts/0 ✅ JAVA_HOME: /usr/lib/jvm/java-11-openjdk ✅ Maven home: /opt/maven ✅ Java version: openjdk version "11.0.13" 2021-10-19 LTS ✅ Environment loaded for openfire PATH = /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/lib/jvm/java-11-openjdk/bin:/opt/maven/bin:/usr/local/ffmpeg/bin:/opt/spark/bin JAVA_HOME = /usr/lib/jvm/java-11-openjdk [openfire@yfw ~]$ cd /opt/openfire [openfire@yfw openfire]$ ./bin/start.sh --no-daemon Starting OpenFire in foreground mode... 17:39:00.999 [main] ERROR org.jivesoftware.util.JiveGlobals - Unable to load default security properties from: /opt/openfire/conf/openfire.xml java.nio.file.NoSuchFileException: XML properties file does not exist: security.xml at org.jivesoftware.util.XMLProperties.<init>(XMLProperties.java:148) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.loadSecurityProperties(JiveGlobals.java:1312) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.isXMLPropertyEncrypted(JiveGlobals.java:1010) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.XMLProperties.getProperty(XMLProperties.java:212) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.XMLProperties.getProperty(XMLProperties.java:171) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.getXMLProperty(JiveGlobals.java:310) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:367) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:658) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] 17:39:01.030 [main] ERROR org.jivesoftware.util.JiveProperties - null java.lang.NullPointerException: null at java.lang.Class.forName0(Native Method) ~[?:?] at java.lang.Class.forName(Class.java:375) ~[?:?] at org.jivesoftware.database.DefaultConnectionProvider.start(DefaultConnectionProvider.java:99) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.database.DbConnectionManager.setConnectionProvider(DbConnectionManager.java:652) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.database.DbConnectionManager.ensureConnectionProvider(DbConnectionManager.java:109) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:162) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.loadProperties(JiveProperties.java:472) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.init(JiveProperties.java:108) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.getInstance(JiveProperties.java:84) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.getProperty(JiveGlobals.java:547) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.cache.CacheFactory.<clinit>(CacheFactory.java:102) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:381) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:658) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Database setup or configuration error: Please verify your database settings and check the logs/openfire.log file for detailed error messages. 17:39:03.615 [main] ERROR org.jivesoftware.openfire.XMPPServer - Database could not be accessed java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Check JDBC properties; data source was not be initialised at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1010) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:666) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] java.lang.IllegalArgumentException: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Check JDBC properties; data source was not be initialised at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1020) at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:666) at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) at java.base/java.lang.Class.newInstance(Class.java:645) at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) Caused by: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Check JDBC properties; data source was not be initialised at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1010) ... 11 more 17:39:03.616 [main] ERROR org.jivesoftware.openfire.XMPPServer - java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Check JDBC properties; data source was not be initialised java.lang.IllegalArgumentException: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Check JDBC properties; data source was not be initialised at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1020) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:666) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Caused by: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Check JDBC properties; data source was not be initialised at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1010) ~[xmppserver-5.0.2.jar:5.0.2] ... 11 more Error starting the server. Please check the log files for more information.
最新发布
11-16
[root@yfw openfire]# sudo -u openfire java \ > -DopenfireHome=/opt/openfire \ > -cp "/opt/openfire/lib/*" \ > org.jivesoftware.util.JiveGlobals Error: LinkageError occurred while loading main class org.jivesoftware.util.JiveGlobals java.lang.UnsupportedClassVersionError: org/jivesoftware/util/JiveGlobals has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0 [root@yfw openfire]# java -version openjdk version "11.0.13" 2021-10-19 LTS OpenJDK Runtime Environment 18.9 (build 11.0.13+8-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8-LTS, mixed mode, sharing) [root@yfw openfire]# sudo -u openfire /usr/lib/jvm/java-17-openjdk/bin/java \ > -DopenfireHome=/opt/openfire \ > -classpath "/opt/openfire/lib/*" \ > org.jivesoftware.openfire.starter.ServerStarter Could not locate home java.io.FileNotFoundException at org.jivesoftware.openfire.XMPPServer.locateOpenfire(XMPPServer.java:1126) at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:365) at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:658) at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) at java.base/java.lang.Class.newInstance(Class.java:645) at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) 11:35:29.888 [main] ERROR org.jivesoftware.openfire.XMPPServer - null java.io.FileNotFoundException: null at org.jivesoftware.openfire.XMPPServer.locateOpenfire(XMPPServer.java:1126) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:365) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:658) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Error starting the server. Please check the log files for more information. Critical Error! The home directory has not been configured, which will prevent the application from working correctly. [root@yfw openfire]#
11-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值