Skip to main content

Help with DiscoveryService !!!

2 replies [Last post]
fxsx2
Offline
Joined: 2009-08-03

hi to all

sorry for my English , but need much help with a problem of DiscoveryService

I'm trying to find Advertisements of pipes remotely, but it does the following error in my code

04/08/2009 00:57:09 net.jxta.impl.discovery.DiscoveryServiceImpl processResponse
WARNING: Uncaught Throwable in listener (PipeClient) :Executor - 3
java.lang.ClassCastException: net.jxta.impl.protocol.ModuleImplAdv cannot be cast to net.jxta.protocol.PipeAdvertisement

below the code that generates this error

public void discoveryEvent(DiscoveryEvent ev){

DiscoveryResponseMsg res;
PipeAdvertisement pipeAdv;
Enumeration en;

res = ev.getResponse();

en = res.getAdvertisements();

if(en != null){

while(en.hasMoreElements()){
pipeAdv = (PipeAdvertisement)en.nextElement();
ta.append("" + pipeAdv + "\n");

}//while
}//if

}//end of discoveryEvent

Please could someone give me an example of how to resolve this?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
fxsx2
Offline
Joined: 2009-08-03

Thank you very much!

wayke
Offline
Joined: 2007-08-09

you can't case net.jxta.impl.protocol.ModuleImplAdv to net.jxta.protocol.PipeAdvertisement. if you search the Advertisement with the type is ADV,then will response all type of Adv(PipeAdv ,ModulAdv ...). so you must make sure the PipeAdv is really a PipeAdv. you can modify your Code like this.

public void discoveryEvent(DiscoveryEvent ev){

DiscoveryResponseMsg res;
PipeAdvertisement pipeAdv;
Enumeration en;

res = ev.getResponse();

en = res.getAdvertisements();
Object obj = null;
if(en != null ){

while(en.hasMoreElements()){
obj = en.nextElement();
if(obj instanceof PipeAdvertisement){
pipeAdv = (PipeAdvertisement)obj;
ta.append("" + pipeAdv + "\n");

}

}//while
}//if

}//end of discoveryEvent

sorry to my English..