use of org.eclipse.ecf.discovery.IServiceProperties in project ecf by eclipse.
the class DnsSdServiceID method toTXTRecords.
/**
* @param aRecord The corresponding SRVRecord
* @return A relative TXT record independent of a given domain/zone
* @throws IOException
*/
Record[] toTXTRecords(final Record aRecord) throws IOException {
final List result = new ArrayList();
final IServiceProperties properties = serviceInfo.getServiceProperties();
final Enumeration enumeration = properties.getPropertyNames();
while (enumeration.hasMoreElements()) {
final Object property = enumeration.nextElement();
final String key = property.toString();
final String value = (String) properties.getProperty(key).toString();
final long ttl = serviceInfo.getTTL();
// $NON-NLS-1$
result.add(new TXTRecord(aRecord.getName(), DClass.IN, ttl, key + "=" + value));
}
return (Record[]) result.toArray(new Record[result.size()]);
}
use of org.eclipse.ecf.discovery.IServiceProperties in project ecf by eclipse.
the class DnsSdAdvertiserServiceTest method createTXTRecords.
private void createTXTRecords() throws TextParseException, IOException, UnknownHostException {
final Name zone = Name.fromString(DnsSdTestHelper.REG_DOMAIN + ".");
final Name name = Name.fromString("_" + DnsSdTestHelper.REG_SCHEME + "._" + DnsSdTestHelper.PROTO, zone);
Update update = null;
final IServiceProperties properties = serviceInfo.getServiceProperties();
final Enumeration enumeration = properties.getPropertyNames();
while (enumeration.hasMoreElements()) {
final Object property = enumeration.nextElement();
final String key = property.toString();
final String value = (String) properties.getProperty(key).toString();
final Record record = Record.fromString(name, Type.TXT, DClass.IN, serviceInfo.getTTL(), key + "=" + value, zone);
update = new Update(zone);
update.add(record);
}
final SimpleResolver resolver = new SimpleResolver(DnsSdTestHelper.DNS_SERVER);
resolver.setTCP(true);
resolver.setTSIGKey(new TSIG(DnsSdTestHelper.TSIG_KEY_NAME, DnsSdTestHelper.TSIG_KEY));
final Message response = resolver.send(update);
final int rcode = response.getRcode();
assertTrue("", rcode == 0);
}
use of org.eclipse.ecf.discovery.IServiceProperties in project ecf by eclipse.
the class ServiceInfoTest method testGetServiceProperties.
/**
* Test method for {@link org.eclipse.ecf.discovery.ServiceInfo#getServiceProperties()}.
*/
public void testGetServiceProperties() {
final IServiceProperties sprops = serviceInfo.getServiceProperties();
assertEquals(sprops, serviceProperties);
}
use of org.eclipse.ecf.discovery.IServiceProperties in project ecf by eclipse.
the class ServiceInfoFactory method createServiceProperties.
/**
* @param endpointDescription endpoint description
* @param advertiser advertiser
* @param serviceTypeID serviceTypeID
* @param serviceName serviceName
* @param uri uri
* @return IServiceProperties for the given input parameters
* @since 3.0
*/
protected IServiceProperties createServiceProperties(org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription, IDiscoveryAdvertiser advertiser, IServiceTypeID serviceTypeID, String serviceName, URI uri) {
Map<String, Object> props = endpointDescription.getProperties();
Map<String, Object> result = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
for (String key : props.keySet()) if (!discoveryProperties.contains(key))
result.put(key, props.get(key));
ServiceProperties spResult = new ServiceProperties();
encodeServiceProperties(new EndpointDescription(result), spResult);
return spResult;
}
use of org.eclipse.ecf.discovery.IServiceProperties in project ecf by eclipse.
the class DOSGiReflectiveRemoteServiceHandler method execute.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
* .ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
final IServiceInfo serviceInfo = DiscoveryHandlerUtil.getActiveIServiceInfoChecked(event);
final IServiceProperties serviceProperties = serviceInfo.getServiceProperties();
final String clazz = serviceProperties.getPropertyString(Constants.OBJECTCLASS);
final String serviceId = new String(serviceProperties.getPropertyString(RemoteConstants.SERVICE_IMPORTED_ENDPOINT_SERVICE_ID));
final String containerId = new String(serviceProperties.getPropertyString(RemoteConstants.SERVICE_IMPORTED_ENDPOINT_ID));
// get the service via the osgi service registry
final BundleContext context = Activator.getDefault().getBundle().getBundleContext();
final Filter filter;
try {
filter = context.createFilter(// $NON-NLS-1$ //$NON-NLS-2$
"(&(" + Constants.OBJECTCLASS + "=" + clazz + ")" + "(" + IDistributionConstants.SERVICE_IMPORTED + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"=*" + ")" + "(" + RemoteConstants.SERVICE_IMPORTED_ENDPOINT_ID + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"=" + containerId + ")(" + RemoteConstants.SERVICE_IMPORTED_ENDPOINT_SERVICE_ID + "=" + serviceId + // $NON-NLS-1$ //$NON-NLS-2$
"))");
} catch (InvalidSyntaxException e1) {
MessageDialog.openError(null, Messages.DOSGiReflectiveRemoteServiceHandler_HandlerInvocationFailed, NLS.bind(Messages.DOSGiReflectiveRemoteServiceHandler_FilterCreationFailed, e1.getMessage()));
return null;
}
final ServiceTracker serviceTracker = new ServiceTracker(context, filter, null);
serviceTracker.open();
final ServiceReference serviceReference = serviceTracker.getServiceReference();
if (serviceReference == null) {
MessageDialog.openError(null, Messages.DOSGiReflectiveRemoteServiceHandler_HandlerInvocationFailed, NLS.bind(Messages.DOSGiReflectiveRemoteServiceHandler_NoServiceMatch, filter.toString()));
return null;
}
// obtain the remote service reference from the local service ref (cool
// ECF feature, huh?)
final IRemoteService remoteService = (IRemoteService) serviceReference.getProperty(IDistributionConstants.SERVICE_IMPORTED);
if (remoteService == null) {
MessageDialog.openError(null, Messages.DOSGiReflectiveRemoteServiceHandler_HandlerInvocationFailed, Messages.DOSGiReflectiveRemoteServiceHandler_RemoteServiceUnresolveable);
return null;
}
try {
executeMethodInvocationDialog(Class.forName(clazz), remoteService);
} catch (ClassNotFoundException e) {
MessageDialog.openError(null, Messages.DOSGiReflectiveRemoteServiceHandler_HandlerInvocationFailed, e.getLocalizedMessage());
throw new ExecutionException(e.getMessage(), e);
}
return null;
}
Aggregations