powered by Jive Software

ServiceDiscoveryManager questions

Just have a question about the ServiceDiscovery manager. Can you get all services available on a server?

This code here:

private void testServiceDiscovery()
     {
          try {                ServiceDiscoveryManager manager = new ServiceDiscoveryManager( Globals.buddyList.getConnection() );
               DiscoverItems items = manager.discoverItems( "netmindz.net" );
               Iterator i = items.getItems();
               com.valhalla.Logger.debug( "Discovery manager searching jabber.org" );                while( i.hasNext() )
               {
                    DiscoverItems.Item item = (DiscoverItems.Item)i.next();
                    com.valhalla.Logger.debug( "\tAction: " + item.getAction() +
                         " Name: " + item.getName() + " Node: " + item.getNode() );
               }                com.valhalla.Logger.debug( "Service Discovery completed." );
          }
          catch( Exception e )
          {
               e.printStackTrace();
          }
     }

doesn’'t do what is expected. I get this stacktrace:

(404) Not Found
        at org.jivesoftware.smackx.ServiceDiscoveryManager.discoverItems(ServiceDiscoveryManager.java:362)
        at org.jivesoftware.smackx.ServiceDiscoveryManager.discoverItems(ServiceDiscoveryManager.java:330)

am I doing this wrong?

Adam

Adam,

It’‘s strange that the server is returning an error since you are sending the disco request to the server itself. You could try the same code against jabber.org and you’‘ll see that it’'ll return its items. The 404 error means that the target entity (netmindz.net in your case) does not exist.

If that’‘s the case, I’'d recommend getting in contact with the people responsible for the netmindz.net server.

Regards,

– Gato

I do get items back from jabber.org - but most of the servers that I usually get stuff back from in PSI’‘s service discovery return the 404 or 405. Here’'s some I tried:

jabber.linux.it

jabber.hawkesnest.net

netmindz.net

amessage.info

A 405 error means that you are not allowed to get that info. So in that case there is nothing you can do.

In the cases were you are getting the 404 error you should contact the administrators/owner of the server since you shouldn’'t be getting that error.

According the disco spec the 404 error means that: “The JID or JID+NodeID of the specified target entity does not exist and that fact can be divulged in accordance with privacy and security considerations and policies”. AFAIK, you are sending the disco request to the server itself so it shouldn’'t complain about an invalid JID.

Regards,

– Gato

I have tested this code…

i have another problem…

the code is :

private void testServiceDiscovery()

{

try {

ServiceDiscoveryManager manager = new ServiceDiscoveryManager(connection);

DiscoverItems items = manager.discoverItems( connection.getHost() );

Iterator i = items.getItems();

System.out.println( items.getNode() );

System.out.println( "Discovery manager searching " + connection.getHost());

System.out.println( i.hasNext() );

while( i.hasNext() )

{

DiscoverItems.Item item = (DiscoverItems.Item)i.next();

System.out.println(items);

System.out.println( "\tAction: " + item.getAction() +

" Name: " + item.getName() + " Node: " + item.getNode() );

}

System.out.println( “Service Discovery completed.” );

}

catch( Exception e )

{

e.printStackTrace();

}

}

the return is :

at org.jivesoftware.smackx.ServiceDiscoveryManager.discoverItems(ServiceDiscoveryM anager.java:425)

at org.jivesoftware.smackx.ServiceDiscoveryManager.discoverItems(ServiceDiscoveryM anager.java:389)

at euja.GUI.ContactListPanel.testServiceDiscovery(ContactListPanel.java:144)

where line 144 is :

DiscoverItems items = manager.discoverItems( connection.getHost() );

Nahuel,

Are you getting an exception? In your post the first line of what you are getting seems to be missing. If you are getting an exception, please post also the XML packets that Smack is receiving from the server. You can open the debugger window to get that info.

Regards,

– GAto

Yes i get an exception :

java.lang.ClassCastException

at org.jivesoftware.smackx.ServiceDiscoveryManager.discoverItems(ServiceDiscoveryM anager.java:425)

at org.jivesoftware.smackx.ServiceDiscoveryManager.discoverItems(ServiceDiscoveryM anager.java:389)

at euja.GUI.ContactListPanel.testServiceDiscovery(ContactListPanel.java:144)

at euja.GUI.ContactListPanel.jToggleButton1ActionPerformed(ContactListPanel.java:1 20)

at euja.GUI.ContactListPanel.access$000(ContactListPanel.java:21)

at euja.GUI.ContactListPanel$1.actionPerformed(ContactListPanel.java:59)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.j ava:1817)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)

at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:273)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.ja va:245)

at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:227)

at java.awt.Component.processMouseEvent(Component.java:5093)

at java.awt.Component.processEvent(Component.java:4890)

at java.awt.Container.processEvent(Container.java:1566)

at java.awt.Component.dispatchEventImpl(Component.java:3598)

at java.awt.Container.dispatchEventImpl(Container.java:1623)

at java.awt.Component.dispatchEvent(Component.java:3439)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)

at java.awt.Container.dispatchEventImpl(Container.java:1609)

at java.awt.Window.dispatchEventImpl(Window.java:1585)

at java.awt.Component.dispatchEvent(Component.java:3439)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java: 197)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:15 0)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

and the packet received is :

<iq id=’‘Va7z8-5’’ to=’‘test@develog.com/Smack’’ type=’‘result’’ from=’‘develog.com’’><query xmlns=’‘http://jabber.org/protocol/disco#items’’><item jid=’‘conference.develog.com’’ name=’‘Public Conferencing’’/><item jid=’‘aim.develog.com’’ name=’‘Relais AIM’’/>

<item jid=’‘yahoo.develog.com’’ name=’‘Relais Yahoo! Messenger’’/><item jid=’‘jud.develog.com’’ name=’‘Annuaire des Utilisateurs Jabber’’/><item jid=’‘msn.develog.com’’ name=’‘Relais MSN’’/><item jid=’‘icq.develog.com’’ name=’‘Relais ICQ’’/>

Nahuel,

My best guess is that the META-INF folder is not in your classpath. It seems that the smack.providers file is not being found so instead of retrieving an instance of DiscoverItems, Smack is generating an internal IQ representation of the received XML which is generating the ClassCastException.

Regards,

– Gato

the META-INF Folder ?

what META-INF Folder ?

i have to create a META-INF foler in my jar package ?

Nahuel,

Sorry for not being very clear in my previous post. Did you build the jar files that you are using from the souce code or are you using the jar files that came with smack-1.4.0.zip?

If you are building the jar files from the source code just make sure that the file smackx.jar contains the folder META-INF which in turns contains the smack.providers file. I still suspect that there must be a configuration problem.

Other option that could be of help is if you can obtain the real class that is being casted.

Regards,

– Gato

i’'m using the source of the smack 1.4.0 dev package.

for the moment i have not make the jar file.

I have to have a jar file of the smack lib ?

Thanks it’'s works now using the jar file until mount the source files.

Nahuel,

Glad to hear that everything is now working fine. If you want to use the source code instead of the jar files just remember to add the resources folder to your classpath.

Regards,

– Gato