use of org.jivesoftware.xmpp.workgroup.interceptor.PacketRejectedException in project Openfire by igniterealtime.
the class Workgroup method process.
public void process(Packet packet) {
InterceptorManager interceptorManager = WorkgroupInterceptorManager.getInstance();
try {
interceptorManager.invokeInterceptors(getJID().toBareJID(), packet, true, false);
String mucDomain = WorkgroupManager.getInstance().getMUCServiceName();
if (mucDomain.equals(packet.getFrom().getDomain())) {
roomActivity(packet);
} else if (packet instanceof Message) {
process((Message) packet);
} else if (packet instanceof Presence) {
process((Presence) packet);
} else if (packet instanceof IQ) {
process((IQ) packet);
}
interceptorManager.invokeInterceptors(getJID().toBareJID(), packet, true, true);
} catch (PacketRejectedException e) {
rejectPacket(packet, e);
}
}
use of org.jivesoftware.xmpp.workgroup.interceptor.PacketRejectedException in project Openfire by igniterealtime.
the class WorkgroupIQHandler method handleIQSet.
private void handleIQSet(IQ packet) {
IQ reply;
// TODO: verify namespace and send error if wrong
Element iq = packet.getChildElement();
JID sender = packet.getFrom();
reply = IQ.createResultIQ(packet);
reply.setFrom(workgroup.getJID());
String queryName = iq.getName();
String queryNamespace = iq.getNamespace().toString();
if ("join-queue".equals(queryName)) {
InterceptorManager interceptorManager = QueueInterceptorManager.getInstance();
try {
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, false);
// Received a Join Queue request from a visitor, create a new request.
UserRequest request = new UserRequest(packet, workgroup);
// Let the workgroup process the new request
if (!workgroup.queueRequest(request)) {
// It was not possible to add the request to a queue so answer that the
// workgroup is not accepting new join-queue requests
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.service_unavailable));
}
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, true);
} catch (PacketRejectedException e) {
workgroup.rejectPacket(packet, e);
reply = null;
}
} else if ("depart-queue".equals(queryName)) {
// Visitor is departing queue
try {
Request request = UserRequest.getRequest(workgroup, sender);
InterceptorManager interceptorManager = QueueInterceptorManager.getInstance();
try {
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, false);
request.cancel(Request.CancelType.DEPART);
iq.add(request.getSessionElement());
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, true);
} catch (PacketRejectedException e) {
workgroup.rejectPacket(packet, e);
reply = null;
}
} catch (NotFoundException e) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
Log.debug("Request not found" + " while departing queue:", e);
}
} else if ("offer-accept".equals(queryName)) {
try {
InterceptorManager interceptorManager = OfferInterceptorManager.getInstance();
String id = iq.attributeValue("id");
String jid = iq.attributeValue("jid");
if (id != null || jid != null) {
Request request;
if (id != null) {
// Search request by its unique ID
request = Request.getRequest(id);
} else {
// Old version of FP refers to requests by the user's jid. This old version
// implements transfers and invitations on the client and not the server side.
// Therefore, for each user's jid there is always a unique Request
request = UserRequest.getRequest(workgroup, new JID(jid));
}
Offer offer = request.getOffer();
if (offer != null && offer.isOutstanding()) {
AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
if (agentSession == null) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
Log.debug("Agent not found while accepting offer");
} else {
try {
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, false);
offer.accept(agentSession);
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, true);
} catch (PacketRejectedException e) {
workgroup.rejectPacket(packet, e);
reply = null;
}
}
} else {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_acceptable));
}
}
} catch (NotFoundException e) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
Log.debug("Request not found " + "while accepting offer: ", e);
} catch (AgentNotFoundException e) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
Log.debug("Agent not found " + "while accepting offer: ", e);
}
} else if ("offer-reject".equals(queryName)) {
try {
InterceptorManager interceptorManager = OfferInterceptorManager.getInstance();
String id = iq.attributeValue("id");
String jid = iq.attributeValue("jid");
if (id != null || jid != null) {
Request request;
if (id != null) {
// Search request by its unique ID
request = Request.getRequest(id);
} else {
// Old version of FP refers to requests by the user's jid. This old version
// implements transfers and invitations on the client and not the server side.
// Therefore, for each user's jid there is always a unique Request
request = UserRequest.getRequest(workgroup, new JID(jid));
}
Offer offer = request.getOffer();
if (offer != null) {
AgentSession agentSession = agentManager.getAgentSession(packet.getFrom());
if (agentSession == null) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
Log.debug("Agent not found while accepting offer");
} else {
try {
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, false);
offer.reject(agentSession);
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, true);
} catch (PacketRejectedException e) {
workgroup.rejectPacket(packet, e);
reply = null;
}
}
}
}
} catch (NotFoundException e) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
Log.debug("Request not found " + "while rejecting offer: ", e);
} catch (AgentNotFoundException e) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
Log.debug("Agent not found " + "while accepting offer: ", e);
}
} else if ("invite".equals(queryName)) {
// Get the type of inviation (i.e. entity type is being invited)
InvitationRequest request = new InvitationRequest(packet, workgroup);
workgroup.processInvitation(request, packet);
reply = null;
} else if ("transfer".equals(queryName)) {
// Get the type of transfer (i.e. entity type is going to get the transfer offer)
TransferRequest request = new TransferRequest(packet, workgroup);
workgroup.processTransfer(request, packet);
reply = null;
} else if ("jabber:iq:private".equals(queryNamespace)) {
// IQ private for agents global macro storage
setIQPrivate(packet);
} else if ("agent-info".equals(queryName)) {
if (!JiveGlobals.getBooleanProperty("xmpp.live.agent.change-properties", true)) {
// Answer that agents are not allowed to change their properties (feature disabled)
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.service_unavailable));
} else {
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 {
String allowsToChange = agentSession.getAgent().getProperties().getProperty("change-properties");
if (!"false".equals(allowsToChange)) {
// Set the new agent's info
agentSession.getAgent().updateAgentInfo(packet);
} else {
// Answer that this agent is not allowed to change his properties
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.service_unavailable));
}
}
} catch (AgentNotFoundException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
}
}
} else {
// none are found, send bad request error.
for (WorkgroupProvider provider : providerManager.getWorkgroupProviders()) {
// Handle packet?
if (provider.handleSet(packet)) {
// If provider accepts responsibility, hand off packet.
provider.executeSet(packet, workgroup);
return;
}
}
dropPacket(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.bad_request));
}
if (reply != null) {
workgroup.send(reply);
}
}
use of org.jivesoftware.xmpp.workgroup.interceptor.PacketRejectedException in project Openfire by igniterealtime.
the class WorkgroupPresence method agentToWorkgroup.
private void agentToWorkgroup(Presence packet) throws AgentNotFoundException {
String workgroupNode = workgroup.getJID().getNode();
String resource = packet.getFrom().getResource();
boolean usesAgentResource = workgroupNode.equalsIgnoreCase(resource);
final JID sender = packet.getFrom();
Agent agent = null;
// Check if the sender of the Presence is an Agent otherwise return an error
try {
agent = workgroup.getAgentManager().getAgent(sender);
} catch (AgentNotFoundException notFound) {
if (usesAgentResource) {
throw notFound;
}
}
// Check if the presence includes the Workgroup extension
boolean includesExtension = packet.getChildElement("agent-status", "http://jabber.org/protocol/workgroup") != null;
AgentManager agentManager = workgroup.getAgentManager();
if (agent != null && !agentManager.isInWorkgroup(agent, workgroup) && includesExtension) {
throw new AgentNotFoundException();
}
if (agent == null || !agentManager.isInWorkgroup(agent, workgroup)) {
if (packet.isAvailable()) {
if (!sender.equals(workgroup.getJID())) {
// Add the user to the list of temporary subscribers. Since the
// user sent this presence using a directed presence the server
// will send an unavailable presence if the user gets disconnected.
// When an unavailable presence is received the subscription is
// going to be removed.
listeners.add(packet.getFrom());
sendPresence(packet.getFrom());
}
} else {
listeners.remove(packet.getFrom());
}
return;
}
InterceptorManager interceptorManager = AgentInterceptorManager.getInstance();
try {
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, false);
// Try to update the presence of the AgentSession with the new presence
AgentSession agentSession = agent.getAgentSession();
if (agentSession == null) {
if (!includesExtension) {
// and does not contain the proper extension
return;
}
// Add new agent session.
agentSession = agent.createSession(packet.getFrom());
if (agentSession == null) {
// User is not able to join since an existing session from another resource already exists
Presence reply = new Presence();
reply.setID(packet.getID());
reply.setTo(packet.getFrom());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
workgroup.send(reply);
return;
}
}
// Update session's presence with latest presence
agentSession.updatePresence(packet);
if (agentSession.getPresence().getType() == null) {
agentSession.join(workgroup);
} else {
agentSession.depart(workgroup);
}
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, true);
} catch (PacketRejectedException e) {
workgroup.rejectPacket(packet, e);
}
}
use of org.jivesoftware.xmpp.workgroup.interceptor.PacketRejectedException in project Openfire by igniterealtime.
the class Chatbot method onMessage.
/**
* Process a message sent by the owner of the specified session.
*
* @param session the session whose owner (i.e. user) sent the message.
* @param message message sent by the owner of the session to the workgroup.
*/
public void onMessage(ChatbotSession session, Message message) {
InterceptorManager interceptorManager = ChatbotInterceptorManager.getInstance();
try {
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), message, true, false);
// Update the Message thread that the user is using in the session
session.setMessageThread(message.getThread());
// Check if the workgroup is opened
synchronized (session) {
if (workgroup.getStatus() != Workgroup.Status.OPEN) {
// Send message saying that the workgroup is closed/not available
sendReply(message, getWorkgroupClosedMessage());
} else if (handleCommand(message, session)) {
// The sent message executed a command so do nothing
} else if (session.getCurrentStep() < 0) {
// Send the welcome message
sendWelcomeMessage(message);
// Send the join question
sendJoinQuestion(message, session);
} else if (session.getCurrentStep() == 1) {
// User is answering join question
if (yes.equalsIgnoreCase(message.getBody().trim())) {
// User accepted to join the workgroup so send the first question of
// the form
userAcceptedJoining(message, session);
} else if (no.equalsIgnoreCase(message.getBody().trim())) {
// User rejected to join the workgroup so send a goodbye message and close
// the chat session
closeSession(message);
} else {
// The user sent an unknown answer so repeat the join question
sendJoinQuestion(message, session);
}
} else if (session.getCurrentStep() == 2) {
// User is filling out the form
if (userAnsweredField(message, session)) {
// form has been filled out then join the queue
if (session.getCurrentSubstep() < getForm().getFormElements().size() - 1) {
sendNextQuestion(message, session);
} else {
userJoinQueue(message, session);
}
} else {
// The user sent an unknown answer so repeat the last question
repeatQuestion(message, session);
}
} else if (session.getCurrentStep() == 4) {
// User is answering if he wants to get another room invitation
if (yes.equalsIgnoreCase(message.getBody().trim())) {
// User accepted to receive another room invitation so send another
// room invitation
sendRoomInvitation(message, session);
} else if (no.equalsIgnoreCase(message.getBody().trim())) {
// User declined to receive another room invitation so do nothing
} else {
// The user sent an unknown answer so repeat the invitation question
sendInvitationQuestion(message.getFrom(), session);
}
} else if (session.getCurrentStep() == 6) {
// User is answering email question
if (yes.equalsIgnoreCase(message.getBody().trim())) {
// User accepted to receive the transcript by email
List<String> emailValue = session.getAttributes().get("email");
if (emailValue == null || emailValue.isEmpty()) {
// The user wants to get the transcript by email but he hasn't provided
// an email yet so ask for one
sendGetEmailQuestion(message, session);
} else {
// Send the transcript by email
sendTranscriptByMail(emailValue.get(0), message, session);
// Send a goodbye message and close the chat session
closeSession(message);
}
} else if (no.equalsIgnoreCase(message.getBody().trim())) {
// User rejected to receive the transcript by email so send a goodbye
// message and close the chat session
closeSession(message);
} else {
// The user sent an unknown answer so repeat the email question
sendEmailQuestion(message.getFrom(), session);
}
} else if (session.getCurrentStep() == 7) {
// Send the transcript by email
sendTranscriptByMail(message.getBody().trim(), message, session);
// Send a goodbye message and close the chat session
closeSession(message);
} else {
// User is waiting in a queue and the sent message contains an unkown content
// so send message saying that the command was not acceptable (i.e. unknown command)
sendReply(message, getNotAcceptableMessage());
}
}
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), message, true, true);
} catch (PacketRejectedException e) {
workgroup.rejectPacket(message, e);
}
}
Aggregations