Package org.apache.vysper.xmpp.addressing

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


        rosterManager = new MemoryRosterManager();
        OpenStorageProviderRegistry storageProviderRegistry = new OpenStorageProviderRegistry();
        storageProviderRegistry.add(rosterManager);
        ((DefaultServerRuntimeContext) sessionContext.getServerRuntimeContext()).setStorageProviderRegistry(storageProviderRegistry);

        Entity client = EntityImpl.parse("tester@vysper.org");
        sessionContext.setInitiatingEntity(client);
        initiatingUser = TestUser.createForSession(sessionContext, client);

        // set up more resources for the same session
        anotherInterestedNotAvailUser = TestUser.createForSession(sessionContext, client);
View Full Code Here


    protected Stanza executeMessageLogic(MessageStanza stanza,
            ServerRuntimeContext serverRuntimeContext,
            SessionContext sessionContext) {

        logger.debug("Received message for MUC");
        Entity from = stanza.getFrom();
        Entity roomWithNickJid = stanza.getTo();
        Entity roomJid = roomWithNickJid.getBareJID();

        MessageStanzaType type = stanza.getMessageType();
        if(type != null && type == MessageStanzaType.GROUPCHAT) {
            // groupchat, message to a room

            // must not have a nick
            if(roomWithNickJid.getResource() != null) {
                return createMessageErrorStanza(roomJid, from, stanza.getID(), StanzaErrorType.MODIFY, StanzaErrorCondition.BAD_REQUEST, stanza);
            }
           
            logger.debug("Received groupchat message to {}", roomJid);
            Room room = conference.findRoom(roomJid);
            if(room != null) {
                Occupant sendingOccupant = room.findOccupantByJID(from);
               
                // sender must be participant in room
                if(sendingOccupant != null) {
                   
                    Entity roomAndSendingNick = new EntityImpl(room.getJID(), sendingOccupant.getName());
                    if(sendingOccupant.hasVoice()) {
                        // relay message to all occupants in room
                       
                        try {
                            if(stanza.getSubjects() != null && !stanza.getSubjects().isEmpty()) {
                                // subject message
                                if(!room.isRoomType(RoomType.OpenSubject) && !sendingOccupant.isModerator()) {
                                    // room only allows moderators to change the subject, and sender is not a moderator
                                    return createMessageErrorStanza(room.getJID(), from, stanza.getID(), StanzaErrorType.AUTH, StanzaErrorCondition.FORBIDDEN, stanza);
                                }
                            }
                        } catch (XMLSemanticError e) {
                            // not a subject message, ignore exception
                        }
                       
                        logger.debug("Relaying message to all room occupants");
                        for(Occupant occupent : room.getOccupants()) {
                            logger.debug("Relaying message to  {}", occupent);
                            List<Attribute> replaceAttributes = new ArrayList<Attribute>();
                            replaceAttributes.add(new Attribute("from", roomAndSendingNick.getFullQualifiedName()));
                            replaceAttributes.add(new Attribute("to", occupent.getJid().getFullQualifiedName()));
                           
                            relayStanza(occupent.getJid(),
                                    StanzaBuilder.createClone(stanza, true, replaceAttributes).build(),
                                    serverRuntimeContext);
                           
                        }
                       
                        // add to discussion history
                        room.getHistory().append(stanza, sendingOccupant);
                    } else {
                        return createMessageErrorStanza(room.getJID(), from, stanza.getID(), StanzaErrorType.MODIFY, StanzaErrorCondition.FORBIDDEN, stanza);
                    }
                } else {
                    return createMessageErrorStanza(room.getJID(), from, stanza.getID(), StanzaErrorType.MODIFY, StanzaErrorCondition.NOT_ACCEPTABLE, stanza);
                }
            } else {
                return createMessageErrorStanza(moduleDomain, from, stanza.getID(), StanzaErrorType.MODIFY, StanzaErrorCondition.ITEM_NOT_FOUND, stanza);
            }
        } else if(type == null  || type == MessageStanzaType.CHAT || type == MessageStanzaType.NORMAL) {
            // private message
            logger.debug("Received direct message to {}", roomWithNickJid);
            Room room = conference.findRoom(roomJid);
            if(room != null) {
                Occupant sendingOccupant = room.findOccupantByJID(from);
               
                // sender must be participant in room
                    if(roomWithNickJid.isResourceSet()) {
                        if(sendingOccupant != null) {
                            // got resource, private message for occupant
                            Occupant receivingOccupant = room.findOccupantByNick(roomWithNickJid.getResource());
                           
                            // must be sent to an existing occupant in the room
                            if(receivingOccupant != null) {
                               
                                Entity roomAndSendingNick = new EntityImpl(room.getJID(), sendingOccupant.getName());
                                logger.debug("Relaying message to  {}", receivingOccupant);
                                List<Attribute> replaceAttributes = new ArrayList<Attribute>();
                                replaceAttributes.add(new Attribute("from", roomAndSendingNick.getFullQualifiedName()));
                                replaceAttributes.add(new Attribute("to", receivingOccupant.getJid().getFullQualifiedName()));
                               
                                relayStanza(receivingOccupant.getJid(),
                                        StanzaBuilder.createClone(stanza, true, replaceAttributes).build(),
                                        serverRuntimeContext);
View Full Code Here

    public void testCreateDuplicateRooms() throws Exception {
        Conference conference = new Conference("foo");
        conference.createRoom(jid1, "room1");
        try {
            // make sure we use a different JID instance
            Entity duplicateJID = EntityImpl.parse("jid1@vysper.org");

            conference.createRoom(duplicateJID, "room1");
            fail("Expecting IllegalArgumentException");
        } catch(IllegalArgumentException e) {
            // ok
View Full Code Here

    }
   
    @Override
    protected Stanza executePresenceLogic(PresenceStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
        // TODO handle null
        Entity roomAndNick = stanza.getTo();

        Entity occupantJid = stanza.getFrom();
       
        Entity roomJid = roomAndNick.getBareJID();
        String nick = roomAndNick.getResource();
       
        // user did not send nick name
        if(nick == null) {
            return createPresenceErrorStanza(roomJid, occupantJid, stanza.getID(), "modify", "jid-malformed");
View Full Code Here

        // do not send own presence
        if(existingOccupant.getJid().equals(newOccupant.getJid())) {
            return;
        }
       
        Entity roomAndOccupantNick = new EntityImpl(room.getJID(), existingOccupant.getName());
        StanzaBuilder builder = StanzaBuilder.createPresenceStanza(roomAndOccupantNick, newOccupant.getJid(), null, null, null, null);
       
        builder.addPreparedElement(new X(NamespaceURIs.XEP0045_MUC_USER,
                new Item(null, null, existingOccupant.getAffiliation(), existingOccupant.getRole())));
View Full Code Here

        logger.debug("Room presence from {} sent to {}", newOccupant, roomAndOccupantNick);
        relayStanza(newOccupant.getJid(), builder.build(), serverRuntimeContext);
    }
   
    private void sendNewOccupantPresenceToExisting(Occupant newOccupant, Occupant existingOccupant, Room room, ServerRuntimeContext serverRuntimeContext) {
        Entity roomAndNewUserNick = new EntityImpl(room.getJID(), newOccupant.getName());
       
        StanzaBuilder builder = StanzaBuilder.createPresenceStanza(roomAndNewUserNick, existingOccupant.getJid(), null, null, null, null);
       
        List<XMLElement> inner = new ArrayList<XMLElement>();
View Full Code Here

        logger.debug("Room presence from {} sent to {}", roomAndNewUserNick, existingOccupant);
        relayStanza(existingOccupant.getJid(), builder.build(), serverRuntimeContext);
    }

    private void sendChangeNickUnavailable(Occupant changer, String oldNick, Occupant receiver, Room room, ServerRuntimeContext serverRuntimeContext) {
        Entity roomAndOldNick = new EntityImpl(room.getJID(), oldNick);
       
        StanzaBuilder builder = StanzaBuilder.createPresenceStanza(roomAndOldNick, receiver.getJid(), null,
                PresenceStanzaType.UNAVAILABLE, null, null);
       
        List<XMLElement> inner = new ArrayList<XMLElement>();
View Full Code Here

        relayStanza(receiver.getJid(), builder.build(), serverRuntimeContext);
    }
   

    private void sendChangeShowStatus(Occupant changer, Occupant receiver, Room room, String show, String status, ServerRuntimeContext serverRuntimeContext) {
        Entity roomAndNick = new EntityImpl(room.getJID(), changer.getName());
       
        StanzaBuilder builder = StanzaBuilder.createPresenceStanza(roomAndNick, receiver.getJid(), null,
                null, show, status);
       
        boolean includeJid = includeJidInItem(room, receiver);
View Full Code Here

     // room is non-anonymous or semi-anonmoys and the occupant a moderator, send full user JID
        return room.getRoomTypes().contains(RoomType.NonAnonymous) ||
            (room.getRoomTypes().contains(RoomType.SemiAnonymous) && receiver.getRole() == Role.Moderator);
    }
    private void sendChangeNickAvailable(Occupant changer, Occupant receiver, Room room, ServerRuntimeContext serverRuntimeContext) {
        Entity roomAndOldNick = new EntityImpl(room.getJID(), changer.getName());
       
        StanzaBuilder builder = StanzaBuilder.createPresenceStanza(roomAndOldNick, receiver.getJid(), null, null, null, null);
       
        List<XMLElement> inner = new ArrayList<XMLElement>();
        boolean includeJid = includeJidInItem(room, receiver)
View Full Code Here

    }

   
    private void sendExitRoomPresenceToExisting(Occupant exitingOccupant, Occupant existingOccupant, Room room,
            String statusMessage, ServerRuntimeContext serverRuntimeContext) {
        Entity roomAndNewUserNick = new EntityImpl(room.getJID(), exitingOccupant.getName());
       
        StanzaBuilder builder = StanzaBuilder.createPresenceStanza(roomAndNewUserNick, existingOccupant.getJid(), null,
                PresenceStanzaType.UNAVAILABLE, null, null);

        List<XMLElement> inner = new ArrayList<XMLElement>();
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.