Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ecf-dev] Consuming existing REST and dynamically changing the endpoint URL

Hi

Am 05.10.2015 um 14:46 schrieb Marin Orlić:
Hi,

what would be the preferred method of dynamically changing the endpoint URL registered for a remote REST service? 

I can register the service with an EDEF initially, but the requirement is that the endpoint must be changeable via workspace preferences. My guess is that a listener on preference change could trigger service registration using dynamically generated EDEF properties? How to start with that and what properties need to be changed along with endpoint URI (endpoint.service.id?).
I had a similar issue (my remote server can be selected by user at login time - so it's not know in advance) and was able to solve it by creating an endpoint description programmatically (look at the ECF Wiki there is some documentation on it). It should look like something like this:

    private EndpointDescription getEndpointDescription(final Class<?> service) {
        final Map<String, Object> props = new HashMap<String, Object>();
        String host = appServerService.getHost();               props.put(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE,
                StringID.class.getName());
        props.put(ENDPOINT_ID, "ecftcp://" + host + ":8889/server");
        final Package package1 = service.getPackage();
        props.put(ENDPOINT_PACKAGE_VERSION_ + package1.getName(), getPackageVersion(package1));
        props.put("objectClass", new String[] { service.getName() });
        props.put(REMOTE_CONFIGS_SUPPORTED, new String[] { "ecf.generic.server" });
        props.put(REMOTE_INTENTS_SUPPORTED, new String[] { "passByValue", "exactlyOnce", "ordered" });
        props.put(SERVICE_IMPORTED, "true");
        props.put(SERVICE_IMPORTED_CONFIGS, new String[] { "ecf.generic.server" });

        return new EndpointDescription(props);
    }

And then register that endpoint desciption using

remoteServiceAdmin.importService(endpointDescription);

The remoteServiceAdmin Service is an org.osgi.service.remoteserviceadmin.RemoteServiceAdmin and in my case is injected/bound via a DS declaration.

Hope that helps you.

Peter


Back to the top