public class SendMessage{
private XMPPConnection con;
private ChatManager chatmanager;
public XMPPConnection login(String messageProducer, String messageProducerPassword) {
ConnectionConfiguration config = new ConnectionConfiguration(this.serverDomain,
this.serverPort);
XMPPConnection con = new XMPPConnection(config);
try {
con.connect();
} catch (XMPPException e) {
throw new RuntimeException("Connect xmpp server", e);
}
try {
con.login(this.messageProducer, this.messageProducerPassword);
} catch (XMPPException e) {
throw new RuntimeException("login failed: " + e.getMessage() + " with "
+ messageProducer + ":" + messageProducerPassword);
}
return con;
}
private void sendMessage(String to, String message) {
try {
Chat newChat = chatmanager.createChat(to, new MessageListener() {
public void processMessage(Chat chat, Message message) {
}
});
newChat.sendMessage(message);
} catch (XMPPException e) {
log.error("Got error while sending message to " + to.getUsername(), e);
}
}
private void layout() {
if (con != null && con.isConnected()) {
con.disconnect();
}
}
}