pollMessage()

I’'m trying to create a jsp page that logs in and retrieves a message.

pollMessage() always returns null.

Is there something I’'m overlooking that is necessary from an HTTP request?

From the cold fusion examples I’'ve seen it looks like this should be straight forward, but nothing I try changes the results.

I

let me make it clearer.

I’'m logging in with a chat thread id from a previous open chat connection. So this should work? No?

I see that the cold fusion examples create a session but this shouldn’'t affect the Smack functionality except as a way to pass the chat ID. Right?

Has any one done this with a JSP tht might have a blcok of code I could peek at?

Thanks.

Here is what I have. Note that for testing I am manually inserting the chat ID into the login. This is where the problem lies, I think, because if I print it out, I notice that it continues to increment with each page request.

Is there no way to reconnect with the same chat ID on a subsequent HTTP request?

<%

XMPPConnection conn = new XMPPConnection(“jabber.com”);

conn.login(“name”, “pass”,“IlWVo56”);

Chat newChat = new Chat(conn, "name@jabber.org");

Message message = newChat.pollMessage();

if (message != null) {

mbody = message.getBody();

out.println(mbody);

} else {

if (message == null) {

out.println(“null”);

}

}

%>

Matthew,

The third #login() parameter is a resource identifier. Resources are typically used for identifying the place from where you are connecting (e.g. Home or Work).

If you want to create a Chat using a given chatID then you should use the following constructor Chat(XMPPConnection connection, String participant, String chatID). Otherwise you will have a new chatID for every new Chat.

Questions:

. Will the username/password be different for each HTTP request? The idea of creating a new connection for every request won’‘t scale (i.e. it’'s expensive) in a site with many requests per minute.

. Will the chatID be different for each HTTP request? If you’'ll have the same ID and username/pass then you can create only one XMPPConnection and only one Chat. You will need to keep these objects in memory so you can locate/reuse them for each request.

Regards,

– Gato

here is a complete JSP page but I still can’‘t get pollMessage to return anything but null ebven though I’'m succsessfully storing and retrieving a single chat session. Any one ever do this?

<%@ page import=“org.jivesoftware.smack.*” %>

<%@ page import=“org.jivesoftware.smack.packet.*” %>

<%@ page import=“java.util.*” %>

<%@page contentType=“text/html”%>

JSP Page

<%

if (session.getAttribute(“chatObject”) == null) {

XMPPConnection conn = new XMPPConnection(“jabber.com”);

conn.login(“name”, “password”);

Chat newChat = new Chat(conn, "name@jabber.com");

newChat.sendMessage(“Howdy!”);

session.setAttribute(“chatObject”, newChat);

session.setAttribute(“connObject”, conn);

} else {

XMPPConnection conn = (XMPPConnection)session.getAttribute(“connObject”);

Chat newChat = (Chat)session.getAttribute(“chatObject”);

Message message = newChat.pollMessage();

String mbody ="";

if (message != null) {

mbody = message.getBody();

out.println(mbody);

} else {

if (message == null) {

out.println(“null”);

}

}

}

%>

The issue is that a chat object is listening for a particular threadID from other users in order to direct the messages to you (messages without that threadID aren’'t delivered through the Chat object). So, you should probably just use a MessageListener instead of a Chat object.

So many people new to Smack have issues with this that I think we need to change the behavior of Chat such that any message from the user you’'re chatting with is delivered to the object.

Regards,

Matt