Search in sources :

Example 6 with PacketError

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

the class OfflineSettingsProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    OfflineSettingsManager offlineSettingsManager = new OfflineSettingsManager();
    OfflineSettings settings;
    try {
        settings = offlineSettingsManager.getOfflineSettings(workgroup);
    } catch (OfflineSettingsNotFound offlineSettingsNotFound) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    Element offline = reply.setChildElement("offline-settings", "http://jivesoftware.com/protocol/workgroup");
    if (ModelUtil.hasLength(settings.getRedirectURL())) {
        offline.addElement("redirectPage").setText(settings.getRedirectURL());
    } else {
        offline.addElement("emailAddress").setText(settings.getEmailAddress());
        offline.addElement("offlineText").setText(settings.getOfflineText());
        offline.addElement("subject").setText(settings.getSubject());
    }
    workgroup.send(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError)

Example 7 with PacketError

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

the class MacroProvider method sendItemNotFound.

private void sendItemNotFound(IQ packet, Workgroup workgroup) {
    IQ reply;
    reply = IQ.createResultIQ(packet);
    reply.setChildElement(packet.getChildElement().createCopy());
    reply.setError(new PacketError(PacketError.Condition.item_not_found));
    workgroup.send(reply);
}
Also used : IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError)

Example 8 with PacketError

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

the class AgentHistory method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    try {
        if (workgroup.getAgentManager().getAgentSession(packet.getFrom()) == 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;
    }
    // Create session list
    List<AgentHistoryModel> sessionList = new ArrayList<AgentHistoryModel>();
    Element chatSessions = reply.setChildElement("chat-sessions", "http://jivesoftware.com/protocol/workgroup");
    Element iq = packet.getChildElement();
    String agentJID = iq.attributeValue("agentJID");
    String ms = iq.attributeValue("maxSessions");
    String date = iq.attributeValue("startDate");
    long startTime = 0;
    if (date != null) {
        startTime = Long.parseLong(date);
    }
    int maxSessions = Integer.parseInt(ms);
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(GET_AGENT_SESSIONS);
        pstmt.setString(1, agentJID);
        ResultSet result = pstmt.executeQuery();
        while (result.next()) {
            String sessionID = result.getString(1);
            String joinTime = result.getString(2);
            String leftTime = result.getString(3);
            AgentHistoryModel model = new AgentHistoryModel();
            if (ModelUtil.hasLength(joinTime) && ModelUtil.hasLength(leftTime)) {
                try {
                    long start = Long.valueOf(joinTime);
                    long end = Long.valueOf(leftTime);
                    long totalTime = end - start;
                    model.setSessionID(sessionID);
                    model.setJoinTime(joinTime);
                    model.setDuration(Long.toString(totalTime));
                    if (start >= startTime) {
                        sessionList.add(model);
                    }
                } catch (NumberFormatException e) {
                    Log.error(e.getMessage(), e);
                }
            }
        }
        result.close();
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    } finally {
        DbConnectionManager.closeConnection(pstmt, con);
    }
    buildAndSend(sessionList, chatSessions, reply, workgroup, maxSessions);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PacketError(org.xmpp.packet.PacketError) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PreparedStatement(java.sql.PreparedStatement) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) ResultSet(java.sql.ResultSet)

Example 9 with PacketError

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

the class XmppWebSocket method sendPacketError.

private void sendPacketError(Element stanza, PacketError.Condition condition) {
    Element reply = stanza.createCopy();
    reply.addAttribute("type", "error");
    reply.addAttribute("to", stanza.attributeValue("from"));
    reply.addAttribute("from", stanza.attributeValue("to"));
    reply.add(new PacketError(condition).getElement());
    deliver(reply.asXML());
}
Also used : Element(org.dom4j.Element) PacketError(org.xmpp.packet.PacketError)

Example 10 with PacketError

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

the class ChatMetadataProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    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;
    }
    Element chatSessions = reply.setChildElement("chat-metadata", "http://jivesoftware.com/protocol/workgroup");
    Element iq = packet.getChildElement();
    String sessionID = iq.element("sessionID").getTextTrim();
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Map<String, String> map = new HashMap<String, String>();
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(GET_SESSION_METADATA);
        pstmt.setString(1, sessionID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            String name = rs.getString(1);
            String value = rs.getString(2);
            map.put(name, value);
        }
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    // Add metadata
    chatSessions.add(getMetaDataElement(map));
    workgroup.send(reply);
}
Also used : AgentSession(org.jivesoftware.xmpp.workgroup.AgentSession) HashMap(java.util.HashMap) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PacketError(org.xmpp.packet.PacketError) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PreparedStatement(java.sql.PreparedStatement) 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