@Override
    public void deliver(Packet packet) throws UnauthorizedException
    {
        if (isClosed()) {
            if (backupDeliverer != null) {
                backupDeliverer.deliver(packet);
            } else {
                Log.trace("Discarding packet that was due to be delivered on closed connection {}, for which no backup deliverer was configured.", this);
            }
        }
        else {
            boolean errorDelivering = false;
            try {
                final String xml;
                if (Namespace.NO_NAMESPACE.equals(packet.getElement().getNamespace())) {
                    // use string-based operation here to avoid cascading xmlns wonkery
                    StringBuilder packetXml = new StringBuilder(packet.toXML());
                    packetXml.insert(packetXml.indexOf(" "), " xmlns=\"jabber:client\"");
                    xml = packetXml.toString();
                } else {
                    xml = packet.toXML();
                }
                socket.getWsSession().getRemote().sendString(xml);
            } catch (Exception e) {
                Log.debug("Error delivering packet:\n" + packet, e);
                errorDelivering = true;
            }
            if (errorDelivering) {
                close();
                // Retry sending the packet again. Most probably if the packet is a
                // Message it will be stored offline
                if (backupDeliverer != null) {
                    backupDeliverer.deliver(packet);
                } else {
                    Log.trace("Discarding packet that failed to be delivered to connection {}, for which no backup deliverer was configured.", this);
                }
            }
            else {
                session.incrementServerPacketCount();
            }
        }
    }
Following the conventions of the BOSH implementation, this class extends {@link VirtualConnection}
and delegates the expected XMPP connection behaviors to the corresponding {@link WebSocketClientConnectionHandler}.
xmppserver/src/main/java/org/jivesoftware/openfire/websocket/WebSocketConnection.java