ChatManager chatManager = connection.getChatManager();
if (LOG.isTraceEnabled()) {
LOG.trace("Looking for existing chat instance with thread ID " + endpoint.getChatId());
}
Chat chat = chatManager.getThreadChat(endpoint.getChatId());
if (chat == null) {
if (LOG.isTraceEnabled()) {
LOG.trace("Creating new chat instance with thread ID " + endpoint.getChatId());
}
chat = chatManager.createChat(getParticipant(), endpoint.getChatId(), new MessageListener() {
public void processMessage(Chat chat, Message message) {
// not here to do conversation
if (LOG.isDebugEnabled()) {
LOG.debug("Received and discarding message from " + getParticipant() + " : " + message.getBody());
}
}
});
}
Message message = null;
try {
message = new Message();
message.setTo(getParticipant());
message.setThread(endpoint.getChatId());
message.setType(Message.Type.normal);
endpoint.getBinding().populateXmppMessage(message, exchange);
if (LOG.isDebugEnabled()) {
LOG.debug("Sending XMPP message to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message.getBody());
}
chat.sendMessage(message);
} catch (XMPPException xmppe) {
throw new RuntimeExchangeException("Cannot send XMPP message: to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
+ " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot send XMPP message to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message