use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class OfflineMessageManager method getHeaders.
/**
* Returns an iterator on <tt>OfflineMessageHeader</tt> that keep information about the
* offline message. The OfflineMessageHeader includes a stamp that could be used to retrieve
* the complete message or delete the specific message.
*
* @return an iterator on <tt>OfflineMessageHeader</tt> that keep information about the offline
* message.
* @throws XMPPException If the user is not allowed to make this request or the server does
* not support offline message retrieval.
*/
public Iterator<OfflineMessageHeader> getHeaders() throws XMPPException {
List<OfflineMessageHeader> answer = new ArrayList<OfflineMessageHeader>();
DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(null, namespace);
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext(); ) {
DiscoverItems.Item item = it.next();
answer.add(new OfflineMessageHeader(item));
}
return answer.iterator();
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class ServiceDiscoveryManager method discoverItems.
/**
* Returns the discovered items of a given XMPP entity addressed by its JID and
* note attribute. Use this message only when trying to query information which is not
* directly addressable.
*
* @param entityID the address of the XMPP entity.
* @param node the optional attribute that supplements the 'jid' attribute.
* @return the discovered items.
* @throws XMPPException if the operation failed for some reason.
*/
public DiscoverItems discoverItems(String entityID, String node) throws XMPPException {
// Discover the entity's items
DiscoverItems disco = new DiscoverItems();
disco.setType(IQ.Type.GET);
disco.setTo(entityID);
disco.setNode(node);
// Create a packet collector to listen for a response.
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(disco.getPacketID()));
connection.sendPacket(disco);
// Wait up to 5 seconds for a result.
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from the server.");
}
if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
return (DiscoverItems) result;
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class ServiceDiscoveryManager method init.
/**
* Initializes the packet listeners of the connection that will answer to any
* service discovery request.
*/
private void init() {
// Register the new instance and associate it with the connection
instances.put(connection, this);
addFeature(DiscoverInfo.NAMESPACE);
addFeature(DiscoverItems.NAMESPACE);
// Add a listener to the connection that removes the registered instance when
// the connection is closed
connection.addConnectionListener(new ConnectionListener() {
public void connectionClosed() {
// Unregister this instance since the connection has been closed
instances.remove(connection);
}
public void connectionClosedOnError(Exception e) {
// ignore
}
public void reconnectionFailed(Exception e) {
// ignore
}
public void reconnectingIn(int seconds) {
// ignore
}
public void reconnectionSuccessful() {
// ignore
}
});
// Listen for disco#items requests and answer with an empty result
PacketFilter packetFilter = new PacketTypeFilter(DiscoverItems.class);
PacketListener packetListener = new PacketListener() {
public void processPacket(Packet packet) {
DiscoverItems discoverItems = (DiscoverItems) packet;
// Send back the items defined in the client if the request is of type GET
if (discoverItems != null && discoverItems.getType() == IQ.Type.GET) {
DiscoverItems response = new DiscoverItems();
response.setType(IQ.Type.RESULT);
response.setTo(discoverItems.getFrom());
response.setPacketID(discoverItems.getPacketID());
response.setNode(discoverItems.getNode());
// Add the defined items related to the requested node. Look for
// the NodeInformationProvider associated with the requested node.
NodeInformationProvider nodeInformationProvider = getNodeInformationProvider(discoverItems.getNode());
if (nodeInformationProvider != null) {
// Specified node was found, add node items
response.addItems(nodeInformationProvider.getNodeItems());
// Add packet extensions
response.addExtensions(nodeInformationProvider.getNodePacketExtensions());
} else if (discoverItems.getNode() != null) {
// Return <item-not-found/> error since client doesn't contain
// the specified node
response.setType(IQ.Type.ERROR);
response.setError(new XMPPError(XMPPError.Condition.item_not_found));
}
connection.sendPacket(response);
}
}
};
connection.addPacketListener(packetListener, packetFilter);
// Listen for disco#info requests and answer the client's supported features
// To add a new feature as supported use the #addFeature message
packetFilter = new PacketTypeFilter(DiscoverInfo.class);
packetListener = new PacketListener() {
public void processPacket(Packet packet) {
DiscoverInfo discoverInfo = (DiscoverInfo) packet;
// Answer the client's supported features if the request is of the GET type
if (discoverInfo != null && discoverInfo.getType() == IQ.Type.GET) {
DiscoverInfo response = new DiscoverInfo();
response.setType(IQ.Type.RESULT);
response.setTo(discoverInfo.getFrom());
response.setPacketID(discoverInfo.getPacketID());
response.setNode(discoverInfo.getNode());
// if the right node is chosen
if (discoverInfo.getNode() == null) {
addDiscoverInfoTo(response);
} else {
// Disco#info was sent to a node. Check if we have information of the
// specified node
NodeInformationProvider nodeInformationProvider = getNodeInformationProvider(discoverInfo.getNode());
if (nodeInformationProvider != null) {
// Node was found. Add node features
response.addFeatures(nodeInformationProvider.getNodeFeatures());
// Add node identities
response.addIdentities(nodeInformationProvider.getNodeIdentities());
// Add packet extensions
response.addExtensions(nodeInformationProvider.getNodePacketExtensions());
} else {
// Return <item-not-found/> error since specified node was not found
response.setType(IQ.Type.ERROR);
response.setError(new XMPPError(XMPPError.Condition.item_not_found));
}
}
connection.sendPacket(response);
}
}
};
connection.addPacketListener(packetListener, packetFilter);
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class AdHocCommandManager method publishCommands.
/**
* Publish the commands to an specific JID.
*
* @param jid the full JID to publish the commands to.
* @throws XMPPException if the operation failed for some reason.
*/
public void publishCommands(String jid) throws XMPPException {
ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
// Collects the commands to publish as items
DiscoverItems discoverItems = new DiscoverItems();
Collection<AdHocCommandInfo> xCommandsList = getRegisteredCommands();
for (AdHocCommandInfo info : xCommandsList) {
DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID());
item.setName(info.getName());
item.setNode(info.getNode());
discoverItems.addItem(item);
}
serviceDiscoveryManager.publishItems(jid, discoNode, discoverItems);
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project Openfire by igniterealtime.
the class SmackServiceNode method searchDiscoItems.
private static void searchDiscoItems(final XMPPConnection xmppConnection, final int maxEntries, final String startPoint, final MappedNodes mappedNodes, final int maxDepth, final int maxSearchNodes, final String protocol, final ConcurrentHashMap<String, String> visited) {
final DiscoverItems items = new DiscoverItems();
items.setTo(startPoint);
PacketCollector collector = xmppConnection.createPacketCollector(new PacketIDFilter(items.getPacketID()));
xmppConnection.sendPacket(items);
DiscoverItems result = (DiscoverItems) collector.nextResult(Math.round(SmackConfiguration.getPacketReplyTimeout() * 1.5));
if (result != null) {
final Iterator<DiscoverItems.Item> i = result.getItems();
for (DiscoverItems.Item item = i.hasNext() ? i.next() : null; item != null; item = i.hasNext() ? i.next() : null) {
deepSearch(xmppConnection, maxEntries, item.getEntityID(), mappedNodes, maxDepth, maxSearchNodes, protocol, visited);
}
}
collector.cancel();
}
Aggregations