/** * Returns a value that is an appropriate unique and stable stanza ID in * context of XEP-0359: it's either the origin-id value, or a UUID. * * @param packet The stanza for what to return the ID (cannot be null). * @return The ID (never null or empty string). */ public static String generateUniqueAndStableStanzaID( final Packet packet ) { String result = null; final Iterator<Element> existingElementIterator = packet.getElement().elementIterator( QName.get( "origin-id", "urn:xmpp:sid:0" ) ); while (existingElementIterator.hasNext() && (result == null || result.isEmpty() ) ) { final Element element = existingElementIterator.next(); result = element.attributeValue( "id" ); } if ( result == null || result.isEmpty() ) { result = UUID.randomUUID().toString(); Log.debug( "Using newly generated value '{}' for stanza that has id '{}'.", result, packet.getID() ); } else { Log.debug( "Using origin-id provided value '{}' for stanza that has id '{}'.", result, packet.getID() ); } return result; } }
@Override public void processPacket(Packet packet) { if (packet instanceof IQ) { IQ iq = (IQ) packet; if (iq.getType() == IQ.Type.result || iq.getType() == IQ.Type.error) { // Check if this IQ reply belongs to a specific component and route // reply to that specific component (if it exists) LocalExternalComponent targetComponent; synchronized (iqs) { targetComponent = iqs.remove(packet.getID()); } if (targetComponent != null) { targetComponent.processPacket(packet); return; } } } // Ask the session to process the outgoing packet. This will // give us the chance to apply PacketInterceptors session.process(packet); }
@Override public void processPacket(Packet packet) { if (packet instanceof IQ) { IQ iq = (IQ) packet; if (iq.getType() == IQ.Type.result || iq.getType() == IQ.Type.error) { // Check if this IQ reply belongs to a specific component and route // reply to that specific component (if it exists) LocalExternalComponent targetComponent; synchronized (iqs) { targetComponent = iqs.remove(packet.getID()); } if (targetComponent != null) { targetComponent.processPacket(packet); return; } } } // Ask the session to process the outgoing packet. This will // give us the chance to apply PacketInterceptors session.process(packet); }