public void completeRegistration(TransportSession session) { final IQ result = IQ.createResultIQ(session.getRegistrationPacket()); if (!session.getFailureStatus().equals(ConnectionFailureReason.NO_ISSUE)) { // Ooh there was a connection issue, we're going to report that back! if (session .getFailureStatus() .equals(ConnectionFailureReason.USERNAME_OR_PASSWORD_INCORRECT)) { result.setError(Condition.not_authorized); } else if (session.getFailureStatus().equals(ConnectionFailureReason.CAN_NOT_CONNECT)) { result.setError(Condition.service_unavailable); } else if (session.getFailureStatus().equals(ConnectionFailureReason.LOCKED_OUT)) { result.setError(Condition.forbidden); } else { result.setError(Condition.undefined_condition); } result.setType(IQ.Type.error); } parent.sendPacket(result); session.setRegistrationPacket(null); // Lets ask them what their presence is, maybe log them in immediately. final Presence p = new Presence(Presence.Type.probe); p.setTo(session.getJID()); p.setFrom(parent.getJID()); parent.sendPacket(p); }
private void sendRemoteChannelServerNotFoundErrorResponses(String server) throws ComponentException { List<Packet> queued = waitingStanzas.get(server); if (queued == null) { return; } Element noRemoteServer = new DOMElement("text", new Namespace("", JabberPubsub.NS_PUBSUB_ERROR)); noRemoteServer.setText("No pubsub channel service discovered for " + server); Element itemNotFound = new DOMElement( PacketError.Condition.item_not_found.toXMPP(), new Namespace("", JabberPubsub.NS_XMPP_STANZAS)); Element error = new DOMElement("error"); error.addAttribute("type", PacketError.Type.cancel.toXMPP()); error.add(itemNotFound); error.add(noRemoteServer); IQ response; for (Packet packet : queued) { response = IQ.createResultIQ((IQ) packet); response.setFrom(localServer); response.setType(IQ.Type.error); response.setChildElement(error); component.sendPacket(response); } }
/** * The packet is a typical 'set' or 'get' update targeted at the server. Notice that the set could * be a roster removal in which case we have to generate a local roster removal update as well as * a new roster removal to send to the the roster item's owner. * * @param packet The packet that triggered this update * @return Either a response to the roster update or null if the packet is corrupt and the session * was closed down */ private IQ manageRoster(org.xmpp.packet.Roster packet) throws UnauthorizedException, UserAlreadyExistsException, SharedGroupException { IQ returnPacket = null; JID sender = packet.getFrom(); IQ.Type type = packet.getType(); try { if ((sender.getNode() == null || !RosterManager.isRosterServiceEnabled() || !userManager.isRegisteredUser(sender.getNode())) && IQ.Type.get == type) { // If anonymous user asks for his roster or roster service is disabled then // return an empty roster IQ reply = IQ.createResultIQ(packet); reply.setChildElement("query", "jabber:iq:roster"); return reply; } if (!localServer.isLocal(sender)) { // Sender belongs to a remote server so discard this IQ request Log.warn("Discarding IQ roster packet of remote user: " + packet); return null; } Roster cachedRoster = userManager.getUser(sender.getNode()).getRoster(); if (IQ.Type.get == type) { returnPacket = cachedRoster.getReset(); returnPacket.setType(IQ.Type.result); returnPacket.setTo(sender); returnPacket.setID(packet.getID()); // Force delivery of the response because we need to trigger // a presence probe from all contacts deliverer.deliver(returnPacket); returnPacket = null; } else if (IQ.Type.set == type) { for (org.xmpp.packet.Roster.Item item : packet.getItems()) { if (item.getSubscription() == org.xmpp.packet.Roster.Subscription.remove) { removeItem(cachedRoster, packet.getFrom(), item); } else { if (cachedRoster.isRosterItem(item.getJID())) { // existing item RosterItem cachedItem = cachedRoster.getRosterItem(item.getJID()); cachedItem.setAsCopyOf(item); cachedRoster.updateRosterItem(cachedItem); } else { // new item cachedRoster.createRosterItem(item); } } } returnPacket = IQ.createResultIQ(packet); } } catch (UserNotFoundException e) { throw new UnauthorizedException(e); } return returnPacket; }
private void fail(IQ request, Condition condition, org.xmpp.packet.PacketError.Type type) throws InterruptedException { IQ reply = IQ.createResultIQ(request); reply.setType(Type.error); PacketError pe = new PacketError(condition, type); reply.setError(pe); outQueue.put(reply); }
private void createExtendedErrorReply( Type type, Condition condition, String additionalElement, String additionalNamespace) { if (null == response) { response = IQ.createResultIQ(request); } response.setType(IQ.Type.error); Element standardError = new DOMElement( condition.toXMPP(), new org.dom4j.Namespace("", JabberPubsub.NS_XMPP_STANZAS)); Element extraError = new DOMElement(additionalElement, new org.dom4j.Namespace("", additionalNamespace)); Element error = new DOMElement("error"); error.addAttribute("type", type.toXMPP()); error.add(standardError); error.add(extraError); response.setChildElement(error); }
/** Creates a new notification IQ and returns it. */ private IQ createNotificationIQ( String id, String apiKey, String title, String message, String uri) { // String id = String.valueOf(System.currentTimeMillis()); Element notification = DocumentHelper.createElement(QName.get("notification", NOTIFICATION_NAMESPACE)); notification.addElement("id").setText(id); notification.addElement("apiKey").setText(apiKey); notification.addElement("title").setText(title); notification.addElement("message").setText(message); notification.addElement("uri").setText(uri); IQ iq = new IQ(); iq.setType(IQ.Type.set); iq.setChildElement(notification); return iq; }
protected void setErrorCondition(Type type, Condition condition) { if (null == response) response = IQ.createResultIQ(request); response.setType(IQ.Type.error); PacketError error = new PacketError(condition, type); response.setError(error); }