I am using the latest version of Smack to communicate with Openfire but the MessageListener returns the same message every time. If I go into the Openfire Logs, I can see that my custom Plugin is returning different results, but the MessageListener only returns the first result. I can fix the problem by creating a new connection with every call, but that is not how the software should be used.
Here is the code to create the connection
// XMPPConnection.DEBUG_ENABLED = true;
conn = new XMPPConnection(“localhost”);
conn.connect();
conn.login(“mfs_laptop”,“mfs_laptop”);
MFSExtension mfs = new MFSExtension();
ProviderManager pm = ProviderManager.getInstance();
pm.addExtensionProvider("x", "http://arl.psu.edu/emss/mfs", mfs);
//see if we can get data from mfs plugin
ChatManager chatMan = conn.getChatManager();
newChat = chatMan.createChat(“mfs@mfs.localhost”, new MessageListener() {
public void processMessage(Chat chat, Message message){
try{
//get extension doc, look through for columns, and read into array
Document resultDoc = DocumentHelper.parseText(message.getExtension("x", "http://arl.psu.edu/emss/mfs").toXML());
System.out.println(resultDoc.asXML());
int numValues = resultDoc.getRootElement().element(“Result”).elements(“row”).size();
String[][] values = new String[numValues][2];
int numRows = 0;
for(Object row : resultDoc.getRootElement().element(“Result”).elements(“row”)){
Element rowElement = (Element)row;
for(Object col : rowElement.elements(“column”)){
Element colElement = (Element)col;
if(!colElement.attribute(0).getStringValue().equals(“NAME”)){
values[numRows][1] = colElement.attribute(1).getStringValue();
}
else if(colElement.attribute(0).getStringValue().equals(“NAME”)){
values[numRows][0] = colElement.attribute(1).getStringValue();
}
}
numRows++;
}
resultArray = values;
resultDone = true;
}
catch(Exception e){
System.out.println("Error processing message: " + e.toString());
}
}
});
Here is one of the individual message sends
public String[][] getSeverities(){
resultDone = false;
resultArray = null;
mfsMessage = new Message();
mfsMessage.setBody(“Howdy!”);
mfsMessage.setFrom(“mfs_laptop@localhost/Smack”);
mfsMessage.setTo(“mfs@mfs.localhost”);
mfsMessage.setType(Message.Type.chat);
MFSExtension mfs = new MFSExtension();
mfs.setUsername(“pdesmond”);
mfs.setSelect(“incident_severity_id,name”);
mfs.setFrom(“CS_INCIDENT_SEVERITIES_VL”);
mfs.setWhere(“end_date_active”);
mfs.setOperator(“is”);
mfs.setValue(“null”);
try{
mfsMessage.addExtension(mfs);
newChat.sendMessage(mfsMessage);
//wait for response
while(!resultDone){
Thread.sleep(100);
}
}
catch(Exception e){
}
return resultArray;
}
All this code is in the same class, and is called form a JSP page.
Any help would be appreciated. Thanks!
~Chris