2
votes

I think I'm doing something wrong. I want to send a XMPP message to my GTalk id but I don't want that the GTalk app receives the message so I'm changing the resource of the recipient JID.

My problem is that GTalk is receiving all the messages although thay have different resource.

My code:

public void doPost(HttpServletRequest req,
        HttpServletResponse resp) throws IOException {

    // Parse incoming message
    XMPPService xmpp = XMPPServiceFactory.getXMPPService();
    Message msg = xmpp.parseMessage(req);
    JID jid = msg.getFromJid();
    String body = msg.getBody();

    String jidID = jid.getId().split("/")[0];
    JID jid2 = new JID(jidID+"/myownresource453242352");

    String response =  jid2.getId() + " " + body;

    // Send out response
    msg = new MessageBuilder().withRecipientJids(jid2).withBody(response).build();
    xmpp.sendMessage(msg);

}

The output:

What's wrong?

UPDATE:

Now I'm sending messages to [email protected]/bot from an aSmack client and it is resending the message to me at my client.

The problem is GTalk for Gmail and GTalk for Android is registering all sent messages but they don't receive the app responses. Other clients don't show the messages I don't sent with them.

Will I be able to hide my messages to Gmail and Android?

My code:

SERVER

  public void doPost(HttpServletRequest req,
  HttpServletResponse resp) throws IOException {
  LOG.setLevel(Level.INFO);
// Parse incoming message
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
Message msg = xmpp.parseMessage(req);

LOG.info(msg.getStanza());

JID jid = msg.getFromJid();
String body = msg.getBody();

String response =  "FullID: "+jid.getId()+" El mensaje recibido es: "+body;

// Send out response
msg = new MessageBuilder().
    withRecipientJids(jid)
    .withMessageType(MessageType.NORMAL)
    .withBody(response)
    .build();
xmpp.sendMessage(msg);

}

CLIENT:

ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
                    XMPPConnection connection = new XMPPConnection(connectionConfiguration);
                    try {
                        Log.i("TAG","Trying to connect");
                        connection.connect();
                        Log.i("TAG","Connected");
                        SASLAuthentication.supportSASLMechanism("PLAIN", 0);
                        Log.i("TAG","Trying to Log In");
                        connection.login("[email protected]",mypass, mires");
                        Log.i("TAG","Logged In");
                    } catch (XMPPException e) {
                        e.printStackTrace();
                        Log.i("TAG","Problem connecting or logging in");
                    }
                    //Creating chat object for processing friend chat
                    Chat chat = connection.getChatManager().createChat(Server, new MessageListener() {
                        //Overriding process message function of MessageListener Interface which will be 
                                    //called whenever a message is received
                        @Override
                        public void processMessage(Chat c, Message m) {
                            //Displaying message sent by friend
                            //System.out.println(friendId+ " : " + m.getBody());
                            Log.i("TAG", m.getBody());
                            message = m.getBody();
                        }   
                    });
                    try {
                        Message out = new Message();
                        out.setBody("Definitivo22222222");
                        out.setType(Type.normal);
                        chat.sendMessage(out);
                        Log.i("TAG", "Mensaje enviado");
                    } catch (XMPPException e) {
                        Log.i("TAG", "No se envió el mensaje");
                        e.printStackTrace();
                    }

Last thing: I've seen in AppEngine Logs that the Stanza received from aSmack isn't of normal type but chat type.

Thanks for helping!!

Last-last thing: You can test what Gmail is doing by connecting from any client and Gmail at same time and talking from the client. Gmail is receiving your messages.

Thanks again.

Another thing: My goalis use XMPP to communicate 2 clients of a game with their gmail account. Do you know an alternative?

3
What Google Talk client are you using? Gmail, the download client (googletalk.exe), Google+, Pidgin, something else?Moishe Lettvin
I've tested in Empathy, GTalk for Windows and GmailRafaesp

3 Answers

5
votes

See RFC 6120, section 10.5.4:

If the JID contained in the 'to' attribute is of the form localpart@domainpart/resourcepart and the user exists but there is no connected resource that exactly matches the full JID, the stanza SHOULD be processed as if the JID were of the form localpart@domainpart as described under Section 10.5.3.2.

If you send to an invalid resource, the server treats it as if you had sent it to the bare JID. On GoogleTalk, this goes to all non-negative priority resources.

2
votes

I think that this is by design. IIRC GTalk routes all messages for a given JID to all connected resources of the JID. This is even true if the message has a full JID as to.

2
votes

If you send the message with JID and resource (user@yoursever/reourcex) then the receiving server will route your request to the intended receiver. The receiving server will decide how to route the JID/resource.

A standard server will look for an exact match of the sent JID/resource. If found then it will behave as expected and the message will be delivered. If that fails on the other hand, it will send the message to the highest priority online resource. If that fails, it will store the message offline.

In the case of Google Talk this will happen: it will try to match the exact resource, and if that fails, broadcast it to all of the online resources. The same is also applied if no resource included.