Search in sources :

Example 26 with PacketError

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

the class ChatNotes method sendNotesPacket.

/**
     * Retrieves note from Fastpath.
     *
     * @param packet the associated IQ Packet.
     * @param workgroup the workgroup the request came from.
     * @param sessionID the sessionID the note is mapped to.
     */
public void sendNotesPacket(IQ packet, Workgroup workgroup, String sessionID) {
    IQ reply = IQ.createResultIQ(packet);
    // Retrieve the web chat setting.
    String notes = getNotes(sessionID);
    if (notes == null) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    Element note = reply.setChildElement("chat-notes", "http://jivesoftware.com/protocol/workgroup");
    note.addElement("sessionID").setText(sessionID);
    note.addElement("text").setText(notes);
    workgroup.send(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError)

Example 27 with PacketError

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

the class MetadataProvider method executeGet.

/**
     * Executed if #handleGet returned true. This is responsible for sending
     * information back to the client.
     *
     * @param packet    the IQ GET packet sent to the server.
     * @param workgroup the Workgroup the packet was sent to.
     */
public void executeGet(IQ packet, Workgroup workgroup) {
    // Create the generic reply packet.
    IQ reply = IQ.createResultIQ(packet);
    // Check that the sender of this IQ is an agent. If so
    // we throw an item not found exception.
    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;
    }
    // If the sender of the packet is an agent, send back name-value pairs
    // of all properties files specified.
    final Map<String, String> map = new HashMap<String, String>();
    final List<String> configFiles = JiveGlobals.getProperties("config");
    for (String fileName : configFiles) {
        File file = new File(fileName);
        if (file.exists()) {
            // load properties file.
            Properties props = new Properties();
            try {
                props.load(new FileInputStream(file));
                Enumeration<?> properties = props.propertyNames();
                while (properties.hasMoreElements()) {
                    String key = (String) properties.nextElement();
                    String value = props.getProperty(key);
                    map.put(key, value);
                }
            } catch (IOException e) {
                Log.error(e.getMessage(), e);
            }
        }
    }
    //  It is VERY IMPORTANT that you use the same name and namespace as the sending packet. Otherwise,
    //  it would never be mapped correctly.
    final Element genericSetting = reply.setChildElement("generic-metadata", "http://jivesoftware.com/protocol/workgroup");
    for (Map.Entry<String, String> entry : map.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        // Create a name-value element
        Element element = genericSetting.addElement("entry");
        element.addElement("name").setText(key);
        element.addElement("value").setText(value);
    }
    // Send back new packet with requested information.
    workgroup.send(reply);
}
Also used : HashMap(java.util.HashMap) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) IOException(java.io.IOException) Properties(java.util.Properties) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) FileInputStream(java.io.FileInputStream) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 28 with PacketError

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

the class ChatSettingsManager method getChatSettingByKey.

/**
     * Send a single WebChat setting a given workgroup.
     *
     * @param packet the original packet that made the request.
     * @param workgroup the workgroup the packet was sent to.
     * @param key the mapped setting key.
     */
public void getChatSettingByKey(IQ packet, Workgroup workgroup, String key) {
    IQ reply = IQ.createResultIQ(packet);
    // Retrieve the web chat setting.
    ChatSetting setting = getChatSetting(workgroup, key);
    if (setting == null) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    Element webSettings = reply.setChildElement("chat-settings", "http://jivesoftware.com/protocol/workgroup");
    Element root = webSettings.addElement("chat-setting");
    root.addElement("key").setText(setting.getKey().toString());
    root.addElement("value").setText(setting.getValue());
    root.addElement("type").setText(Integer.toString(setting.getType().getType()));
    workgroup.send(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError)

Example 29 with PacketError

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

the class ChatSettingsManager method getAllChatSettings.

/**
     * Send all WebChat settings for a particular Workgroup.
     *
     * @param packet    the original packet that made the request.
     * @param workgroup the workgroup the packet was sent to.
     */
public void getAllChatSettings(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    // Retrieve the web chat setting.
    ChatSettings chatSettings = getChatSettings(workgroup);
    if (chatSettings == null) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    Element webSettings = reply.setChildElement("chat-settings", "http://jivesoftware.com/protocol/workgroup");
    for (ChatSetting setting : chatSettings.getChatSettings()) {
        Element root = webSettings.addElement("chat-setting");
        try {
            root.addElement("key").setText(setting.getKey().toString());
            root.addElement("value").setText(setting.getValue());
            root.addElement("type").setText(Integer.toString(setting.getType().getType()));
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
    workgroup.send(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError)

Example 30 with PacketError

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

the class WorkgroupIQHandler method handleIQGet.

private void handleIQGet(IQ packet) {
    IQ reply = null;
    // TODO: verify namespace and send error if wrong
    Element iq = packet.getChildElement();
    UserRequest request;
    final WorkgroupStats stats = new WorkgroupStats(workgroup);
    String name = iq.getName();
    String namespace = iq.getNamespaceURI();
    if ("queue-status".equals(name)) {
        try {
            request = UserRequest.getRequest(workgroup, packet.getFrom());
            request.updateQueueStatus(true);
        } catch (NotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
        }
    } else if ("transcripts".equals(name)) {
        try {
            // Otherwise return a not_authorized
            if (agentManager.getAgentSession(packet.getFrom()) == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.not_authorized));
            } else {
                String userID = iq.attributeValue("userID");
                stats.getChatTranscripts(packet, userID);
            }
        } catch (AgentNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.not_authorized));
        }
    } else if ("transcript".equals(name)) {
        try {
            // Otherwise return a not_authorized
            if (agentManager.getAgentSession(packet.getFrom()) == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.not_authorized));
            } else {
                String sessionID = iq.attributeValue("sessionID");
                stats.getChatTranscript(packet, sessionID);
            }
        } catch (AgentNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.not_authorized));
        }
    } else if ("agent-status-request".equals(name)) {
        try {
            AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
            if (agentSession == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
            } else {
                agentSession.sendAgentsInWorkgroup(packet, workgroup);
            }
        } catch (AgentNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
        }
    } else if ("agent-info".equals(name)) {
        try {
            // Send the agent's info to the session that requested its own information
            AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
            if (agentSession == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.item_not_found));
            } else {
                agentSession.sendAgentInfo(packet);
            }
        } catch (AgentNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
        }
    } else if ("occupants-info".equals(name)) {
        try {
            // Just check that the packet was sent by a logged agent to this workgroup
            AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
            if (agentSession == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.not_authorized));
            } else {
                // Send information about the occupants of the requested room
                String roomID = iq.attributeValue("roomID");
                workgroup.sendOccupantsInfo(packet, roomID);
            }
        } catch (AgentNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.not_authorized));
        }
    } else if ("chat-settings".equals(name)) {
        ChatSettingsManager chatSettingsManager = ChatSettingsManager.getInstance();
        String key = iq.attributeValue("key");
        String type = iq.attributeValue("type");
        if (ModelUtil.hasLength(key)) {
            chatSettingsManager.getChatSettingByKey(packet, workgroup, key);
        } else if (ModelUtil.hasLength(type)) {
            try {
                int typeInt = Integer.parseInt(type);
                chatSettingsManager.getChatSettingsByType(packet, workgroup, typeInt);
            } catch (NumberFormatException e) {
            // Bad type.
            }
        } else {
            chatSettingsManager.getAllChatSettings(packet, workgroup);
        }
    } else if ("jabber:iq:private".equals(namespace)) {
        // IQ private for agents global macro storage
        getIQPrivate(packet);
    } else if ("vcard-temp".equals(namespace)) {
        // Return workgroup's VCard
        getVCard(packet);
    } else {
        // none are found, send bad request error.
        for (WorkgroupProvider provider : providerManager.getWorkgroupProviders()) {
            // Will provider handle the GET
            if (provider.handleGet(packet)) {
                // Pass off packet
                provider.executeGet(packet, workgroup);
                return;
            }
        }
        dropPacket(packet);
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.bad_request));
    }
    if (reply != null) {
        workgroup.send(reply);
    }
}
Also used : ChatSettingsManager(org.jivesoftware.openfire.fastpath.settings.chat.ChatSettingsManager) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) NotFoundException(org.jivesoftware.util.NotFoundException) PacketError(org.xmpp.packet.PacketError) UserRequest(org.jivesoftware.xmpp.workgroup.request.UserRequest)

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