Package org.apache.vysper.xmpp.stanza

Examples of org.apache.vysper.xmpp.stanza.XMPPCoreStanza


    public void testWithBOTH() throws BindException, EntityFormatException {

        setResourceState(initiatingUser.getBoundResourceId(), ResourceState.AVAILABLE_INTERESTED);

        XMPPCoreStanza initialPresence = XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(initiatingUser.getEntityFQ(), subscribed_BOTH.getEntity(), null, PresenceStanzaType.SUBSCRIBE, null, null).build());

        handler.executeCore(initialPresence, sessionContext.getServerRuntimeContext(), true, sessionContext);
        assertEquals(ResourceState.AVAILABLE_INTERESTED, getResourceState());

        assertStanzasDeliveredAndRelayed(0); // TO subscription already exists with subscribed_BOTH
View Full Code Here


    public void testUpdatedPresence() throws BindException, EntityFormatException {
        StanzaReceiverRelay receiverRelay = (StanzaReceiverRelay) sessionContext.getServerRuntimeContext().getStanzaRelay();
        setResourceState(initiatingUser.getBoundResourceId(), ResourceState.AVAILABLE_INTERESTED);

        // at first, initial presence
        XMPPCoreStanza initialPresence = XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(initiatingUser.getEntityFQ(), unrelatedUser.getEntityFQ(), null, null, null, null).build());
        handler.executeCore(initialPresence, sessionContext.getServerRuntimeContext(), true, sessionContext);
        assertTrue(0 < receiverRelay.getCountDelivered());

        // directed presence has been recorded internally
        Set<Entity> map = (Set<Entity>)sessionContext.getAttribute("DIRECTED_PRESENCE_MAP_" + initiatingUser.getBoundResourceId());
        assertNotNull(map);
        assertEquals(map.iterator().next(), unrelatedUser.getEntityFQ());

        Stanza directedPresence = unrelatedUser.getNextStanza();
        assertNotNull(directedPresence);
        assertTrue(PresenceStanza.isOfType(directedPresence)); // is presence
        PresenceStanza presenceStanza = new PresenceStanza(directedPresence);
        assertEquals(initiatingUser.getEntityFQ(), presenceStanza.getFrom());

        resetRecordedStanzas(); // purge recorded

        // directed unavailable presence
        XMPPCoreStanza directedUnvailPresence = XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(initiatingUser.getEntityFQ(), unrelatedUser.getEntityFQ(), null, PresenceStanzaType.UNAVAILABLE, null, null).build());
        handler.executeCore(directedUnvailPresence, sessionContext.getServerRuntimeContext(), true, sessionContext);
        assertTrue(0 < receiverRelay.getCountDelivered());

        // directed presence has been recorded internally
        map = (Set<Entity>)sessionContext.getAttribute("DIRECTED_PRESENCE_MAP_" + initiatingUser.getBoundResourceId());
View Full Code Here

    public void testUnavailableForDirectedPresences() throws BindException, EntityFormatException {
        StanzaReceiverRelay receiverRelay = (StanzaReceiverRelay) sessionContext.getServerRuntimeContext().getStanzaRelay();
        setResourceState(initiatingUser.getBoundResourceId(), ResourceState.AVAILABLE_INTERESTED);

        // at first, initial presence
        XMPPCoreStanza initialPresence = XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(initiatingUser.getEntityFQ(), unrelatedUser.getEntityFQ(), null, null, null, null).build());
        handler.executeCore(initialPresence, sessionContext.getServerRuntimeContext(), true, sessionContext);

        // directed presence has been recorded internally
        Set<Entity> map = (Set<Entity>)sessionContext.getAttribute("DIRECTED_PRESENCE_MAP_" + initiatingUser.getBoundResourceId());
        assertEquals(map.iterator().next(), unrelatedUser.getEntityFQ());

        resetRecordedStanzas(); // purge recorded

        // GENERAL unavailable presence
        XMPPCoreStanza generalUnavailable = XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(initiatingUser.getEntityFQ(), null, null, PresenceStanzaType.UNAVAILABLE, null, null).build());
        handler.executeCore(generalUnavailable, sessionContext.getServerRuntimeContext(), true, sessionContext);
        assertTrue(0 < receiverRelay.getCountDelivered());
        ResourceState resourceState = sessionContext.getServerRuntimeContext().getResourceRegistry().getResourceState(initiatingUser.getBoundResourceId());
        assertFalse(ResourceState.isAvailable(resourceState));
View Full Code Here

public class PresenceAvailInitialOutHandlerTestCase extends PresenceHandlerBaseTestCase {

    protected PresenceHandler handler = new PresenceHandler();

    public void testInitialPresence() throws BindException, EntityFormatException {
        XMPPCoreStanza initialPresence = XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(initiatingUser.getEntityFQ(), null, null, null, null, null).build());

        assertEquals(ResourceState.CONNECTED, getResourceState());
        handler.executeCore(initialPresence, sessionContext.getServerRuntimeContext(), true, sessionContext);
        // check resource state change, do not override interested
        assertEquals(ResourceState.AVAILABLE, getResourceState());
View Full Code Here

    }

    public void testInitialPresenceWithoutFrom() throws BindException, EntityFormatException, XMLSemanticError {
        // after setUp(), there is more than one bound resource
        // so, if leaving from == null, the handler will not know from which resource the presence really comes...
        XMPPCoreStanza initialPresence = XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(null, null, null, null, null, null).build());

        Stanza stanza = handler.executeCore(initialPresence, sessionContext.getServerRuntimeContext(), true, sessionContext);
        // ... and will give an error:
        assertEquals("error", stanza.getAttribute("type").getValue());
        assertEquals(StanzaErrorCondition.UNKNOWN_SENDER.value(), stanza.getSingleInnerElementsNamed("error").getFirstInnerElement().getName());
View Full Code Here

    public void relay(Entity receiver, Stanza stanza, DeliveryFailureStrategy deliveryFailureStrategy)
            throws DeliveryException {
       
        // rewrite the namespace into the jabber:server namespace
        stanza = StanzaBuilder.rewriteNamespace(stanza, NamespaceURIs.JABBER_CLIENT, NamespaceURIs.JABBER_SERVER);
        XMPPCoreStanza coreStanza = XMPPCoreStanza.getWrapper(stanza);
       
        if(coreStanza != null) {
            Future<RelayResult> resultFuture = executor.submit(new OutboundRelayCallable(coreStanza, deliveryFailureStrategy));
        } else {
            // ignore non-core stanzas
View Full Code Here

                sessionContext.getXMLLang(), "could not process incoming stanza", receivedStanza);
        writeErrorAndClose(sessionContext, errorStanza);
    }

    public void handleWrongFromJID(SessionContext sessionContext, Stanza receivedStanza) {
        XMPPCoreStanza receivedCoreStanza = XMPPCoreStanza.getWrapper(receivedStanza);
        if (receivedCoreStanza == null) {
            handleNotAuthorized(sessionContext, receivedStanza);
            return;
        }
View Full Code Here

            stanza = XMPPCoreStanza.getWrapper(stanza);
        }
        if (stanza == null)
            throw new IllegalArgumentException("cannot coerce into a message, iq or presence stanza");

        XMPPCoreStanza coreStanza = (XMPPCoreStanza) stanza;
        Stanza errorStanza = ServerErrorResponses.getStanzaError(
                StanzaErrorCondition.SERVICE_UNAVAILABLE, coreStanza, StanzaErrorType.CANCEL,
                "namespace not supported", null, null);
        return new ResponseStanzaContainerImpl(errorStanza);
    }
View Full Code Here

        if (!(failedToDeliverStanza instanceof XMPPCoreStanza)) {
            throw new DeliveryException("could not return to sender");
        }
       
       
        XMPPCoreStanza failedCoreStanza = (XMPPCoreStanza) failedToDeliverStanza;
        if ("error".equals(failedCoreStanza.getType())) {
            return; // do not answer these
        }

        if (deliveryExceptions == null) {
            XMPPCoreStanza error = XMPPCoreStanza.getWrapper(ServerErrorResponses.getStanzaError(
                    stanzaErrorCondition, failedCoreStanza, errorType, "stanza could not be delivered", "en", null));
            stanzaRelay.relay(error.getTo(), error, IgnoreFailureStrategy.IGNORE_FAILURE_STRATEGY);
        } else if (deliveryExceptions.size() == 1) {
            DeliveryException deliveryException = deliveryExceptions.get(0);
            if (deliveryException instanceof LocalRecipientOfflineException) {
                // TODO implement 8.2.3 here
                stanzaErrorCondition = StanzaErrorCondition.RECIPIENT_UNAVAILABLE;
                if (failedCoreStanza instanceof MessageStanza || failedCoreStanza instanceof IQStanza) {
                    // RFC3921bis#8.1: message and IQ must return service unavailable
                    stanzaErrorCondition = StanzaErrorCondition.SERVICE_UNAVAILABLE;
                }
            } else if (deliveryException instanceof NoSuchLocalUserException) {
                // RFC3921bis#8.1: message and IQ must return service unavailable
                stanzaErrorCondition = StanzaErrorCondition.SERVICE_UNAVAILABLE;
                if (failedCoreStanza instanceof PresenceStanza) {
                    final PresenceStanzaType presenceStanzaType = ((PresenceStanza) failedCoreStanza).getPresenceType();
                    if (presenceStanzaType == null || presenceStanzaType == SUBSCRIBED
                            || presenceStanzaType == UNSUBSCRIBE || presenceStanzaType == UNSUBSCRIBED
                            || presenceStanzaType == UNAVAILABLE || presenceStanzaType == ERROR) {
                        return; // silently ignore
                    }
                    // TODO what happens with PROBE? 8.1 is silent here, but see 4.3
                    if (presenceStanzaType == SUBSCRIBE) {
                        // return UNSUBSCRIBED
                        final Entity from = failedToDeliverStanza.getTo(); // reverse from/to
                        final Entity to = failedToDeliverStanza.getFrom(); // reverse from/to
                        StanzaBuilder builder = StanzaBuilder.createPresenceStanza(from, to, null, UNSUBSCRIBED, null,
                                null);
                        final Stanza finalStanza = builder.build();
                        stanzaRelay.relay(to, finalStanza, IgnoreFailureStrategy.IGNORE_FAILURE_STRATEGY);
                        return;
                    }
                }
            } else if (deliveryException instanceof SmartDeliveryException) {
                // RFC3921bis#10.4.3: return remote server error to sender
                SmartDeliveryException smartDeliveryException = (SmartDeliveryException) deliveryException;
                XMPPCoreStanza error = XMPPCoreStanza
                        .getWrapper(ServerErrorResponses.getStanzaError(
                                smartDeliveryException.getStanzaErrorCondition(), failedCoreStanza,
                                smartDeliveryException.getStanzaErrorType(), smartDeliveryException.getErrorText(),
                                "en", null));
                stanzaRelay.relay(error.getTo(), error, IgnoreFailureStrategy.IGNORE_FAILURE_STRATEGY);
            }
        } else if (deliveryExceptions.size() > 1) {
            throw new RuntimeException("cannot return to sender for multiple failed deliveries");
        }
    }
View Full Code Here

            }
        }

        Entity from = stanza.getFrom();
        if(sessionContext.isServerToServer()) {
            XMPPCoreStanza coreStanza = XMPPCoreStanza.getWrapper(stanza);
           
            if(coreStanza != null) {
                // stanza must come from the origin server
                if(from == null) {
                    Stanza errorStanza = ServerErrorResponses.getStanzaError(StanzaErrorCondition.UNKNOWN_SENDER,
View Full Code Here

TOP

Related Classes of org.apache.vysper.xmpp.stanza.XMPPCoreStanza

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.