getURI() in EurekaServiceInstance misses custom contextPath.
I have several Spring Boot Apps with REST endpoints with custom server.contextPath's
which use @EnableDiscoveryClient to register themselves in the eureka service registry.
The applications are registered with eureka at startup and later queried
by a management application. I just found out that the URIs returned by
org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance.getUri()
only contain scheme,hostname and port but no custom context-path.
The URIs were returned by discoveryClient.getInstances(serviceId) where
discoveryClient is an EurekaDiscoveryClient.
The URI one gets via
public URI getUri() {
return DefaultServiceInstance.getUri(this);
}
looks like:
http://localhost:8761
The proper URI would be:
http://localhost:8761/mycontextpath/
I fixed tested this by locally shadowing the org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient and replacing the body of the URI getUri() method with:
@Override
public URI getUri() {
//HACK to get proper URI with context-path back
//return DefaultServiceInstance.getUri(this);
return URI.create(this.instance.getHomePageUrl());
}
With that adjustment the org.springframework.cloud.client.ServiceInstance that I got back
returned the proper service URIs.
I think the op of the issue #500 has the same problem.
Another Problem was that I needed to explicitly declare a
@Bean
public EurekaInstanceConfig eurekaConfigBean() {
return new EurekaInstanceConfigBean();
}
in order to get custom eureka instance settings in an applications.yml file taken into account at
all but I guess that's for another issue ;-)
server:
port: 9999
context-path: /admin
...
eureka:
instance:
statusPageUrlPath: /admin/manage/info
homePageUrlPath: /admin/
healthCheckUrlPath: /admin/manage/health
non-secure-port: ${server.port:9999}
...
We've not extended eureka to know about an instances context path yet.
Hi,
When will it be available to download?
@ofbizbrazil it hasn't been done, until it has, it won't be available to download.
@spencergibb,
My applications have context-path at uri, is there any workaround until this is done?
https://github.com/spring-cloud/spring-cloud-netflix/issues/737#issue-123043546
Hi @spencergibb, of course i saw that comment, but my doubt is how to apply this 'locally shadowing' mentioned in there.
I guess the spring package was patched to overwrite the class EurekaDiscoveryClient. Do you know how to do it?
Hi @ofbizbrazil,
(as a quick hack) just copy the org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient in your local source folder (e.g. src/main/java) with the same package structure and change the method in question as described.
Your classes take precedence over classes from additional libraries.
Cheers, Thomas
That's I was afraid of, doing a patch into my project to handle the class EurekaDiscoveryClient.
Yep - same here - I just used this to verify what a potential solution might be... ;-)
What's the use case? Why do you need this?
Nowadays we are limiting an application to only use a root context, and if I want to change the context-path to a different name, EurekaDiscoveryClient simply does work and nobody will know about it.
So, in my opinion that's a critical issue, taking in mind Spring Netflix only works for a specific URI.
I guess I think it's strange that you would change the context of a service and not expect clients to change. This has been marked as Help Wanted. Pull requests are welcome.
My micro-service uses a custom context-path and the clients which uses it really works fine.
The issue here is EurekaDiscoveryClient does support context-path when the method getUri() builds the URI. There should be the methods getContextPath or getHomePageUrl in EurekaServiceInstance to allow this resource.
@spencergibb I wanted to do a fix on this fella the other day
When I modified the EurekaDiscoveryClient.getUri to what @thomasdarimont suggested, DiscoveryClientConfigServiceAutoConfigurationTests fails on onWhenRequested because
DiscoveryClientConfigServiceBootstrapConfiguration sets the homePage as follows
private String getHomePage(ServiceInstance server) {
return server.getUri().toString() + "/";
}
So, I think if it is decided to change the EurekaDiscoveryClient.getUri, to modify in spring-cloud-config the homePage
Hi, I ran into the same problem and looks like the current implementation assumes only one eureka client application per JVM (web)container. Is this a restriction being imposed ? If so , then it needs to be documented else it needs to be fixed to include a configured context-path as part of the look ups
is ther any news about this matter?
Is this still the case? I´m running in to this problem at the moment using the default ribbon configuration.
I am curious. Has there been any update to this issue? Thanks!
No update. It's not high on our priorities since it can be done with properties. Pull requests welcome.
Use case for this issue: We have a java application deployed on Tomcat with a context root. The urls look like '/myapp/url_path_in_the_application. Now we have also deploy the application in on Docker. Now the urls are the same, but without the context root '/myapp', so only '/url_path_in_the_application'.
We are looking for a way that we can register the old version with context root '/myapp' and the new version with '/' as context root. For the client the invocation is easy base_url + '/url_path_in_the_application'. Base_url is created based on the registration in Eureka.