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