Java Code Examples for org.xmpp.packet.Message#addExtension()

The following examples show how to use org.xmpp.packet.Message#addExtension() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Openfire   File: NodeSubscription.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sends an request to authorize the pending subscription to the specified owner.
 *
 * @param owner the JID of the user that will get the authorization request.
 */
public void sendAuthorizationRequest(JID owner) {
    Message authRequest = new Message();
    authRequest.addExtension(node.getAuthRequestForm(this));
    authRequest.setTo(owner);
    authRequest.setFrom(node.getService().getAddress());
    // Send authentication request to node owners
    node.getService().send(authRequest);
}
 
Example 2
Source Project: Openfire   File: NodeSubscription.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sends an request to authorize the pending subscription to all owners. The first
 * answer sent by a owner will be processed. Rest of the answers will be discarded.
 */
public void sendAuthorizationRequest() {
    Message authRequest = new Message();
    authRequest.addExtension(node.getAuthRequestForm(this));
    // Send authentication request to node owners
    node.getService().broadcast(node, authRequest, node.getOwners());
}
 
Example 3
Source Project: Openfire   File: ForwardTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testForwarded() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    message.setBody("Tests");
    message.addExtension(new DataForm(DataForm.Type.submit));

    Forwarded forwarded = new Forwarded(message);
    Forwarded forwarded2 = new Forwarded(message);
    String xml1 = forwarded.getElement().asXML();
    String xml2 = forwarded2.getElement().asXML();
    assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml1);
    assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml2);
}
 
Example 4
@Test
public void shouldNotStoreEmptyChatMessagesWithOnlyChatStates() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
    message.addExtension(chatState);
    assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
 
Example 5
@Test
public void shouldNotStoreEmptyChatMessagesWithOnlyChatStatesAndThread() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    message.setThread("1234");
    PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
    message.addExtension(chatState);
    assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
 
Example 6
@Test
public void shouldStoreEmptyChatMessagesWithOtherExtensions() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
    message.addExtension(chatState);
    PacketExtension packetExtension2 = new PacketExtension("received", "urn:xmpp:receipts");
    message.addExtension(packetExtension2);
    assertTrue(OfflineMessageStore.shouldStoreMessage(message));
}
 
Example 7
Source Project: Openfire   File: RoutingTableImpl.java    License: Apache License 2.0 4 votes vote down vote up
private void ccMessage(JID originalRecipient, Message message) {
    // We don't want to CC a message that is already a CC
    final Element receivedElement = message.getChildElement(Received.NAME, Received.NAMESPACE);
    final boolean isCC = receivedElement != null;
    if (message.getType() == Message.Type.chat && !isCC) {
        List<JID> routes = getRoutes(originalRecipient.asBareJID(), null);
        for (JID ccJid : routes) {
            // The receiving server MUST NOT send a forwarded copy to the full JID the original <message/> stanza was addressed to, as that recipient receives the original <message/> stanza.
            if (!ccJid.equals(originalRecipient)) {
                ClientSession clientSession = getClientRoute(ccJid);
                if (clientSession.isMessageCarbonsEnabled()) {
                    Message carbon = new Message();
                    // The wrapping message SHOULD maintain the same 'type' attribute value;
                    carbon.setType(message.getType());
                    // the 'from' attribute MUST be the Carbons-enabled user's bare JID
                    carbon.setFrom(ccJid.asBareJID());
                    // and the 'to' attribute MUST be the full JID of the resource receiving the copy
                    carbon.setTo(ccJid);
                    // The content of the wrapping message MUST contain a <received/> element qualified by the namespace "urn:xmpp:carbons:2", which itself contains a <forwarded/> element qualified by the namespace "urn:xmpp:forward:0" that contains the original <message/>.
                    carbon.addExtension(new Received(new Forwarded(message)));

                    try {
                        final RoutableChannelHandler localRoute = localRoutingTable.getRoute(ccJid);
                        if (localRoute != null) {
                            // This session is on a local cluster node
                            localRoute.process(carbon);
                        } else {
                            // The session is not on a local cluster node, so try a remote
                            final ClientRoute remoteRoute = getClientRouteForLocalUser(ccJid);
                            if (remotePacketRouter != null // If we're in a cluster
                                && remoteRoute != null // and we've found a route to the other node
                                && !remoteRoute.getNodeID().equals(XMPPServer.getInstance().getNodeID())) { // and it really is a remote node
                                // Try and route the packet to the remote session
                                remotePacketRouter.routePacket(remoteRoute.getNodeID().toByteArray(), ccJid, carbon);
                            } else {
                                Log.warn("Unable to find route to CC remote user {}", ccJid);
                            }
                        }
                    } catch (UnauthorizedException e) {
                        Log.error("Unable to route packet {}", message, e);
                    }
                }
            }
        }
    }
}