XMPP reply from GAE to Google+ doesn't work
-
27-10-2019 - |
Question
I've noticed errors in my Google App Engine Log while parsing messages. The stack trace was unhelpful to diagnose the problem, so I wrote a small message dumper inspired by Google's implementation of InboundMessageParser.
public class ChatRequestParser extends HttpRequestParser {
public static Map<String, String> parseMessage(HttpServletRequest request)
throws IOException {
try {
Map<String, String> message = new HashMap<String, String>();
MimeMultipart multipart = parseMultipartRequest(request);
int parts = multipart.getCount();
for (int i = 0; i < parts; i++) {
BodyPart part = multipart.getBodyPart(i);
String fieldName = getFieldName(part);
String fieldValue = getTextContent(part);
message.put(fieldName, fieldValue);
}
return message;
} catch (MessagingException ex) {
throw new IOException("Could not parse incoming request.", ex);
}
}
}
I found out that Google+ sends two messages for each message, only one of which contains a body (Gmail Talk client sends only one message).
Here is the first message, without a body:
{to=xxx@appspot.com, stanza=<message to="xxx@appspot.com" type="chat"
from="yyy@gmail.com/TalkGadgetD9F45A83" xmlns="jabber:client">
<cha:composing xmlns:cha="http://jabber.org/protocol/chatstates"/>
<nos:x value="disabled" xmlns:nos="google:nosave"/>
<arc:record otr="false" xmlns:arc="http://jabber.org/protocol/archive"/>
</message>, from=yyy@gmail.com/TalkGadgetD9F45A83}
And the second one is (my payload is many asterisks, mails changed):
{to=xxx@appspot.com, body=**********************************,
stanza=<message to="xxx@appspot.com" type="chat"
id="7279D79D0.17809585028724073_:sl" from="yyy@gmail.com/TalkGadgetD9F45A83"
xmlns="jabber:client"><body>**********************************</body>
<cha:active xmlns:cha="http://jabber.org/protocol/chatstates"/>
<nos:x value="disabled" xmlns:nos="google:nosave"/><arc:record otr="false"
xmlns:arc="http://jabber.org/protocol/archive"/></message>,
from=yyy@gmail.com/TalkGadgetD9F45A83}
Since the first message doesn't have a body calling parseMessage() on XMPPService throws exception. Has anyone noticed this problem?
Now I am catching the IllegalArgumentException and throwing away meaningless messages, but the real problem is, that the reply to the valid message doesn't arrive back to Google+ client, while works perfectly with Gmail and also with my Jabber client on Linux.
I've filed issue 6467.
Solution
I can reproduce the crash when no body is set and parseMessage is called, and I'm fixing it. Thanks for finding it!
However, I can't repro the "send reply doesn't work" bug. I have code like this:
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
Message message = xmpp.parseMessage(req);
Message reply = new MessageBuilder().withFromJid(message.getRecipientJids()[0])
.withRecipientJids(message.getFromJid())
.withBody("Back at you!")
.build();
xmpp.sendMessage(reply);
And I receive the reply both in Google+ and in Gmail. What are you doing differently?