Search in sources :

Example 56 with NotFoundException

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

the class Avatar method loadFromDb.

/**
     * Load avatar from database.
     *
     * @throws NotFoundException if avatar entry was not found in database.
     */
private void loadFromDb() throws NotFoundException {
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(LOAD_AVATAR);
        pstmt.setString(1, jid.toString());
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new NotFoundException("Avatar not found for " + jid);
        }
        this.xmppHash = rs.getString(1);
        this.legacyIdentifier = rs.getString(2);
        this.createDate = new Date(rs.getLong(3));
        this.lastUpdate = new Date(rs.getLong(4));
        this.mimeType = rs.getString(5);
    } catch (SQLException sqle) {
        Log.error(sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NotFoundException(org.jivesoftware.util.NotFoundException) PreparedStatement(java.sql.PreparedStatement) Date(java.util.Date)

Example 57 with NotFoundException

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

the class BaseMUCTransport method processPacket.

/**
     * Handles all incoming message stanzas.
     *
     * @param packet The message packet to be processed.
     * @return list of packets that will be sent back to the message sender.
     */
private List<Packet> processPacket(Message packet) {
    Log.debug("Received message packet: " + packet.toXML());
    List<Packet> reply = new ArrayList<Packet>();
    JID from = packet.getFrom();
    JID to = packet.getTo();
    try {
        TransportSession<B> session = getTransport().getSessionManager().getSession(from);
        if (!session.isLoggedIn()) {
            Message m = new Message();
            m.setError(Condition.service_unavailable);
            m.setTo(from);
            m.setFrom(getJID());
            m.setBody(LocaleUtils.getLocalizedString("gateway.base.notloggedin", "kraken", Arrays.asList(getTransport().getType().toString().toUpperCase())));
            reply.add(m);
        } else if (to.getNode() == null) {
        // Message to gateway itself.  Throw away for now.
        } else {
            MUCTransportSession mucSession = session.getMUCSessionManager().getSession(to.getNode());
            if (packet.getBody() != null) {
                if (to.getResource() == null) {
                    // Message to room
                    mucSession.sendMessage(packet.getBody());
                } else {
                    // Private message
                    mucSession.sendPrivateMessage(to.getResource(), packet.getBody());
                }
            } else {
                if (packet.getSubject() != null) {
                    // Set topic of room
                    mucSession.updateTopic(packet.getSubject());
                }
            }
        }
    } catch (NotFoundException e) {
        Log.debug("Unable to find session.");
        Message m = new Message();
        m.setError(Condition.service_unavailable);
        m.setTo(from);
        m.setFrom(getJID());
        m.setBody(LocaleUtils.getLocalizedString("gateway.base.notloggedin", "kraken", Arrays.asList(getTransport().getType().toString().toUpperCase())));
        reply.add(m);
    }
    return reply;
}
Also used : Packet(org.xmpp.packet.Packet) JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) ArrayList(java.util.ArrayList) NotFoundException(org.jivesoftware.util.NotFoundException)

Example 58 with NotFoundException

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

the class BaseMUCTransport 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 (packet.getType() == Presence.Type.error) {
        // We don't want to do anything with this.  Ignore it.
        return reply;
    }
    try {
        TransportSession<B> session = getTransport().getSessionManager().getSession(from);
        if (!session.isLoggedIn()) {
            Message m = new Message();
            m.setError(Condition.service_unavailable);
            m.setTo(from);
            m.setFrom(getJID());
            m.setBody(LocaleUtils.getLocalizedString("gateway.base.notloggedin", "kraken", Arrays.asList(getTransport().getType().toString().toUpperCase())));
            reply.add(m);
        } else if (to.getNode() == null) {
        // Ignore undirected presence.
        } else if (to.getResource() != null) {
            // Presence to a specific resource.
            if (packet.getType() == Presence.Type.unavailable) {
                // Handle logout.
                try {
                    MUCTransportSession mucSession = session.getMUCSessionManager().getSession(to.getNode());
                    mucSession.leaveRoom();
                    session.getMUCSessionManager().removeSession(to.getNode());
                } catch (NotFoundException e) {
                // Not found?  Well then no problem.
                }
            } else {
                // Handle login.
                try {
                    MUCTransportSession mucSession = session.getMUCSessionManager().getSession(to.getNode());
                    // Active session.
                    mucSession.updateStatus(this.getTransport().getPresenceType(packet));
                } catch (NotFoundException e) {
                    // No current session, lets create one.
                    MUCTransportSession mucSession = createRoom(session, to.getNode(), to.getResource());
                    session.getMUCSessionManager().storeSession(to.getNode(), mucSession);
                    mucSession.enterRoom();
                }
            }
        } else {
            // Presence to the room itself.  Return error as per protocol.
            Presence p = new Presence();
            p.setError(Condition.jid_malformed);
            p.setType(Presence.Type.error);
            p.setTo(from);
            p.setFrom(to);
            reply.add(p);
        }
    } catch (NotFoundException e) {
        Log.debug("Unable to find session.");
        Message m = new Message();
        m.setError(Condition.service_unavailable);
        m.setTo(from);
        m.setFrom(getJID());
        m.setBody(LocaleUtils.getLocalizedString("gateway.base.notloggedin", "kraken", Arrays.asList(getTransport().getType().toString().toUpperCase())));
        reply.add(m);
    }
    return reply;
}
Also used : Packet(org.xmpp.packet.Packet) JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) ArrayList(java.util.ArrayList) NotFoundException(org.jivesoftware.util.NotFoundException) Presence(org.xmpp.packet.Presence)

Example 59 with NotFoundException

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

the class BaseMUCTransport method handleDiscoInfo.

/**
     * Handle service discovery info request.
     *
     * @param packet An IQ packet in the disco info namespace.
     * @return A list of IQ packets to be returned to the user.
     */
private List<Packet> handleDiscoInfo(IQ packet) {
    List<Packet> reply = new ArrayList<Packet>();
    JID from = packet.getFrom();
    JID to = packet.getTo();
    if (packet.getTo().getNode() == null) {
        // Requested info from transport itself.
        IQ result = IQ.createResultIQ(packet);
        if (from.getNode() == null || getTransport().permissionManager.hasAccess(from)) {
            Element response = DocumentHelper.createElement(QName.get("query", NameSpace.DISCO_INFO));
            response.addElement("identity").addAttribute("category", "conference").addAttribute("type", "text").addAttribute("name", this.getDescription());
            response.addElement("feature").addAttribute("var", NameSpace.DISCO_INFO);
            response.addElement("feature").addAttribute("var", NameSpace.DISCO_ITEMS);
            response.addElement("feature").addAttribute("var", NameSpace.MUC);
            result.setChildElement(response);
        } else {
            result.setError(PacketError.Condition.forbidden);
        }
        reply.add(result);
    } else {
        // Ah, a request for information about a room.
        IQ result = IQ.createResultIQ(packet);
        try {
            TransportSession<B> session = getTransport().getSessionManager().getSession(from);
            if (session.isLoggedIn()) {
                storePendingRequest(packet);
                session.getRoomInfo(getTransport().convertJIDToID(to));
            } else {
                // Not logged in?  Not logged in then.
                result.setError(PacketError.Condition.forbidden);
                reply.add(result);
            }
        } catch (NotFoundException e) {
            // Not found?  No active session then.
            result.setError(PacketError.Condition.forbidden);
            reply.add(result);
        }
    }
    return reply;
}
Also used : Packet(org.xmpp.packet.Packet) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) IQ(org.xmpp.packet.IQ) NotFoundException(org.jivesoftware.util.NotFoundException)

Example 60 with NotFoundException

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

the class ConversationPDFServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    long conversationID = ParamUtils.getLongParameter(request, "conversationID", -1);
    if (conversationID == -1) {
        return;
    }
    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
    ConversationManager conversationManager = (ConversationManager) plugin.getModule(ConversationManager.class);
    Conversation conversation;
    if (conversationID > -1) {
        try {
            conversation = new Conversation(conversationManager, conversationID);
            ByteArrayOutputStream stream = new ConversationUtils().getConversationPDF(conversation);
            // setting some response headers
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
            response.setHeader("Pragma", "public");
            // setting the content type
            response.setContentType("application/pdf");
            // the content length is needed for MSIE!!!
            response.setContentLength(stream.size());
            // write ByteArrayOutputStream to the ServletOutputStream
            ServletOutputStream out = response.getOutputStream();
            stream.writeTo(out);
            out.flush();
        } catch (NotFoundException nfe) {
            Log.error(nfe.getMessage(), nfe);
        }
    }
}
Also used : MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) ServletOutputStream(javax.servlet.ServletOutputStream) NotFoundException(org.jivesoftware.util.NotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

NotFoundException (org.jivesoftware.util.NotFoundException)64 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)28 Element (org.dom4j.Element)16 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 UserRequest (org.jivesoftware.xmpp.workgroup.request.UserRequest)4 KrakenPlugin (net.sf.kraken.KrakenPlugin)3 Registration (net.sf.kraken.registration.Registration)3 PluginManager (org.jivesoftware.openfire.container.PluginManager)3 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)3