am trying to develop a XMPP chat client (web application) which can connect to Gtalk. I am using jsp, servlets and Smack API.
When I ran the code in java class the whole application works smoothly.
But the moment I use jsp servlets I am having an issue regarding presence of the users.
Following is the code in servlet. I get the credentials from the jsp page to the servlet.
String userName=request.getParameter("username");
String password=request.getParameter("password");
// turn on the enhanced debugger
XMPPConnection.DEBUG_ENABLED = true;
// Start the connection with the Gtalk server
ConnectionConfiguration config = new ConnectionConfiguration(
"talk.google.com", 5222, "gmail.com");
connection = new XMPPConnection(config);
config.setSASLAuthenticationEnabled(false);
try {
connection.connect();
} catch (XMPPException e) {
e.printStackTrace();
}
try {
connection.login(userName, password);
} catch (XMPPException e) {
e.printStackTrace();
}
boolean status=connection.isAuthenticated();
if(status==true)
{
System.out.println("You are logged to gtalk..retreving roster list");
Roster roster = connection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry r : entries) {
String name = r.getName();
String user = r.getUser();
int count1 = 0;
int count2 = 0;
Presence presence = roster.getPresence(user);
System.out.println(presence.toXML());
if (presence.getType() == Presence.Type.available) {
System.out.println(user + "is online");
count1++;
} else {
System.out.println(name+user + "is offline");
count2++;
}
}
}
}
The code System.out.println(presence.toXML())
is returning unavailable for all users even when the user is available. The same code in java class returns correct presence.
So I think Smack API is used only for desktop. Has anyone tried using smack with JSP and servlets? Is there a workaround for this?