use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.
the class SLPDaemonImpl method registerService.
/**
* register a service with the SLP framework. For the scopes, where DAs are
* known, the service will be registered with all DAs.
*
* @param reg
* the ServiceRegistration.
*/
private void registerService(final ServiceRegistration reg) {
Service service = new Service(reg);
for (Iterator scopeIter = reg.scopeList.iterator(); scopeIter.hasNext(); ) {
String scope = (String) scopeIter.next();
scope = scope.toLowerCase();
synchronized (registeredServices) {
SLPUtils.addValue(registeredServices, scope, service);
}
if (reg.url.getLifetime() > ServiceURL.LIFETIME_PERMANENT) {
synchronized (serviceDisposalQueue) {
long next = System.currentTimeMillis() + (reg.url.getLifetime() * 1000);
ArrayList keys = new ArrayList(serviceDisposalQueue.keySet());
for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
Object key = iter.next();
if (serviceDisposalQueue.get(key).equals(reg.url)) {
serviceDisposalQueue.remove(key);
}
}
serviceDisposalQueue.put(new Long(next), reg.url);
serviceDisposalQueue.notifyAll();
}
}
SLPCore.platform.logTraceReg("REGISTERED " + reg.url);
// register the service with all known DAs in the scopes
List daList = (List) SLPCore.dAs.get(scope);
// try to find one
if ((daList == null || daList.isEmpty()) && !SLPCore.noDiscovery) {
try {
SLPCore.daLookup(Arrays.asList(new String[] { (String) scope }));
// wait a short time for incoming replies
synchronized (SLPCore.dAs) {
try {
SLPCore.dAs.wait(SLPCore.CONFIG.getWaitTime());
} catch (InterruptedException e) {
}
}
daList = (List) SLPCore.dAs.get(scope);
} catch (ServiceLocationException sle) {
SLPCore.platform.logError(sle.getMessage(), sle.fillInStackTrace());
}
}
if (daList != null && !daList.isEmpty()) {
final String[] dAs = (String[]) daList.toArray(new String[daList.size()]);
final ServiceRegistration announcement = new ServiceRegistration(reg.url, reg.serviceType, reg.scopeList, reg.attList, reg.locale);
announcement.authBlocks = reg.authBlocks;
for (int i = 0; i < dAs.length; i++) {
try {
announceService(dAs[i], announcement);
SLPCore.platform.logTraceReg("ANNOUNCED " + announcement.url + " to " + dAs[i]);
} catch (ServiceLocationException e) {
// remove DA from list
SLPUtils.removeValueFromAll(SLPCore.dAs, dAs[i]);
SLPCore.dASPIs.remove(dAs[i]);
SLPCore.platform.logError(e.getMessage(), e.fillInStackTrace());
}
}
}
}
}
use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.
the class SLPMessage method attributeStringToList.
/**
* @param input
* @return
* @throws ServiceLocationException
*
* @author Markus Alexander Kuppe
* @since 1.1
*/
protected List attributeStringToList(String input) throws ServiceLocationException {
if ("".equals(input)) {
return new ArrayList();
}
Parser parser = new Parser();
try {
Rule parse = parser.parse("attr-list", input);
AttributeListVisitor visitor = new AttributeListVisitor();
parse.visit(visitor);
return visitor.getAttributes();
} catch (IllegalArgumentException e) {
throw new ServiceLocationException(ServiceLocationException.PARSE_ERROR, e.getMessage());
} catch (ParserException e) {
throw new ServiceLocationException(ServiceLocationException.PARSE_ERROR, e.getMessage());
}
}
use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.
the class AttributeParserTest method testByteAttributeType.
/**
* Test method for {@link ch.ethz.iks.slp.impl.SLPMessage#attributeStringToList(java.lang.String)}.
*/
public void testByteAttributeType() {
SLPTestMessage stm = new SLPTestMessage();
String input = BYTE;
List attributeStringToList = new ArrayList();
try {
attributeStringToList = stm.attributeStringToList(input);
} catch (ServiceLocationException e) {
fail("Input " + input + " must be valid");
}
assertEquals(1, attributeStringToList.size());
assertTrue(attributeStringToList.contains(BYTE));
}
use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.
the class AttributeParserTest method testAllAttributeType.
/**
* Test method for {@link ch.ethz.iks.slp.impl.SLPMessage#attributeStringToList(java.lang.String)}.
*/
public void testAllAttributeType() {
SLPTestMessage stm = new SLPTestMessage();
String input = STRING + "," + BOOLEAN + "," + BYTE + "," + VENDOR_WITH_EN + "," + POS_INTEGER + "," + NEG_INTEGER;
List attributeStringToList = new ArrayList();
try {
attributeStringToList = stm.attributeStringToList(input);
} catch (ServiceLocationException e) {
fail("Input " + input + " must be valid");
}
assertEquals(6, attributeStringToList.size());
assertTrue(attributeStringToList.contains(NEG_INTEGER));
assertTrue(attributeStringToList.contains(POS_INTEGER));
assertTrue(attributeStringToList.contains(VENDOR_WITH_EN));
assertTrue(attributeStringToList.contains(STRING));
assertTrue(attributeStringToList.contains(BOOLEAN));
assertTrue(attributeStringToList.contains(BYTE));
}
use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.
the class AttributeReply method getAuthData.
/**
* get the authentication data.
*
* @param spiStr
* the SPI.
* @param timestamp
* the timestamp.
* @return the auth data.
* @throws ServiceLocationException
* in case of IO errors.
*/
private byte[] getAuthData(final String spiStr, final int timestamp) throws ServiceLocationException {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
dos.writeUTF(spiStr);
dos.writeUTF(listToString(attributes, ","));
dos.writeInt(timestamp);
return bos.toByteArray();
} catch (IOException ioe) {
throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR, ioe.getMessage());
}
}
Aggregations