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

The following examples show how to use org.xmpp.packet.Message#createCopy() . 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 File: MessageRouter.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private void bounce(Message message) {
    // The bouncing behavior as implemented beyond this point was introduced as part
    // of OF-1852. This kill-switch allows it to be disabled again in case it
    // introduces unwanted side-effects.
    if ( !JiveGlobals.getBooleanProperty( "xmpp.message.bounce", true ) ) {
        log.trace( "Not bouncing a message stanza, as bouncing is disabled by configuration." );
        return;
    }

    // Do nothing if the packet included an error. This intends to prevent scenarios
    // where a stanza that is bounced itself gets bounced, causing a loop.
    if (message.getError() != null) {
        log.trace( "Not bouncing a stanza that included an error (to prevent never-ending loops of bounces-of-bounces)." );
        return;
    }

    // Do nothing if the sender was the server itself
    if (message.getFrom() == null || message.getFrom().toString().equals( serverName )) {
        log.trace( "Not bouncing a stanza that was sent by the server itself." );
        return;
    }
    try {
        log.trace( "Bouncing a message stanza." );

        // Generate a rejection response to the sender
        final Message errorResponse = message.createCopy();
        // return an error stanza to the sender, which SHOULD be <service-unavailable/>
        errorResponse.setError(PacketError.Condition.service_unavailable);
        errorResponse.setFrom(message.getTo());
        errorResponse.setTo(message.getFrom());
        // Send the response
        route(errorResponse);
    }
    catch (Exception e) {
        log.error("An exception occurred while trying to bounce a message.", e);
    }
}
 
Example 2
Source File: OfflineMessageStrategy.java    From Openfire with Apache License 2.0 4 votes vote down vote up
public void storeOffline(Message message) {
    if (message != null) {
        // Do nothing if the message was sent to the server itself, an anonymous user or a non-existent user
        // Also ignore message carbons
        JID recipientJID = message.getTo();
        if (recipientJID == null || serverAddress.equals(recipientJID) ||
                recipientJID.getNode() == null ||
                message.getExtension("received", "urn:xmpp:carbons:2") != null ||
                !UserManager.getInstance().isRegisteredUser(recipientJID.getNode())) {
            return;
        }

        // Do not store messages if communication is blocked
        PrivacyList list =
                PrivacyListManager.getInstance().getDefaultPrivacyList(recipientJID.getNode());
        if (list != null && list.shouldBlockPacket(message)) {
            Message result = message.createCopy();
            result.setTo(message.getFrom());
            result.setFrom(message.getTo());
            result.setError(PacketError.Condition.service_unavailable);
            XMPPServer.getInstance().getRoutingTable().routePacket(message.getFrom(), result, true);
            return;
        }

        // 8.5.2.  localpart@domainpart
        // 8.5.2.2.  No Available or Connected Resources
        if (recipientJID.getResource() == null) {
            if (message.getType() == Message.Type.headline || message.getType() == Message.Type.error) {
                // For a message stanza of type "headline" or "error", the server MUST silently ignore the message.
                return;
            }
            // // For a message stanza of type "groupchat", the server MUST return an error to the sender, which SHOULD be <service-unavailable/>.
            else if (message.getType() == Message.Type.groupchat) {
                bounce(message);
                return;
            }
        } else {
            // 8.5.3.  localpart@domainpart/resourcepart
            // 8.5.3.2.1.  Message

            // For a message stanza of type "normal", "groupchat", or "headline", the server MUST either (a) silently ignore the stanza
            // or (b) return an error stanza to the sender, which SHOULD be <service-unavailable/>.
            if (message.getType() == Message.Type.normal || message.getType() == Message.Type.groupchat || message.getType() == Message.Type.headline) {
                // Depending on the OfflineMessageStragey, we may silently ignore or bounce
                if (type == Type.bounce) {
                    bounce(message);
                }
                // Either bounce or silently ignore, never store such messages
                return;
            }
            // For a message stanza of type "error", the server MUST silently ignore the stanza.
            else if (message.getType() == Message.Type.error) {
                return;
            }
        }

        switch (type) {
        case bounce:
            bounce(message);
            break;
        case store:
            store(message);
            break;
        case store_and_bounce:
            if (underQuota(message)) {
                store(message);
            }
            else {
                Log.debug( "Unable to store, as user is over storage quota. Bouncing message instead: " + message.toXML() );
                bounce(message);
            }
            break;
        case store_and_drop:
            if (underQuota(message)) {
                store(message);
            } else {
                Log.debug( "Unable to store, as user is over storage quota. Silently dropping message: " + message.toXML() );
            }
            break;
        case drop:
            // Drop essentially means silently ignore/do nothing
            break;
        }
    }
}
 
Example 3
Source File: Forwarded.java    From Openfire with Apache License 2.0 4 votes vote down vote up
public Forwarded(Message message, Date delay, JID delayFrom) {
    super("forwarded", "urn:xmpp:forward:0");

    Message copy = message.createCopy();
    populate(copy.getElement(), delay, delayFrom);
}
 
Example 4
Source File: Forwarded.java    From Openfire with Apache License 2.0 4 votes vote down vote up
public Forwarded(Message message) {
    super("forwarded", "urn:xmpp:forward:0");

    Message copy = message.createCopy();
    populate(copy.getElement(), null, null);
}