Package org.jivesoftware.xmpp.workgroup.interceptor

Examples of org.jivesoftware.xmpp.workgroup.interceptor.InterceptorManager


                listeners.remove(packet.getFrom());
            }
            return;
        }

        InterceptorManager interceptorManager = AgentInterceptorManager.getInstance();
        try {
            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, false);
            // Try to update the presence of the AgentSession with the new presence
            AgentSession agentSession = agent.getAgentSession();
            if (agentSession == null) {
                if (!includesExtension) {
                    // Ignote presence packet of agents that have not joined the workgroup
                    // and does not contain the proper extension
                    return;
                }

                // Add new agent session.
                agentSession = agent.createSession(packet.getFrom());
                if (agentSession == null) {
                    // User is not able to join since an existing session from another resource already exists
                    Presence reply = new Presence();
                    reply.setID(packet.getID());
                    reply.setTo(packet.getFrom());
                    reply.setFrom(packet.getTo());
                    reply.setError(PacketError.Condition.not_allowed);
                    workgroup.send(reply);
                    return;
                }
            }

            // Update session's presence with latest presence
            agentSession.updatePresence(packet);
            if (agentSession.getPresence().getType() == null) {
                agentSession.join(workgroup);
            }
            else {
                agentSession.depart(workgroup);
            }

            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, true);
        }
        catch (PacketRejectedException e) {
            workgroup.rejectPacket(packet, e);
        }
    }
View Full Code Here


        }
        return false;
    }

    public void send(Packet packet) {
        InterceptorManager interceptorManager = WorkgroupInterceptorManager.getInstance();
        try {
            interceptorManager.invokeInterceptors(getJID().toBareJID(), packet, false, false);
            WorkgroupManager.getInstance().send(packet);
            interceptorManager.invokeInterceptors(getJID().toBareJID(), packet, false, true);
        }
        catch (PacketRejectedException e) {
            Log.warn("Packet was not sent " +
                "due to interceptor REJECTION: " + packet.toXML(), e);
        }
View Full Code Here

    public void process(Message packet) {
        messageHandler.process(packet);
    }

    public void process(Packet packet) {
        InterceptorManager interceptorManager = WorkgroupInterceptorManager.getInstance();
        try {
            interceptorManager.invokeInterceptors(getJID().toBareJID(), packet, true, false);

            String mucDomain = WorkgroupManager.getInstance().getMUCServiceName();
            if (mucDomain.equals(packet.getFrom().getDomain())) {
                roomActivity(packet);
            }
            else if (packet instanceof Message) {
                process((Message)packet);
            }
            else if (packet instanceof Presence) {
                process((Presence)packet);
            }
            else if (packet instanceof IQ) {
                process((IQ)packet);
            }
            interceptorManager.invokeInterceptors(getJID().toBareJID(), packet, true, true);
        }
        catch (PacketRejectedException e) {
            rejectPacket(packet, e);
        }
    }
View Full Code Here

        reply.setFrom(workgroup.getJID());
        String queryName = iq.getName();
        String queryNamespace = iq.getNamespace().toString();

        if ("join-queue".equals(queryName)) {
            InterceptorManager interceptorManager = QueueInterceptorManager.getInstance();
            try {
                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true,
                        false);
                // Received a Join Queue request from a visitor, create a new request.
                UserRequest request = new UserRequest(packet, workgroup);
                // Let the workgroup process the new request
                if (!workgroup.queueRequest(request)) {
                    // It was not possible to add the request to a queue so answer that the
                    // workgroup is not accepting new join-queue requests
                    reply.setChildElement(packet.getChildElement().createCopy());
                    reply.setError(new PacketError(PacketError.Condition.service_unavailable));
                }
                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true,
                        true);
            }
            catch (PacketRejectedException e) {
                workgroup.rejectPacket(packet, e);
                reply = null;
            }
        }
        else if ("depart-queue".equals(queryName)) {
            // Visitor is departing queue
            try {
                Request request = UserRequest.getRequest(workgroup, sender);
                InterceptorManager interceptorManager = QueueInterceptorManager.getInstance();
                try {
                    interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet,
                            true, false);
                    request.cancel(Request.CancelType.DEPART);
                    iq.add(request.getSessionElement());
                    interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet,
                            true, true);
                }
                catch (PacketRejectedException e) {
                    workgroup.rejectPacket(packet, e);
                    reply = null;
                }
            }
            catch (NotFoundException e) {
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
                Log.debug("Request not found" +
                        " while departing queue:", e);
            }
        }
        else if ("offer-accept".equals(queryName)) {
            try {
                InterceptorManager interceptorManager = OfferInterceptorManager.getInstance();
                String id = iq.attributeValue("id");
                String jid = iq.attributeValue("jid");
                if (id != null || jid  != null) {
                    Request request;
                    if (id != null) {
                        // Search request by its unique ID
                        request = Request.getRequest(id);
                    }
                    else  {
                        // Old version of FP refers to requests by the user's jid. This old version
                        // implements transfers and invitations on the client and not the server side.
                        // Therefore, for each user's jid there is always a unique Request
                        request = UserRequest.getRequest(workgroup, new JID(jid));
                    }
                    Offer offer = request.getOffer();
                    if (offer != null && offer.isOutstanding()) {
                        AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
                        if (agentSession == null) {
                            reply.setChildElement(packet.getChildElement().createCopy());
                            reply.setError(new PacketError(PacketError.Condition.item_not_found));
                            Log
                                    .debug("Agent not found while accepting offer");
                        }
                        else {
                            try {
                                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(),
                                        packet, true, false);
                                offer.accept(agentSession);
                                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(),
                                        packet, true, true);
                            }
                            catch (PacketRejectedException e) {
                                workgroup.rejectPacket(packet, e);
                                reply = null;
                            }
                        }
                    }
                    else {
                        reply.setChildElement(packet.getChildElement().createCopy());
                        reply.setError(new PacketError(PacketError.Condition.not_acceptable));
                    }
                }
            }
            catch (NotFoundException e) {
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
                Log.debug("Request not found " +
                        "while accepting offer: ", e);
            }
            catch (AgentNotFoundException e) {
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
                Log.debug("Agent not found " +
                        "while accepting offer: ", e);
            }
        }
        else if ("offer-reject".equals(queryName)) {
            try {
                InterceptorManager interceptorManager = OfferInterceptorManager.getInstance();
                String id = iq.attributeValue("id");
                String jid = iq.attributeValue("jid");
                if (id != null || jid  != null) {
                    Request request;
                    if (id != null) {
                        // Search request by its unique ID
                        request = Request.getRequest(id);
                    }
                    else  {
                        // Old version of FP refers to requests by the user's jid. This old version
                        // implements transfers and invitations on the client and not the server side.
                        // Therefore, for each user's jid there is always a unique Request
                        request = UserRequest.getRequest(workgroup, new JID(jid));
                    }
                    Offer offer = request.getOffer();
                    if (offer != null) {
                        AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
                        if (agentSession == null) {
                            reply.setChildElement(packet.getChildElement().createCopy());
                            reply.setError(new PacketError(PacketError.Condition.item_not_found));
                            Log
                                    .debug("Agent not found while accepting offer");
                        }
                        else {
                            try {
                                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(),
                                        packet, true, false);
                                offer.reject(agentSession);
                                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(),
                                        packet, true, true);
                            }
                            catch (PacketRejectedException e) {
                                workgroup.rejectPacket(packet, e);
                                reply = null;
View Full Code Here

     *
     * @param session the session whose owner (i.e. user) sent the message.
     * @param message message sent by the owner of the session to the workgroup.
     */
    public void onMessage(ChatbotSession session, Message message) {
        InterceptorManager interceptorManager = ChatbotInterceptorManager.getInstance();
        try {
            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), message, true,
                    false);

            // Update the Message thread that the user is using in the session
            session.setMessageThread(message.getThread());
            // Check if the workgroup is opened
            synchronized(session) {
                if (workgroup.getStatus() != Workgroup.Status.OPEN) {
                    // Send message saying that the workgroup is closed/not available
                    sendReply(message, getWorkgroupClosedMessage());
                }
                else if (handleCommand(message, session)) {
                    // The sent message executed a command so do nothing
                }
                else if (session.getCurrentStep() < 0) {
                    // Send the welcome message
                    sendWelcomeMessage(message);
                    // Send the join question
                    sendJoinQuestion(message, session);
                }
                else if (session.getCurrentStep() == 1) {
                    // User is answering join question
                    if (yes.equalsIgnoreCase(message.getBody().trim())) {
                        // User accepted to join the workgroup so send the first question of
                        // the form
                        userAcceptedJoining(message, session);
                    }
                    else if (no.equalsIgnoreCase(message.getBody().trim())) {
                        // User rejected to join the workgroup so send a goodbye message and close
                        // the chat session
                        closeSession(message);
                    }
                    else {
                        // The user sent an unknown answer so repeat the join question
                        sendJoinQuestion(message, session);
                    }
                }
                else if (session.getCurrentStep() == 2) {
                    // User is filling out the form
                    if (userAnsweredField(message, session)) {
                        // User answered correctly the question so send the next question or if the
                        // form has been filled out then join the queue
                        if (session.getCurrentSubstep() < getForm().getFormElements().size()-1) {
                            sendNextQuestion(message, session);
                        }
                        else {
                            userJoinQueue(message, session);
                        }
                    }
                    else {
                        // The user sent an unknown answer so repeat the last question
                        repeatQuestion(message, session);
                    }
                }
                else if (session.getCurrentStep() == 4) {
                    // User is answering if he wants to get another room invitation
                    if (yes.equalsIgnoreCase(message.getBody().trim())) {
                        // User accepted to receive another room invitation so send another
                        // room invitation
                        sendRoomInvitation(message, session);
                    }
                    else if (no.equalsIgnoreCase(message.getBody().trim())) {
                        // User declined to receive another room invitation so do nothing
                    }
                    else {
                        // The user sent an unknown answer so repeat the invitation question
                        sendInvitationQuestion(message.getFrom(), session);
                    }
                }
                else if (session.getCurrentStep() == 6) {
                    // User is answering email question
                    if (yes.equalsIgnoreCase(message.getBody().trim())) {
                        // User accepted to receive the transcript by email
                        List<String> emailValue = session.getAttributes().get("email");
                        if (emailValue == null || emailValue.isEmpty()) {
                            // The user wants to get the transcript by email but he hasn't provided
                            // an email yet so ask for one
                            sendGetEmailQuestion(message, session);
                        }
                        else {
                            // Send the transcript by email
                            sendTranscriptByMail(emailValue.get(0), message, session);
                            // Send a goodbye message and close the chat session
                            closeSession(message);
                        }
                    }
                    else if (no.equalsIgnoreCase(message.getBody().trim())) {
                        // User rejected to receive the transcript by email so send a goodbye
                        // message and close the chat session
                        closeSession(message);
                    }
                    else {
                        // The user sent an unknown answer so repeat the email question
                        sendEmailQuestion(message.getFrom(), session);
                    }
                }
                else if (session.getCurrentStep() == 7) {
                    // Send the transcript by email
                    sendTranscriptByMail(message.getBody().trim(), message, session);
                    // Send a goodbye message and close the chat session
                    closeSession(message);
                }
                else {
                    // User is waiting in a queue and the sent message contains an unkown content
                    // so send message saying that the command was not acceptable (i.e. unknown command)
                    sendReply(message, getNotAcceptableMessage());
                }
            }
            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), message, true,
                    true);
        }
        catch (PacketRejectedException e) {
            workgroup.rejectPacket(message, e);
        }
View Full Code Here

            workgroup.rejectPacket(message, e);
        }
    }

    private void userJoinQueue(Message message, ChatbotSession session) {
        InterceptorManager interceptorManager = QueueInterceptorManager.getInstance();
        try {
            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), message, true,
                    false);
            if (getRoutingMessage() != null && getRoutingMessage().length() > 0) {
                sendReply(message, getRoutingMessage());
            }
            // Set that we are currently joining a waiting queue
            session.setCurrentStep(3);

            // Received a Join Queue request from a visitor, create a new request.
            UserRequest request = new UserRequest(session, workgroup);
            // Let the workgroup process the new request
            if (!workgroup.queueRequest(request)) {
                // It was not possible to add the request to a queue so send message saying that
                // the workgroup is not accepting new join requests
                sendReply(message, getCannotJoinMessage());
                // Send the goodbye message and close the session
                closeSession(message);
            }
            else {
                session.setRequest(request);
            }
            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), message, true,
                    true);
        }
        catch (PacketRejectedException e) {
            workgroup.rejectPacket(message, e);
        }
View Full Code Here

    private void userDepartQueue(Message message) {
        // Remove the user from the queue if he was waiting in the queue
        try {
            Request request = UserRequest.getRequest(workgroup, message.getFrom());
            InterceptorManager interceptorManager = QueueInterceptorManager.getInstance();
            try {
                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), message, true,
                        false);
                request.cancel(Request.CancelType.DEPART);
                // Remove the session (the goodbye message is sent when leaving the queue)
                removeSession(message.getFrom());
                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), message, true,
                        true);
            }
            catch (PacketRejectedException e) {
                workgroup.rejectPacket(message, e);
            }
View Full Code Here

        packet.setBody(body);
        send(packet);
    }

    private void send(Message packet) {
        InterceptorManager interceptorManager = ChatbotInterceptorManager.getInstance();
        try {
            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, false,
                    false);
            workgroup.send(packet);
            interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, false,
                    true);
        }
        catch (PacketRejectedException e) {
            Log.warn("Packet was not sent " +
                    "due to interceptor REJECTION: " + packet.toXML(), e);
View Full Code Here

        }

        try {
            offer.addPendingSession(this);

            InterceptorManager interceptorManager = OfferInterceptorManager.getInstance();
            try {
                Workgroup workgroup = offer.getRequest().getWorkgroup();
                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(),
                    offerPacket, false, false);
                // Send the Offer to the agent
                WorkgroupManager.getInstance().send(offerPacket);
                interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(),
                    offerPacket, false, true);
            }
            catch (PacketRejectedException e) {
                Log.warn("Offer was not sent " +
                    "due to interceptor REJECTION: " + offerPacket.toXML(), e);
View Full Code Here

TOP

Related Classes of org.jivesoftware.xmpp.workgroup.interceptor.InterceptorManager

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.