Message sessions

can i receive offline messages with smack?

i mean: my program dont have connection all the time, but periodically connects to jabber server; on other side there are jabber client (Exodus). Main task of my software - create bidirectional message session (or chat) between web-client and instant messenger.

i created simple prototype, but now i can only send messages from web-client.

Roman,

Yes, you should be able receive offline messages. Does something in particular appear to not be working?

Regards,

Matt

I think the problem is that you can only open chat sessions with a given or new id. Is there also a possibility to retrieve non-chat messages or to accept chats with an unknown id ?

You can register a PacketCollector or PacketListener to listen for any messages (use the PacketTypeFilter). Eventually, we’'ll add a special filter that can listen for new conversations.

Regards,

Matt

*first request: *

XMPPConnection con = new XMPPConnection(request.getAttribute(“Server”));

con.login(request.getAttribute(“User”), request.getAttribute(“Password”));

Chat chat = con.createChat(request.getAttribute(“To”));

chat.sendMessage(request.getAttribute(“Message”));

response.setVariable(request.getAttribute(“Name”), chat.getChatID());

*second request: *

XMPPConnection con = new XMPPConnection(request.getAttribute(“Server”));

con.login(request.getAttribute(“User”), request.getAttribute(“Password”));

Chat chat = new Chat(con, request.getAttribute(“To”), request.getAttribute(“ChatID”));

Message msg = chat.pollMessage();

but variable msg is *null *

Roman,

If you read the Javadocs for pollMessage() you’'ll see that it always returns immediately, even if no results are present. You probably want to try the methods:

Chat.nextMessage() or

Chat.nextMessage(long timeout)

Also, what you’‘re trying won’‘t quite work unless your server is setup for offline delivery. Even then, you could run into a problem since the server could send the message to the second connection before the packet collector is registered. It looks like this is a JSP page? In that case, I’‘d recommend making the connection object persistent across page views. You could do this by adding it to the user’‘s session, having a seperate cache for connection objects, or by making the connection a static variable (although that might not work well). Once connections live across multiple page views, I think you’'ll find things work better.

Regards,

Matt

Server is configured for offline delivery.

Its not JSP, its ColdFusion MX Java CFX

But today ive found some problem (even in console application) - smack (xml parser) reports exception when im trying to send message to application. (there are font definition in message and looks like parser dont understand it)

Can you post a sample of a message that’'s giving you errors?

Regards,

Matt

тест
B5AB

looks like xml parser dont understand html

Roman,

That’‘s an invalid message – you’‘re not allowed to use any XML inside the body tag. So, you’'ll either need to encode it (convert < to &lt;, etc) or use the xhtml message format (see jabber.org).

Regards,

Matt

its not XML, its XHTML, but ive found that is not included in xhtml-basic RFC. May be this is problem.

Roman,

It’'s still against the Jabber spec to include any XML inside a normal body tag. Instead, your message is supposed to have a seperate section.

Regards,

Matt