Search in sources :

Example 21 with PacketError

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

the class SiteTracker method handleInvitation.

private void handleInvitation(IQ packet, Workgroup workgroup) {
    Element iq = packet.getChildElement();
    // Define default values
    IQ update = new IQ();
    Element elem = update.setChildElement("site-invite", "http://jivesoftware.com/protocol/workgroup");
    String sessionID = iq.attribute("sessionID").getText();
    elem.addAttribute("sessionID", sessionID);
    SiteUser siteUser = siteUsers.get(sessionID);
    IQ reply = IQ.createResultIQ(packet);
    if (siteUser == null) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    } else {
        // Send back reply
        workgroup.send(reply);
    }
    String agent = iq.element("agent").getText();
    String message = iq.element("message").getText();
    elem.addElement("agent").setText(agent);
    elem.addElement("message").setText(message);
    update.setTo(siteUser.getJID());
    update.setType(IQ.Type.set);
    workgroup.send(update);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError)

Example 22 with PacketError

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

the class SoundProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    // Retrieve the sound settings.
    String outgoingMessage = workgroup.getProperties().getProperty("outgoingSound");
    String incomingMessage = workgroup.getProperties().getProperty("incomingSound");
    Element soundSetting = reply.setChildElement("sound-settings", "http://jivesoftware.com/protocol/workgroup");
    if (ModelUtil.hasLength(outgoingMessage) && ModelUtil.hasLength(incomingMessage)) {
        soundSetting.addElement("outgoingSound").setText(outgoingMessage);
        soundSetting.addElement("incomingSound").setText(incomingMessage);
    } else {
        // Throw error
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
    }
    workgroup.send(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError)

Example 23 with PacketError

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

the class MacroProvider method executeSet.

public void executeSet(IQ packet, Workgroup workgroup) {
    IQ reply;
    Element iq = packet.getChildElement();
    String personalMacro = iq.element("personalMacro").getTextTrim();
    try {
        // Verify that an agent is requesting this information.
        Agent agent = workgroup.getAgentManager().getAgent(packet.getFrom());
        DbProperties props = agent.getProperties();
        XStream xstream = new XStream();
        xstream.alias("macro", Macro.class);
        xstream.alias("macrogroup", MacroGroup.class);
        MacroGroup group = (MacroGroup) xstream.fromXML(personalMacro);
        String saveString = xstream.toXML(group);
        try {
            props.deleteProperty("personal.macro");
            props.setProperty("personal.macro", saveString);
        } catch (UnauthorizedException e) {
            Log.error(e.getMessage(), e);
        }
        reply = IQ.createResultIQ(packet);
    } 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 : Agent(org.jivesoftware.xmpp.workgroup.Agent) XStream(com.thoughtworks.xstream.XStream) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties)

Example 24 with PacketError

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

the class MacroProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    Element iq = packet.getChildElement();
    String name = iq.getName();
    boolean isPersonal = iq.element("personal") != null;
    Agent agent;
    try {
        agent = workgroup.getAgentManager().getAgent(packet.getFrom());
    } catch (AgentNotFoundException e) {
        sendItemNotFound(packet, workgroup);
        return;
    }
    if ("macros".equals(name) && !isPersonal) {
        Element globalMacros = reply.setChildElement("macros", "http://jivesoftware.com/protocol/workgroup");
        DbProperties props = workgroup.getProperties();
        String macroModel = props.getProperty("jive.macro" + workgroup.getID());
        if (ModelUtil.hasLength(macroModel)) {
            globalMacros.addElement("model").setText(macroModel);
        } else {
            sendItemNotFound(packet, workgroup);
            return;
        }
    } else if (isPersonal) {
        Element personalMacros = reply.setChildElement("macros", "http://jivesoftware.com/protocol/workgroup");
        DbProperties props = agent.getProperties();
        String macroModel = props.getProperty("personal.macro");
        if (ModelUtil.hasLength(macroModel)) {
            personalMacros.addElement("model").setText(macroModel);
        } else {
            sendItemNotFound(packet, workgroup);
            return;
        }
    } else {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    workgroup.send(reply);
}
Also used : Agent(org.jivesoftware.xmpp.workgroup.Agent) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties)

Example 25 with PacketError

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

the class ChatNotes method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply;
    Element iq = packet.getChildElement();
    // Verify that an agent is requesting this information.
    try {
        AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
        if (agentSession != null) {
            String sessionID = iq.element("sessionID").getTextTrim();
            sendNotesPacket(packet, workgroup, sessionID);
        } else {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
            workgroup.send(reply);
        }
    } 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)

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