1

I am trying t call another service using Spring Cloud's Open Feign but here is the response I keep getting:

{
  "timestamp": 1579015052962,
  "status": 500,
  "error": "Internal Server Error",
  "message": "auth-service: Name or service not known executing GET http://auth-service/api/v1/auth",
  "path": "/api/v1/event"
}

Here's my code:

package com.eventmanager.events.client;

import com.eventmanager.events.client.mappings.Auth;
import com.eventmanager.events.config.CustomFeignClientConfig;
import com.eventmanager.events.responses.Response;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;

@FeignClient(name = "auth-service", configuration = CustomFeignClientConfig.class)
public interface AuthClient {
  @GetMapping("/api/v1/auth")
  public Response<Auth> getLoggedUser(@RequestHeader(value = "Authorization") String authorization);
}

I configured Feign to use the OkHttp client and I'm not sure if it's responsible for the error:

package com.eventmanager.events.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import feign.okhttp.OkHttpClient;

@Configuration
public class CustomFeignClientConfig {
  @Bean
  public OkHttpClient client() {
    return new OkHttpClient();
  }
}

3 Answers3

1

If you are using Finchey.SR1, You can check this https://stackoverflow.com/a/52727544 There seems to be an issue with ContentPath in that cloud version.

Grim42
  • 49
  • 1
  • 11
1

Guess I'm a little late to the party. The following dependency can be added to your pom.xml file. If you you have feign-okhttp dependency then you should be having this dependency by default.

<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>5.0.0-alpha.6</version>
</dependency>

Now instead of importing feign.okhttp.OkHttpClient; import okhttp3.OkHttpClient.

So your class should look like below.

package com.eventmanager.events.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import okhttp3.OkHttpClient;

@Configuration
public class CustomFeignClientConfig {
  @Bean
  public OkHttpClient client() {
    return new OkHttpClient();
  }
}

Also consider adding the below entry in your application.properties file. This will stop Feign from using the default http client.

feign.httpclient.enabled=false

You may refer to this post for more information

0

May be because you have not specified base URL. for client & it is taking base URL as auth-service.

@FeignClient(name = "auth-service", configuration = CustomFeignClientConfig.class, url = "http://lcoalhost:8080")
public interface AuthClient {
  @GetMapping("/api/v1/auth")
  public Response<Auth> getLoggedUser(@RequestHeader(value = "Authorization") String authorization);
}
Jaganath Kamble
  • 506
  • 2
  • 10