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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations