question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to configure @FeignCient with an HTTPS url (non-Eureka)?

See original GitHub issue

Hi,

I have a feign client defined like:

@FeignClient(name = "authserverTokenService", path="/authserver", url="${authserver.server}", configuration = AuthServerTokenServiceConfig.class)

The authserver service is not registered with Eureka. We specify the url in a properties file.

If I put in my properties file:

authserver.server=localhost:8087

it resolves correctly to http://localhost:8087 (looks like FeignClientsRegistrar adds the protocol?).

But beyond my local dev box, it needs to hit an HTTPS service.

If I try:

authserver.server=https://localhost:8087

it gives me an error, because the final host/url is: http://https😕/localhost:8087

I’ve tried putting the URL into the name attribute (per some other threads that I saw), but then I get:

0:31:54.651 [RMI TCP Connection(2)-127.0.0.1] ERROR [fweb,,,] o.s.boot.SpringApplication - Application startup failed (SpringApplication.java:771) 
java.lang.IllegalStateException: Service id not legal hostname (${authserver.listOfServers})
	at org.springframework.util.Assert.state(Assert.java:70)
	at org.springframework.cloud.netflix.feign.FeignClientsRegistrar.getName(FeignClientsRegistrar.java:238)
	at org.springframework.cloud.netflix.feign.FeignClientsRegistrar.registerFeignClient(FeignClientsRegistrar.java:181)

i.e. it doesn’t seem to like properties in the name attribute.

What is the correct way to configure an @FeignClient with a property-based HTTPS url?

Thanks in advance,

yngwietiger

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
yngwietigercommented, Jan 25, 2018

Thanks for looking. Yeah, I figured out the issue. It wasn’t just https, it was any url value that already had a protocol, http or https.

We have a legacy application that was converted to a Spring Boot application. In the old code, we instantiate a PropertySourcesPlaceholderConfigurer that looks into a few different files. I had my properties defined in one of those files (not in application.properties). So, when FeignClientsRegistrar.getUrl() was called, the property value for url wasn’t resolving. So url was getting built as “http://${authserver.server}”. Eventually, ${authserver.server} would get resolved to “https://localhost:8087”, making the final url value “http://https😕/localhost:8087”.

Once I placed the properties in application.properties, everything worked fine, since FeignClientsRegistrar.environment could see them.

Long term, we plan to clean up our properties files in a way that’s more compatible with Spring Boot.

In the meantime, I’m able to work around the issue by using spEL for the property values. For example:

@FeignClient(name = "authserverTokenService", path="/authserver", url="#{'${authserver.url}'}", configuration = AuthServerTokenServiceConfig.class)

That was a product of this: https://github.com/spring-cloud/spring-cloud-netflix/issues/1522

That causes FeignClientsRegistrar.getUrl() to not try to prepend a protocol. And ultimately, the url resolves to my property value.

Thoughts?

0reactions
bipin-yadavcommented, Dec 24, 2019

java.lang.IllegalStateException: Service id not legal hostname (${service.id.checkout-gateway}) at org.springframework.util.Assert.state(Assert.java:73) at org.springframework.cloud.openfeign.FeignClientsRegistrar.getName(FeignClientsRegistrar.java:103) at org.springframework.cloud.openfeign.FeignClientsRegistrar.getName(FeignClientsRegistrar.java:278) at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerFeignClient(FeignClientsRegistrar.java:233) at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerFeignClients(FeignClientsRegistrar.java:219) at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerBeanDefinitions(FeignClientsRegistrar.java:144) at org.springframework.context.annotation.ImportBeanDefinitionRegistrar.registerBeanDefinitions(ImportBeanDefinitionRegistrar.java:86) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambda$loadBeanDefinitionsFromRegistrars$1(ConfigurationClassBeanDefinitionReader.java:385) at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:384) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:148)

Getting this, is the issue with resolving config from yml file?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I configure a @FeignClient url using a properties/yml file?
I got a way to pass the environment variables in a very simple way interface FeignClient, @FeignClient(url = "https://"+"\${url}") interface ...
Read more >
23. Declarative REST Client: Feign - Spring Cloud
Feign is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it....
Read more >
Configure Feign Client in Spring Boot - Coding N Concepts
Step by step guide of how to configure feign client to consume RESTFul APIs from given endpoint in a Spring Boot application.
Read more >
SSL-Based/Secured FeignClient Example in Java ... - DZone
In simple words, how a Feign Client can make an HTTPS REST service call. Also for this project, I assumed that we have...
Read more >
Spring Boot Micro-Services with Eureka and Zuul proxy with ...
I would like to illustrate the spring-boot micro-service implementation with eureka and zuul gateway. Apart from that explain how to configure feign client...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found