Package org.apache.vysper.xmpp.addressing

Examples of org.apache.vysper.xmpp.addressing.Entity


        assertEquals("stanza relayed to correct receiver", receiverUser.getEntity(), receivedStanza.getTo());

    }

    public void testStanzaReceiverUnavailable() throws EntityFormatException, DeliveryException {
        Entity sender = EntityImpl.parse("from@example.com/resID");
        Entity receiver = EntityImpl.parse("to_exist@example.com");
        Entity noReceiver = EntityImpl.parse("to_unavail@example.com");

        StanzaReceiverRelay stanzaRelay = (StanzaReceiverRelay) senderSessionContext.getServerRuntimeContext()
                .getStanzaRelay();
        StanzaReceiverQueue senderQueue = new StanzaReceiverQueue();
        StanzaReceiverQueue receiverQueue = new StanzaReceiverQueue();
View Full Code Here


        if (rosterItem.getJid() == null)
            throw new RosterException("contact jid not provided");

        // TODO think about concurrent updates

        Entity contactJid = rosterItem.getJid().getBareJID();
        Node contactNode = getOrCreateContactNode(jid, contactJid);
        try {
            setOrRemoveAttribute(contactNode, "name", rosterItem.getName());
            String subscriptionTypeValue = rosterItem.getSubscriptionType() == null ? null : rosterItem
                    .getSubscriptionType().value();
View Full Code Here

    }

    private StanzaHandler getIQHandler(Stanza stanza) {
        StanzaHandler handlerForElement = null;

        Entity to = stanza.getTo();
        Entity serverEntity = (serverRuntimeContext == null) ? null : serverRuntimeContext.getServerEnitity();
        boolean isAddressedToServerOrComponent = (to == null || (!to.isNodeSet() && !to.isResourceSet()));
        boolean isAddressedToComponent = (to != null) && isAddressedToServerOrComponent && serverEntity != null
                && (!serverEntity.equals(to));
        boolean isAddressedToServer = (to == null) || (isAddressedToServerOrComponent && !isAddressedToComponent);

        // The following cases must be properly handled:
        // 1. IQ disco stanza always handled by disco subsystem, not addressee
        // 2. to = someone@vysper.org => relay
View Full Code Here

        assertTrue("closed", sessionContext.isClosed());
    }

    public void testDetectWrongFromAddress() throws XMLSemanticError {

        Entity server = sessionContext.getServerRuntimeContext().getServerEnitity();
        sessionContext.setSessionState(SessionState.AUTHENTICATED);
        // the session is running for 'mark'
        sessionContext.setInitiatingEntity(new EntityImpl("mark", server.getDomain(), null));

        CallTestStanzaHandler stanzaHandler = new CallTestStanzaHandler("iq");
        namespaceHandlerDictionary.register(stanzaHandler);

        StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(null, null, IQStanzaType.GET, "test");
        // we set a different from user name 'ernest'!
        stanzaBuilder.addAttribute("from", new EntityImpl("ernest", server.getDomain(), null).getFullQualifiedName());
        stanzaBuilder.startInnerElement("query", "jabber:iq:roster").endInnerElement();

        protocolWorker.processStanza(sessionContext.getServerRuntimeContext(), sessionContext, stanzaBuilder.build(),
                sessionStateHolder);
View Full Code Here

        assertUnknownSenderError(recordedResponse);
    }

    public void testAllowProperFromResourceId() throws XMLSemanticError, BindException {

        Entity server = sessionContext.getServerRuntimeContext().getServerEnitity();
        sessionContext.setSessionState(SessionState.AUTHENTICATED);
        // the session is running for 'charlotte'
        sessionContext.setInitiatingEntity(new EntityImpl("charlotte", server.getDomain(), null));

        CallTestStanzaHandler stanzaHandler = new CallTestStanzaHandler("iq", "testNSURI");
        namespaceHandlerDictionary.register(stanzaHandler);

        String onlyBoundResource = sessionContext.bindResource();

        StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(null, null, IQStanzaType.GET, "test");
        stanzaBuilder.addAttribute("from", new EntityImpl("charlotte", server.getDomain(), onlyBoundResource)
                .getFullQualifiedName());
        stanzaBuilder.startInnerElement("query", "testNSURI").endInnerElement();

        protocolWorker.processStanza(sessionContext.getServerRuntimeContext(), sessionContext, stanzaBuilder.build(),
                sessionStateHolder);
View Full Code Here

        stanzaHandler.assertHandlerCalled();
    }

    public void testDetectWrongFromResourceId() throws XMLSemanticError, BindException {

        Entity server = sessionContext.getServerRuntimeContext().getServerEnitity();
        sessionContext.setSessionState(SessionState.AUTHENTICATED);
        // the session is running for 'charlotte'
        sessionContext.setInitiatingEntity(new EntityImpl("charlotte", server.getDomain(), null));

        CallTestStanzaHandler stanzaHandler = new CallTestStanzaHandler("iq", "testNSURI");
        namespaceHandlerDictionary.register(stanzaHandler);

        String onlyBoundResource = sessionContext.bindResource();
        String arbitraryUnboundResource = "unboundResourceID";

        StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(null, null, IQStanzaType.GET, "test");

        stanzaBuilder.addAttribute("from", new EntityImpl("charlotte", server.getDomain(), arbitraryUnboundResource)
                .getFullQualifiedName());
        stanzaBuilder.startInnerElement("query", "testNSURI").endInnerElement();

        protocolWorker.processStanza(sessionContext.getServerRuntimeContext(), sessionContext, stanzaBuilder.build(),
                sessionStateHolder);
View Full Code Here

    public void testAllowBareFromEntityOnlyOnSingleBoundResource() throws XMLSemanticError, BindException {
        // from="client@vysper.org" is only allowed when a single resource is bound
        // if there is more than one resource bound in the same session, from must come
        // fully qualified, e.g. from="client@vysper.org/resourceId"

        Entity server = sessionContext.getServerRuntimeContext().getServerEnitity();
        sessionContext.setSessionState(SessionState.AUTHENTICATED);
        // the session is running for 'lea'
        sessionContext.setInitiatingEntity(new EntityImpl("lea", server.getDomain(), null));

        CallTestStanzaHandler stanzaHandler = new CallTestStanzaHandler("iq", "testNSURI");
        namespaceHandlerDictionary.register(stanzaHandler);

        String firstBoundResource = sessionContext.bindResource();
        String secondBoundResource = sessionContext.bindResource();

        StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(null, null, IQStanzaType.GET, "test");
        stanzaBuilder.addAttribute("from", new EntityImpl("lea", server.getDomain(), null).getFullQualifiedName());
        stanzaBuilder.startInnerElement("query", "testNSURI").endInnerElement();

        protocolWorker.processStanza(sessionContext.getServerRuntimeContext(), sessionContext, stanzaBuilder.build(),
                sessionStateHolder);
        Stanza recordedResponse = sessionContext.getNextRecordedResponse();
        assertUnknownSenderError(recordedResponse); // not allowed, bare id without resource and two resources bound
        sessionContext.reset();

        // unbind second resource, leaving only one
        boolean noResourceRemains = sessionContext.getServerRuntimeContext().getResourceRegistry().unbindResource(
                secondBoundResource);
        assertFalse(noResourceRemains);

        // bare id allowed, only one resource is bound
        stanzaBuilder = StanzaBuilder.createIQStanza(null, null, IQStanzaType.GET, "test");
        stanzaBuilder.addAttribute("from", new EntityImpl("lea", server.getDomain(), null).getFullQualifiedName());
        stanzaBuilder.startInnerElement("query", "testNSURI").endInnerElement();
        protocolWorker.processStanza(sessionContext.getServerRuntimeContext(), sessionContext, stanzaBuilder.build(),
                sessionStateHolder);
        stanzaHandler.assertHandlerCalled();
        sessionContext.reset();

        // second resource is now invalid and cannot be used anymore in a full qualified entity
        stanzaBuilder = StanzaBuilder.createIQStanza(null, null, IQStanzaType.GET, "test");
        stanzaBuilder.addAttribute("from", new EntityImpl("lea", server.getDomain(), secondBoundResource)
                .getFullQualifiedName());
        stanzaBuilder.startInnerElement("query", "testNSURI").endInnerElement();
        protocolWorker.processStanza(sessionContext.getServerRuntimeContext(), sessionContext, stanzaBuilder.build(),
                sessionStateHolder);
        recordedResponse = sessionContext.getNextRecordedResponse();
View Full Code Here

        presenceCache.put(getEntity(), getPresenceStanza(initiatingUser));
        assertNotNull(presenceCache.get(getEntity()));
    }

    public void testRemove() {
        Entity entity = getEntity();
        presenceCache.put(entity, getPresenceStanza(initiatingUser));
        presenceCache.remove(entity);

        // It should return null
        assertNull("Entry should be null", presenceCache.get(entity));
View Full Code Here

    }

    @Override
    protected Stanza handleSet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
        // Get From
        Entity to = stanza.getTo();
        Entity from = stanza.getFrom();
        if (from == null) {
            from = sessionContext.getInitiatingEntity();
        }

        // Not null, and not addressed to itself
View Full Code Here

        }
    }

    @Override
    protected Stanza handleGet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
        Entity to = stanza.getTo();
        Entity from = stanza.getFrom();
        if (from == null) {
            from = sessionContext.getInitiatingEntity();
        }

        // Not null, and not addressed to itself
View Full Code Here

TOP

Related Classes of org.apache.vysper.xmpp.addressing.Entity

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.