Search in sources :

Example 1 with IServiceProperties

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()]);
}
Also used : Enumeration(java.util.Enumeration) TXTRecord(org.xbill.DNS.TXTRecord) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SRVRecord(org.xbill.DNS.SRVRecord) Record(org.xbill.DNS.Record) TXTRecord(org.xbill.DNS.TXTRecord) IServiceProperties(org.eclipse.ecf.discovery.IServiceProperties)

Example 2 with IServiceProperties

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);
}
Also used : Enumeration(java.util.Enumeration) Message(org.xbill.DNS.Message) SRVRecord(org.xbill.DNS.SRVRecord) Record(org.xbill.DNS.Record) TXTRecord(org.xbill.DNS.TXTRecord) TSIG(org.xbill.DNS.TSIG) Update(org.xbill.DNS.Update) IServiceProperties(org.eclipse.ecf.discovery.IServiceProperties) SimpleResolver(org.xbill.DNS.SimpleResolver) Name(org.xbill.DNS.Name)

Example 3 with IServiceProperties

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);
}
Also used : IServiceProperties(org.eclipse.ecf.discovery.IServiceProperties)

Example 4 with IServiceProperties

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;
}
Also used : ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) IServiceProperties(org.eclipse.ecf.discovery.IServiceProperties) TreeMap(java.util.TreeMap)

Example 5 with IServiceProperties

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;
}
Also used : Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IServiceProperties(org.eclipse.ecf.discovery.IServiceProperties) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) ExecutionException(org.eclipse.core.commands.ExecutionException) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

IServiceProperties (org.eclipse.ecf.discovery.IServiceProperties)7 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)3 URI (java.net.URI)2 Enumeration (java.util.Enumeration)2 TreeMap (java.util.TreeMap)2 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)2 Record (org.xbill.DNS.Record)2 SRVRecord (org.xbill.DNS.SRVRecord)2 TXTRecord (org.xbill.DNS.TXTRecord)2 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 Namespace (org.eclipse.ecf.core.identity.Namespace)1 ServiceInfo (org.eclipse.ecf.discovery.ServiceInfo)1 ServiceProperties (org.eclipse.ecf.discovery.ServiceProperties)1 IServiceID (org.eclipse.ecf.discovery.identity.IServiceID)1 IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)1 BundleContext (org.osgi.framework.BundleContext)1