public void deliver(Packet packet) throws UnauthorizedException { if (isClosed()) { // 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; IoBuffer buffer = IoBuffer.allocate(4096); buffer.setAutoExpand(true); try { // OF-464: if the connection has been dropped, fail over to backupDeliverer (offline) if (!ioSession.isConnected()) { throw new IOException("Connection reset/closed by peer"); } XMLWriter xmlSerializer = new XMLWriter(new ByteBufferWriter(buffer, encoder.get()), new OutputFormat()); xmlSerializer.write(packet.getElement()); xmlSerializer.flush(); if (flashClient) { buffer.put((byte) '\0'); } buffer.flip(); ioSessionLock.lock(); try { ioSession.write(buffer); } finally { ioSessionLock.unlock(); } } 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 backupDeliverer.deliver(packet); } else { session.incrementServerPacketCount(); } } }
@Override boolean canProcess(Packet packet) { String senderDomain = packet.getFrom().getDomain(); if (!getAuthenticatedDomains().contains(senderDomain)) { synchronized (senderDomain.intern()) { if (!getAuthenticatedDomains().contains(senderDomain) && !authenticateSubdomain(senderDomain, packet.getTo().getDomain())) { // Return error since sender domain was not validated by remote server LocalSession.returnErrorToSender(packet); return false; } } } return true; }
/** * Closes the session, the virtual connection and notifies listeners that the connection has been * closed. */ @Override public void close() { if (state.compareAndSet(State.OPEN, State.CLOSED)) { if (session != null) { session.setStatus(Session.STATUS_CLOSED); } try { closeVirtualConnection(); } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error.close") + "\n" + toString(), e); } notifyCloseListeners(); } }
public void close() { synchronized (this) { if (isClosed()) { return; } try { deliverRawText(flashClient ? "</flash:stream>" : "</stream:stream>", false); } catch (Exception e) { // Ignore } if (session != null) { session.setStatus(Session.STATUS_CLOSED); } closed = true; } // OF-881: Notify any close listeners after the synchronized block has completed. notifyCloseListeners(); // clean up session, etc. ioSession.close(false); // async via MINA }