Commit 9205a2f1 authored by Tom Evans's avatar Tom Evans

OF-857: Added offline packet deliverer

When a connection is closed, any further packets to be delivered need to
be handled by the "backup" packet deliverer. The original implementation
simply tried to reuse the primary delivery/routing mechanism, which
resulted in a recursive call. This has been replaced with a packet
deliverer that will route undeliverable message packets into the offline
store.
parent 4c4949eb
......@@ -50,7 +50,7 @@ public class ClientConnectionHandler extends ConnectionHandler {
@Override
NIOConnection createNIOConnection(IoSession session) {
return new NIOConnection(session, XMPPServer.getInstance().getPacketDeliverer());
return new NIOConnection(session, new OfflinePacketDeliverer());
}
@Override
......
......@@ -255,7 +255,15 @@ public class NIOConnection implements Connection {
public void deliver(Packet packet) throws UnauthorizedException {
if (isClosed()) {
backupDeliverer.deliver(packet);
// OF-857: Do not allow the backup deliverer to recurse
if (backupDeliverer == null) {
Log.error("Failed to deliver packet: " + packet.toXML());
throw new IllegalStateException("Connection closed");
}
// attempt to deliver via backup only once
PacketDeliverer backup = backupDeliverer;
backupDeliverer = null;
backup.deliver(packet);
}
else {
boolean errorDelivering = false;
......
/**
* Copyright (C) 2005-2015 Jive Software. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.openfire.nio;
import org.jivesoftware.openfire.OfflineMessageStrategy;
import org.jivesoftware.openfire.PacketDeliverer;
import org.jivesoftware.openfire.PacketException;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.util.LocaleUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
/**
* Fallback method used by {@link org.jivesoftware.openfire.nio.NIOConnection} when a
* connection fails to send a {@link Packet} (likely because it was closed). Message packets
* will be stored offline for later retrieval. IQ and Presence packets are dropped.<p>
*
* @author Tom Evans
*/
public class OfflinePacketDeliverer implements PacketDeliverer {
private static final Logger Log = LoggerFactory.getLogger(OfflinePacketDeliverer.class);
private OfflineMessageStrategy messageStrategy;
public OfflinePacketDeliverer() {
this.messageStrategy = XMPPServer.getInstance().getOfflineMessageStrategy();
}
@Override
public void deliver(Packet packet) throws UnauthorizedException, PacketException {
if (packet instanceof Message) {
messageStrategy.storeOffline((Message) packet);
}
else if (packet instanceof Presence) {
// presence packets are dropped silently
}
else if (packet instanceof IQ) {
// IQ packets are logged before being dropped
Log.warn(LocaleUtils.getLocalizedString("admin.error.routing") + "\n" + packet.toString());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment