Search in sources :

Example 11 with PacketError

use of org.xmpp.packet.PacketError in project Openfire by igniterealtime.

the class ChatNotes method executeSet.

public void executeSet(IQ packet, Workgroup workgroup) {
    IQ reply;
    Element iq = packet.getChildElement();
    try {
        // Verify that an agent is requesting this information.
        AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
        if (agentSession != null) {
            String sessionID = iq.element("sessionID").getTextTrim();
            Element notes = iq.element("notes");
            String noteText = notes.getTextTrim();
            appendNote(sessionID, noteText);
            reply = IQ.createResultIQ(packet);
        } else {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
        }
    } catch (AgentNotFoundException e) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
    }
    workgroup.send(reply);
}
Also used : AgentSession(org.jivesoftware.xmpp.workgroup.AgentSession) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException)

Example 12 with PacketError

use of org.xmpp.packet.PacketError in project Openfire by igniterealtime.

the class SiteTracker method handleUserHistoryRequest.

private void handleUserHistoryRequest(IQ packet, Workgroup workgroup) {
    IQ reply;
    Element iq = packet.getChildElement();
    try {
        AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
        if (agentSession == null) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.not_authorized));
            workgroup.send(reply);
            return;
        }
    } catch (AgentNotFoundException e) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.not_authorized));
        workgroup.send(reply);
        return;
    }
    // Define default values
    String sessionID = iq.attribute("sessionID").getText();
    reply = IQ.createResultIQ(packet);
    Element views = reply.setChildElement("site-user-history", "http://jivesoftware.com/protocol/workgroup");
    views.addAttribute("sessionID", sessionID);
    SiteUser siteUser = siteUsers.get(sessionID);
    if (siteUser != null) {
        for (PageView view : siteUser.getViews()) {
            Element pageView = views.addElement("page-view");
            pageView.addElement("title").setText(view.getTitle());
            pageView.addElement("url").setText(view.getUrl());
            pageView.addElement("time").setText(Long.toString(view.getTimeViewed()));
        }
        workgroup.send(reply);
    }
}
Also used : AgentSession(org.jivesoftware.xmpp.workgroup.AgentSession) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException)

Example 13 with PacketError

use of org.xmpp.packet.PacketError in project Openfire by igniterealtime.

the class EmailProvider method executeSet.

public void executeSet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    Element iq = packet.getChildElement();
    String from = iq.element("fromAddress").getTextTrim();
    String to = iq.element("toAddress").getTextTrim();
    String subject = iq.element("subject").getTextTrim();
    String body = iq.element("message").getTextTrim();
    // Need to replace the \\n for \n to allow for text sending.
    body = body.replace("\\n", "\n");
    String html = iq.element("useHTML").getTextTrim();
    boolean useHTML = false;
    if ("true".equals(html)) {
        useHTML = true;
    }
    String sessionID = null;
    if (iq.element("sessionID") != null) {
        sessionID = iq.element("sessionID").getTextTrim();
    }
    // Handle missing information.
    if (!ModelUtil.hasLength(from) || !ModelUtil.hasLength(to) || !ModelUtil.hasLength(subject) || (!ModelUtil.hasLength(body) && !ModelUtil.hasLength(sessionID))) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.not_acceptable));
        workgroup.send(reply);
        return;
    }
    if (ModelUtil.hasLength(sessionID)) {
        ChatTranscriptManager.sendTranscriptByMail(sessionID, to);
    } else {
        EmailService emailService = EmailService.getInstance();
        if (!useHTML) {
            emailService.sendMessage(null, to, null, from, subject, body, null);
        } else {
            emailService.sendMessage(null, to, null, from, subject, null, body);
        }
    }
    workgroup.send(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError) EmailService(org.jivesoftware.util.EmailService)

Example 14 with PacketError

use of org.xmpp.packet.PacketError in project Openfire by igniterealtime.

the class MonitorProvider method executeSet.

public void executeSet(IQ packet, Workgroup workgroup) {
    IQ reply = null;
    Element iq = packet.getChildElement();
    try {
        JID from = packet.getFrom();
        String bareJID = from.toBareJID();
        if (!isOwner(bareJID, workgroup)) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.forbidden));
            workgroup.send(reply);
            return;
        }
        // Verify that an agent is requesting this information.
        WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
        if (iq.element("makeOwner") != null) {
            String sessionID = iq.element("makeOwner").attributeValue("sessionID");
            final String serviceName = workgroupManager.getMUCServiceName();
            final String roomName = sessionID + "@" + serviceName;
            // final String roomJID = roomName + "/" + workgroup.getJID().getNode();
            IQ iqPacket = new IQ(IQ.Type.set);
            iqPacket.setTo(roomName);
            iqPacket.setFrom(workgroup.getFullJID());
            Element query = iqPacket.setChildElement("query", "http://jabber.org/protocol/muc#admin");
            Element item = query.addElement("item");
            item.addAttribute("affiliation", "owner");
            item.addAttribute("jid", packet.getFrom().toBareJID());
            workgroup.send(iqPacket);
        }
        reply = IQ.createResultIQ(packet);
    } catch (Exception e) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
    }
    workgroup.send(reply);
}
Also used : JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager)

Example 15 with PacketError

use of org.xmpp.packet.PacketError in project Openfire by igniterealtime.

the class SearchProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    // Retrieve the web chat setting.
    String kbURL = workgroup.getProperties().getProperty("kb");
    String forumURL = workgroup.getProperties().getProperty("forums");
    // Check that the sender of this IQ is an agent
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    try {
        workgroupManager.getAgentManager().getAgent(packet.getFrom());
    } catch (AgentNotFoundException e) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    Element searchSetting = reply.setChildElement("search-settings", "http://jivesoftware.com/protocol/workgroup");
    if (forumURL != null) {
        searchSetting.addElement("forums").setText(forumURL);
    }
    if (kbURL != null) {
        searchSetting.addElement("kb").setText(kbURL);
    }
    workgroup.send(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager)

Aggregations

PacketError (org.xmpp.packet.PacketError)35 IQ (org.xmpp.packet.IQ)31 Element (org.dom4j.Element)29 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)10 JID (org.xmpp.packet.JID)7 AgentSession (org.jivesoftware.xmpp.workgroup.AgentSession)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 File (java.io.File)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)2 NotFoundException (org.jivesoftware.util.NotFoundException)2 Agent (org.jivesoftware.xmpp.workgroup.Agent)2 DbProperties (org.jivesoftware.xmpp.workgroup.DbProperties)2 WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)2 PacketRejectedException (org.jivesoftware.xmpp.workgroup.interceptor.PacketRejectedException)2 UserRequest (org.jivesoftware.xmpp.workgroup.request.UserRequest)2