Search in sources :

Example 1 with Type

use of org.xmpp.packet.IQ.Type in project Openfire by igniterealtime.

the class SearchPlugin method handleIQRequest.

/**
	 * Handles IQ requests. This method throws an IllegalArgumentException if an IQ stanza is supplied that is not a request (if the stanza
	 * is not of type 'get' or 'set'). This method will either throw an Exception, or return a non-null IQ stanza of type 'error' or
	 * 'result', as XMPP Core specifies that <strong>all</strong> IQ request stanza's (type 'get' or 'set') MUST be replied to.
	 * 
	 * @param iq
	 *            The IQ stanza that forms the request.
	 * @return The response to the request.
	 */
private IQ handleIQRequest(IQ iq) {
    // 'final' to ensure that it is set.
    final IQ replyPacket;
    if (iq == null) {
        throw new IllegalArgumentException("Argument 'iq' cannot be null.");
    }
    final IQ.Type type = iq.getType();
    if (type != IQ.Type.get && type != IQ.Type.set) {
        throw new IllegalArgumentException("Argument 'iq' must be of type 'get' or 'set'");
    }
    final Element childElement = iq.getChildElement();
    if (childElement == null) {
        replyPacket = IQ.createResultIQ(iq);
        replyPacket.setError(new PacketError(Condition.bad_request, org.xmpp.packet.PacketError.Type.modify, "IQ stanzas of type 'get' and 'set' MUST contain one and only one child element (RFC 3920 section 9.2.3)."));
        return replyPacket;
    }
    final String namespace = childElement.getNamespaceURI();
    if (namespace == null) {
        replyPacket = IQ.createResultIQ(iq);
        replyPacket.setError(Condition.feature_not_implemented);
        return replyPacket;
    }
    if (namespace.equals(NAMESPACE_JABBER_IQ_SEARCH)) {
        replyPacket = handleSearchRequest(iq);
    } else if (namespace.equals(IQDiscoInfoHandler.NAMESPACE_DISCO_INFO)) {
        replyPacket = handleDiscoInfo(iq);
    } else if (namespace.equals(IQDiscoItemsHandler.NAMESPACE_DISCO_ITEMS)) {
        replyPacket = IQ.createResultIQ(iq);
        replyPacket.setChildElement("query", IQDiscoItemsHandler.NAMESPACE_DISCO_ITEMS);
    } else {
        // don't known what to do with this.
        replyPacket = IQ.createResultIQ(iq);
        replyPacket.setError(Condition.feature_not_implemented);
    }
    return replyPacket;
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError) Type(org.xmpp.packet.IQ.Type)

Aggregations

Element (org.dom4j.Element)1 IQ (org.xmpp.packet.IQ)1 Type (org.xmpp.packet.IQ.Type)1 PacketError (org.xmpp.packet.PacketError)1