Search in sources :

Example 36 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class DbDispatcherInfoProvider method getDispatcherInfo.

/**
     * Returns the Dispatcher to be used for the given queue.
     *
     * @param workgroup the owning workgroup.
     * @param queueID the id of the queue this dispatcher belongs to.
     * @return the Dispatcher.
     * @throws NotFoundException thrown if no dispatcher was found.
     */
public DispatcherInfo getDispatcherInfo(Workgroup workgroup, long queueID) throws NotFoundException {
    BasicDispatcherInfo userInfo = null;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(LOAD_DISPATCHER_BY_ID);
        pstmt.setLong(1, queueID);
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new NotFoundException();
        }
        userInfo = new BasicDispatcherInfo(workgroup, queueID, // name
        rs.getString(1), // description
        rs.getString(2), // offer timeout
        rs.getInt(3), // request timeout
        rs.getInt(4));
    } catch (SQLException e) {
        throw new NotFoundException("Failed to read dispatcher " + queueID + " from database. " + e.getMessage());
    } catch (NumberFormatException nfe) {
        Log.error("WARNING: There was an error parsing the dates " + "returned from the database. Ensure that they're being stored " + "correctly.");
        throw new NotFoundException("Dispatcher with id " + queueID + " could not be loaded from the database.");
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return userInfo;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NotFoundException(org.jivesoftware.util.NotFoundException) PreparedStatement(java.sql.PreparedStatement) BasicDispatcherInfo(org.jivesoftware.xmpp.workgroup.dispatcher.BasicDispatcherInfo)

Example 37 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class InvitationRequest method execute.

public void execute() {
    if (Type.user == type) {
        AgentSession agentSession = null;
        // Verify if the invitee user is an agent that is currently logged
        try {
            agentSession = WorkgroupManager.getInstance().getAgentManager().getAgent(invitee).getAgentSession();
        } catch (AgentNotFoundException e) {
        // Ignore
        }
        // Only Send muc invites to a particular user.
        if (true) {
            // Invitee is not an agent so send a standard MUC room invitation
            sendMUCInvitiation();
            // Keep track when the invitation was sent to the user
            offerAccpeted = System.currentTimeMillis();
        } else {
            // Invite the agent to the room by sending an offer
            Workgroup workgroup = agentSession.getWorkgroups().iterator().next();
            RequestQueue requestQueue = workgroup.getRequestQueues().iterator().next();
            // Add the requested agent as the initial target agent to get the offer
            getMetaData().put("agent", Arrays.asList(invitee.toString()));
            getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
            // Dispatch the request
            requestQueue.getDispatcher().injectRequest(this);
        }
    } else if (Type.queue == type) {
        // Send offer to the best again available in the requested queue
        Workgroup targetWorkgroup = WorkgroupManager.getInstance().getWorkgroup(invitee.getNode());
        if (targetWorkgroup == null) {
            // No workgroup was found for the specified invitee. Send a Message with the error
            sendErrorMessage("Specified workgroup was not found.");
            return;
        }
        try {
            RequestQueue requestQueue = targetWorkgroup.getRequestQueue(invitee.getResource());
            getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
            // Dispatch the request
            requestQueue.getDispatcher().injectRequest(this);
        } catch (NotFoundException e) {
            // No queue was found for the specified invitee. Send a Message with the error
            sendErrorMessage("Specified queue was not found.");
        }
    } else if (Type.workgroup == type) {
        // Select the best queue based on the original request
        Workgroup targetWorkgroup = WorkgroupManager.getInstance().getWorkgroup(invitee.getNode());
        if (targetWorkgroup != null) {
            RequestQueue requestQueue = RoutingManager.getInstance().getBestQueue(targetWorkgroup, userRequest);
            getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
            // Send offer to the best again available in the requested queue
            requestQueue.getDispatcher().injectRequest(this);
        } else {
            // No workgroup was found for the specified invitee. Send a Message with the error
            sendErrorMessage("Specified workgroup was not found.");
        }
    }
}
Also used : AgentSession(org.jivesoftware.xmpp.workgroup.AgentSession) RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) NotFoundException(org.jivesoftware.util.NotFoundException) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup)

Example 38 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class TransferRequest method execute.

public void execute() {
    if (Type.user == type) {
        AgentSession agentSession = null;
        // Verify if the invitee user is an agent that is currently logged
        try {
            agentSession = WorkgroupManager.getInstance().getAgentManager().getAgent(invitee).getAgentSession();
        } catch (AgentNotFoundException e) {
        // Ignore
        }
        // Only send muc invites to a particular user.
        if (true) {
            // Invitee is not an agent so send a standard MUC room invitation
            sendMUCInvitiation();
            // Keep track when the invitation was sent to the user
            offerAccepted = System.currentTimeMillis();
        } else {
            // Invite the agent to the room by sending an offer
            Workgroup workgroup = agentSession.getWorkgroups().iterator().next();
            RequestQueue requestQueue = workgroup.getRequestQueues().iterator().next();
            // Add the requested agent as the initial target agent to get the offer
            getMetaData().put("agent", Arrays.asList(invitee.toString()));
            getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
            // Dispatch the request
            requestQueue.getDispatcher().injectRequest(this);
        }
    } else if (Type.queue == type) {
        // Send offer to the best again available in the requested queue
        Workgroup targetWorkgroup = WorkgroupManager.getInstance().getWorkgroup(invitee.getNode());
        if (targetWorkgroup == null) {
            // No workgroup was found for the specified invitee. Send a Message with the error
            sendErrorMessage("Specified workgroup was not found.");
            return;
        }
        try {
            RequestQueue requestQueue = targetWorkgroup.getRequestQueue(invitee.getResource());
            getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
            // Dispatch the request
            requestQueue.getDispatcher().injectRequest(this);
        } catch (NotFoundException e) {
            // No queue was found for the specified invitee. Send a Message with the error
            sendErrorMessage("Specified queue was not found.");
        }
    } else if (Type.workgroup == type) {
        // Select the best queue based on the original request
        Workgroup targetWorkgroup = WorkgroupManager.getInstance().getWorkgroup(invitee.getNode());
        if (targetWorkgroup != null) {
            RequestQueue requestQueue = RoutingManager.getInstance().getBestQueue(targetWorkgroup, userRequest);
            getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
            // Send offer to the best again available in the requested queue
            requestQueue.getDispatcher().injectRequest(this);
        } else {
            // No workgroup was found for the specified invitee. Send a Message with the error
            sendErrorMessage("Specified workgroup was not found.");
        }
    }
}
Also used : AgentSession(org.jivesoftware.xmpp.workgroup.AgentSession) RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) NotFoundException(org.jivesoftware.util.NotFoundException) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup)

Example 39 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class BaseTransport method processPacket.

/**
     * Handles all incoming presence stanzas.
     *
     * @param packet The presence packet to be processed.
     * @return list of packets that will be sent back to the presence requester.
     */
private List<Packet> processPacket(Presence packet) {
    Log.debug("Received presence packet: " + packet.toXML());
    List<Packet> reply = new ArrayList<Packet>();
    JID from = packet.getFrom();
    JID to = packet.getTo();
    if (to == null) {
        // Well clearly it's for us or it wouldn't have gotten here...
        packet.setTo(getJID());
        to = getJID();
    }
    if (packet.getType() == Presence.Type.error) {
        // We don't want to do anything with this.  Ignore it.
        return reply;
    }
    try {
        if (to.getNode() == null) {
            Collection<Registration> registrations = RegistrationManager.getInstance().getRegistrations(from, this.transportType);
            if (registrations.isEmpty()) {
                // User is not registered with us.
                Log.debug("Unable to find registration.");
                Presence p = new Presence();
                p.setTo(from);
                p.setFrom(to);
                p.setError(PacketError.Condition.forbidden);
                p.setType(Presence.Type.unavailable);
                reply.add(p);
                return reply;
            }
            if (JiveGlobals.getBooleanProperty("plugin.gateway." + getType() + ".registrationstrict", false) && !permissionManager.hasAccess(from)) {
                Log.debug("Attempt to log in by restricted account: " + from);
                Presence p = new Presence();
                p.setTo(from);
                p.setFrom(to);
                p.setError(PacketError.Condition.forbidden);
                p.setType(Presence.Type.unavailable);
                reply.add(p);
                return reply;
            }
            Registration registration = registrations.iterator().next();
            // This packet is to the transport itself.
            if (packet.getType() == null) {
                // A user's resource has come online.
                TransportSession<B> session;
                Lock l = CacheFactory.getLock(registration.getJID() + "@" + transportType.toString() + "ns", sessionRouter.sessionLocations);
                try {
                    l.lock();
                    session = sessionManager.getSession(from);
                    if (session.hasResource(from.getResource())) {
                        Log.debug("An existing resource has changed status: " + from);
                        if (session.getPriority(from.getResource()) != packet.getPriority()) {
                            session.updatePriority(from.getResource(), packet.getPriority());
                        }
                        if (session.isHighestPriority(from.getResource())) {
                            // Well, this could represent a status change.
                            session.updateStatus(getPresenceType(packet), packet.getStatus());
                        }
                    } else {
                        Log.debug("A new resource has come online: " + from);
                        // This is a new resource, lets send them what we know.
                        session.addResource(from.getResource(), packet.getPriority());
                        // Tell the new resource what the state of their buddy list is.
                        session.getBuddyManager().sendAllAvailablePresences(from);
                        // If this priority is the highest, treat it's status as golden
                        if (session.isHighestPriority(from.getResource())) {
                            session.updateStatus(getPresenceType(packet), packet.getStatus());
                        }
                    }
                    // Attach the session
                    session.attachSession();
                } catch (NotFoundException e) {
                    Log.debug("A new session has come online: " + from);
                    session = this.registrationLoggedIn(registration, from, getPresenceType(packet), packet.getStatus(), packet.getPriority());
                    sessionManager.storeSession(from, session);
                } finally {
                    l.unlock();
                }
            } else if (packet.getType() == Presence.Type.unavailable) {
                // A user's resource has gone offline.
                TransportSession<B> session;
                try {
                    session = sessionManager.getSession(from);
                    String resource = from.getResource();
                    if (session.hasResource(resource)) {
                        if (session.getResourceCount() > 1) {
                            // Just one of the resources, lets adjust accordingly.
                            if (session.isHighestPriority(resource)) {
                                Log.debug("A high priority resource (of multiple) has gone offline: " + from);
                                // Ooh, the highest resource went offline, drop to next highest.
                                session.removeResource(resource);
                                // Lets ask the next highest resource what it's presence is.
                                Presence p = new Presence(Presence.Type.probe);
                                p.setTo(session.getJIDWithHighestPriority());
                                p.setFrom(this.getJID());
                                sendPacket(p);
                            } else {
                                Log.debug("A low priority resource (of multiple) has gone offline: " + from);
                                // Meh, lower priority, big whoop.
                                session.removeResource(resource);
                            }
                        } else {
                            Log.debug("A final resource has gone offline: " + from);
                            // No more resources, byebye.
                            this.registrationLoggedOut(session);
                            sessionManager.removeSession(from);
                        }
                    }
                } catch (NotFoundException e) {
                    Log.debug("Ignoring unavailable presence for inactive seession.");
                }
            } else if (packet.getType() == Presence.Type.probe) {
                // Client is asking for presence status.
                TransportSession<B> session;
                try {
                    session = sessionManager.getSession(from);
                    session.sendPresence(from);
                } catch (NotFoundException e) {
                    Log.debug("Ignoring probe presence for inactive session.");
                }
            } else {
                Log.debug("Ignoring this packet:" + packet.toString());
            // Anything else we will ignore for now.
            }
        } else {
            // This packet is to a user at the transport.
            try {
                TransportSession<B> session = sessionManager.getSession(from);
                if (packet.getType() == Presence.Type.probe) {
                    // Presence probe, lets try to answer appropriately.
                    if (session.isLoggedIn()) {
                        try {
                            TransportBuddy buddy = session.getBuddyManager().getBuddy(to);
                            buddy.sendPresence(from);
                        } catch (NotFoundException e) {
                            // User was not found so send an error presence
                            Presence p = new Presence();
                            p.setTo(from);
                            p.setFrom(to);
                            // TODO: this causes some ugliness in some clients
                            //                                p.setError(PacketError.Condition.forbidden);
                            // If the user tries to check on a buddy before we are totally logged in
                            // and have the full list, this gets thrown for legit contacts.
                            // We'll send unavailable for now.
                            p.setType(Presence.Type.unavailable);
                            sendPacket(p);
                        }
                    }
                } else if (packet.getType() == Presence.Type.subscribe) {
                    // For the time being, we are going to lie to the end user that the subscription has worked.
                    Presence p = new Presence();
                    p.setType(Presence.Type.subscribed);
                    p.setTo(from);
                    p.setFrom(to);
                    sendPacket(p);
                } else if (packet.getType() == Presence.Type.unsubscribe) {
                    // For the time being, we are going to lie to the end user that the unsubscription has worked.
                    Presence p = new Presence();
                    p.setType(Presence.Type.unsubscribed);
                    p.setTo(from);
                    p.setFrom(to);
                    sendPacket(p);
                } else if (packet.getType() == Presence.Type.subscribed) {
                    // let the legacy domain know that the contact was accepted.
                    session.acceptAddContact(packet.getTo());
                } else {
                // Anything else we will ignore for now.
                }
            } catch (NotFoundException e) {
                // Well we just don't care then.
                Log.debug("User not found while processing " + "presence stanza: " + packet.toXML(), e);
            }
        }
    } catch (Exception e) {
        Log.debug("Exception while processing packet: ", e);
    }
    return reply;
}
Also used : TransportBuddy(net.sf.kraken.roster.TransportBuddy) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) TransportSession(net.sf.kraken.session.TransportSession) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) NotFoundException(org.jivesoftware.util.NotFoundException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Lock(java.util.concurrent.locks.Lock) Registration(net.sf.kraken.registration.Registration)

Example 40 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class BaseTransport method vCardUpdated.

/**
     * VCard was just updated.
     *
     * @see org.jivesoftware.openfire.vcard.VCardListener#vCardUpdated(String, Element)
     */
public void vCardUpdated(String username, Element vcardElem) {
    if (vcardElem != null) {
        if (JiveGlobals.getBooleanProperty("plugin.gateway." + getType() + ".avatars", true)) {
            Element photoElem = vcardElem.element("PHOTO");
            if (photoElem != null) {
                Element typeElem = photoElem.element("TYPE");
                Element binElem = photoElem.element("BINVAL");
                if (typeElem != null && binElem != null) {
                    try {
                        MessageDigest md = MessageDigest.getInstance("SHA-1");
                        byte[] imageData = Base64.decode(binElem.getText());
                        md.update(imageData);
                        String xmppHash = StringUtils.encodeHex(md.digest());
                        try {
                            TransportSession<B> trSession = sessionManager.getSession(username);
                            if (trSession.getAvatar() == null || !trSession.getAvatar().getXmppHash().equals(xmppHash)) {
                                // Store a cache of the avatar
                                trSession.setAvatar(new Avatar(trSession.getJID(), imageData));
                                trSession.updateLegacyAvatar(typeElem.getText(), imageData);
                            }
                        } catch (NotFoundException e) {
                        // Not an active session, ignore.
                        }
                    } catch (NoSuchAlgorithmException e) {
                        Log.error("Gateway: Unable to find support for SHA algorith?");
                    }
                }
            }
        }
    }
}
Also used : Element(org.dom4j.Element) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) Avatar(net.sf.kraken.avatars.Avatar)

Aggregations

NotFoundException (org.jivesoftware.util.NotFoundException)67 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)29 Element (org.dom4j.Element)17 JID (org.xmpp.packet.JID)15 ArrayList (java.util.ArrayList)10 Connection (java.sql.Connection)8 PreparedStatement (java.sql.PreparedStatement)8 SQLException (java.sql.SQLException)8 ResultSet (java.sql.ResultSet)7 TransportSession (net.sf.kraken.session.TransportSession)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 Avatar (net.sf.kraken.avatars.Avatar)5 TransportBuddy (net.sf.kraken.roster.TransportBuddy)5 Packet (org.xmpp.packet.Packet)5 Date (java.util.Date)4 MultiUserChatServiceImpl (org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl)4 UserRequest (org.jivesoftware.xmpp.workgroup.request.UserRequest)4 KrakenPlugin (net.sf.kraken.KrakenPlugin)3 Registration (net.sf.kraken.registration.Registration)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3