com.addc.commons.slp.ServiceURLEnumeration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of addc-slp Show documentation
Show all versions of addc-slp Show documentation
The addc-slp library supplies client classes for registering objects with a Service Location Protocol Daemon and
for looking theses objects up later.
package com.addc.commons.slp;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.text.MessageFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.addc.commons.slp.configuration.SLPConfig;
import com.addc.commons.slp.messages.SLPMessageHeader;
import com.addc.commons.slp.messages.UAMessage;
/**
* The ServiceURLEnumeration supplies an enumerator for returned
* {@link ServiceURL}s
*/
public class ServiceURLEnumeration extends AbstractSlpEnumeration {
private static final Logger LOGGER= LoggerFactory.getLogger(ServiceURLEnumeration.class);
/**
* Create a new ServiceURLEnumeration
*
* @param config
* The configuration to use
* @param netManager
* The NetworkManagerImpl
* @param message
* The request message
* @throws ServiceLocationException
* If there is an error sending or receiving data
*/
public ServiceURLEnumeration(SLPConfig config, NetworkManager netManager, UAMessage message)
throws ServiceLocationException {
super(config, netManager, message);
}
@Override
protected void parseResponse(DataInputStream dis, SLPMessageHeader header)
throws IOException, ServiceLocationException {
if (header.getFunctionId() != SLPConstants.SRVRPLY) {
String reason= MessageFormat.format("Expected function Id {0} received {1}", SLPConstants.SRVRPLY,
header.getFunctionId());
throw new ServiceLocationException(reason, SLPConstants.INTERNAL_SYSTEM_ERROR);
}
int size= dis.readShort();
LOGGER.debug("Received SRVRPLY {} size {}", header.getFunctionId(), size);
for (int i= 0; i < size; i++) {
try {
ServiceURL result= new ServiceURL(config);
result.readExternal(dis);
if (config.isSecurityEnabled()) {
if (result.verify()) {
received.add(result);
}
} else {
received.add(result);
}
} catch (EOFException e) {
if (header.isOverflow()) {
break;
}
throw e;
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy