use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class DefaultVCardProvider method updateVCard.
@Override
public Element updateVCard(String username, Element vCardElement) throws NotFoundException {
if (loadVCard(username) == null) {
// The user does not have a vCard
throw new NotFoundException("Username " + username + " does not have a vCard");
}
if (JiveGlobals.getBooleanProperty(PhotoResizer.PROPERTY_RESIZE_ON_CREATE, PhotoResizer.PROPERTY_RESIZE_ON_CREATE_DEFAULT)) {
PhotoResizer.resizeAvatar(vCardElement);
}
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(UPDATE_PROPERTIES);
pstmt.setString(1, vCardElement.asXML());
pstmt.setString(2, username);
pstmt.executeUpdate();
} catch (SQLException e) {
Log.error("Error updating vCard of username: " + username, e);
} finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return vCardElement;
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class MultiUserChatServiceImpl method process.
/**
* Processes an IQ stanza.
*
* @param packet The stanza to route
* @param room The room that the stanza was addressed to.
* @param preExistingRole The role of this user in the addressed room prior to processing of this stanza, if any.
*/
private void process(@Nonnull final IQ packet, @Nullable final MUCRoom room, @Nullable final MUCRole preExistingRole) {
// Packets to a specific node/group/room
if (preExistingRole == null || room == null) {
Log.debug("Ignoring stanza received from a non-occupant of a room (room might not even exist): {}", packet.toXML());
if (packet.isRequest()) {
// If a non-occupant sends a disco to an address of the form <room@service/nick>, a MUC service MUST
// return a <bad-request/> error. http://xmpp.org/extensions/xep-0045.html#disco-occupant
sendErrorPacket(packet, PacketError.Condition.bad_request, "You are not an occupant of this room.");
}
return;
}
if (packet.isResponse()) {
// Only process IQ result packet if it's a private packet sent to another room occupant
if (packet.getTo().getResource() != null) {
try {
// User is sending an IQ result packet to another room occupant
room.sendPrivatePacket(packet, preExistingRole);
} catch (NotFoundException | ForbiddenException e) {
// Do nothing. No error will be sent to the sender of the IQ result packet
Log.debug("Silently ignoring an IQ response sent to the room as a private message that caused an exception while being processed: {}", packet.toXML(), e);
}
} else {
Log.trace("Silently ignoring an IQ response sent to the room, but not as a private message: {}", packet.toXML());
}
} else {
// Check and reject conflicting packets with conflicting roles In other words, another user already has this nickname
if (!preExistingRole.getUserAddress().equals(packet.getFrom())) {
Log.debug("Rejecting conflicting stanza with conflicting roles: {}", packet.toXML());
sendErrorPacket(packet, PacketError.Condition.conflict, "Another user uses this nickname.");
return;
}
try {
// TODO Analyze if it is correct for these first two blocks to be processed without evaluating if they're addressed to the room or if they're a PM.
Element query = packet.getElement().element("query");
if (query != null && "http://jabber.org/protocol/muc#owner".equals(query.getNamespaceURI())) {
room.getIQOwnerHandler().handleIQ(packet, preExistingRole);
} else if (query != null && "http://jabber.org/protocol/muc#admin".equals(query.getNamespaceURI())) {
room.getIQAdminHandler().handleIQ(packet, preExistingRole);
} else {
final String toNickname = packet.getTo().getResource();
if (toNickname != null) {
// User is sending to a room occupant.
final boolean selfPingEnabled = JiveGlobals.getBooleanProperty("xmpp.muc.self-ping.enabled", true);
if (selfPingEnabled && toNickname.equals(preExistingRole.getNickname()) && packet.isRequest() && packet.getElement().element(QName.get(IQPingHandler.ELEMENT_NAME, IQPingHandler.NAMESPACE)) != null) {
Log.trace("User '{}' is sending an IQ 'ping' to itself. See XEP-0410: MUC Self-Ping (Schrödinger's Chat).", packet.getFrom());
XMPPServer.getInstance().getPacketRouter().route(IQ.createResultIQ(packet));
} else {
Log.trace("User '{}' is sending an IQ stanza to another room occupant (as a PM) with nickname: '{}'.", packet.getFrom(), toNickname);
room.sendPrivatePacket(packet, preExistingRole);
}
} else {
Log.debug("An IQ request was addressed to the MUC room '{}' which cannot answer it: {}", room.getName(), packet.toXML());
sendErrorPacket(packet, PacketError.Condition.bad_request, "IQ request cannot be processed by the MUC room itself.");
}
}
} catch (NotAcceptableException e) {
Log.debug("Unable to process IQ stanza: room requires a password, but none was supplied.", e);
sendErrorPacket(packet, PacketError.Condition.not_acceptable, "Room requires a password, but none was supplied.");
} catch (ForbiddenException e) {
Log.debug("Unable to process IQ stanza: sender don't have authorization to perform the request.", e);
sendErrorPacket(packet, PacketError.Condition.forbidden, "You don't have authorization to perform this request.");
} catch (NotFoundException e) {
Log.debug("Unable to process IQ stanza: the intended recipient is not available.", e);
sendErrorPacket(packet, PacketError.Condition.recipient_unavailable, "The intended recipient is not available.");
} catch (ConflictException e) {
Log.debug("Unable to process IQ stanza: processing this request would leave the room in an invalid state (eg: without owners).", e);
sendErrorPacket(packet, PacketError.Condition.conflict, "Processing this request would leave the room in an invalid state (eg: without owners).");
} catch (NotAllowedException e) {
Log.debug("Unable to process IQ stanza: an owner or administrator cannot be banned from the room.", e);
sendErrorPacket(packet, PacketError.Condition.not_allowed, "An owner or administrator cannot be banned from the room.");
} catch (CannotBeInvitedException e) {
Log.debug("Unable to process IQ stanza: user being invited as a result of being added to a members-only room still does not have permission.", e);
sendErrorPacket(packet, PacketError.Condition.not_acceptable, "User being invited as a result of being added to a members-only room still does not have permission.");
} catch (Exception e) {
Log.error("An unexpected exception occurred while processing IQ stanza: {}", packet.toXML(), e);
sendErrorPacket(packet, PacketError.Condition.internal_server_error, "An unexpected exception occurred while processing your request.");
}
}
}
Aggregations