[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