public LeafNode getOrCreateLeafNode ( final String id ) throws NoResponseException , NotConnectedException , InterruptedException , XMPPErrorException , NotALeafNodeException { try { return getLeafNode ( id ) ; } catch ( NotAPubSubNodeException e ) { return createNode ( id ) ; } catch ( XMPPErrorException e1 ) { if ( e1 . getStanzaError ( ) . getCondition ( ) == Condition . item_not_found ) { try { return createNode ( id ) ; } catch ( XMPPErrorException e2 ) { if ( e2 . getStanzaError ( ) . getCondition ( ) == Condition . conflict ) { // The node was created in the meantime, re-try getNode(). Note that this case should be rare. try { return getLeafNode ( id ) ; } catch ( NotAPubSubNodeException e ) { // Should not happen throw new IllegalStateException ( e ) ; } } throw e2 ; } } if ( e1 . getStanzaError ( ) . getCondition ( ) == Condition . service_unavailable ) { // This could be caused by Prosody bug #805 (see https://prosody.im/issues/issue/805). Prosody does not // answer to disco#info requests on the node ID, which makes it undecidable if a node is a leaf or // collection node. LOGGER . warning ( "The PubSub service " + pubSubService + " threw an DiscoInfoNodeAssertionError, trying workaround for Prosody bug #805 (https://prosody.im/issues/issue/805)" ) ; return getOrCreateLeafNodeProsodyWorkaround ( id ) ; } throw e1 ; } }
Try to get a leaf node and create one if it does not already exist .