[Openfire API] Sending message to all users

Hi,

We are trying to develop a plugin for communicating our clients. I have couple of questions:

  1. Broadcasting message using the SessionManager **sendServerMessage method sends from a default account. Is there a way to change the sender address there? **

**2. How to get the list of all JIDs in my openfire server? **

Thanks in advanced

you should learn IQHandler, and your class extends IQHandler

public class TestIQHandler extends IQHandler {

@Override

public IQ handleIQ(IQ packet) throws UnauthorizedException {

String myjid=packet.getFrom().toBareJID();//this is a login user jid

//do someting,such as send message to all jids

//you should use sql to get all jid.code:

String sql = “select jid from ofroster”;

Connection con = DbConnectionManager.getConnection();

Statement pstmt = con.createStatement();

ResultSet rs = pstmt.executeQuery(sql);

ResultSetMetaData md = rs.getMetaData();

while (rs.next()) {

list.add(rs.getString(“jid”));

}

}

}

in initializePlugin method add code:

XMPPServer.getInstance().getIQRouter().addHandler(new TestIQHandler());

Thanks for your reply. I started learning IQ and below is my function. Im trying to send a ping to a client. However, when I execute it, client receive nothing. Any idea why ?

public void sendMessage(String from, String to) {

final Message message = new Message();

final XMPPServer xmppServer = XMPPServer.getInstance();

JID toAddress = new JID(to+"@"+serverName);

JID fromAddress = new JID(from+"@"+serverName);

//message.setTo(toAddress);

//message.setFrom(fromAddress);

//message.setSubject(getSubject());

//message.setBody(getMessage());

// For testing purpose

IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();

IQ iq = new IQ();

iq.setTo(toAddress);

iq.setFrom(fromAddress);

iq.setType(IQ.Type.get);

iq.setChildElement(“ping”,“urn:xmpp:ping”);

iqRouter.route(iq);

//router.route(message);

}

JID toAddress = new JID(to+"@"+serverName+"/Smack");

Full JID is equal to Client JID, add your resources,such as “/Smack”

when jid resources is right,the client can receive iq

Thanks a lot Sun… working!