Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot feign client getting HTTP 404

I am currently just checking how to use Feign as Declarative REST client in one of my project.

following is Feign Client

@FeignClient(name = "SEARCHCABMS",configuration = AppFeignConfiguration.class)
       public interface SearchCabMsClient {

        @RequestMapping(value = "api/searchcab/locationcabtimedetail/search/getCabForLocationAfterTimeSlot", method = RequestMethod.GET)
        String  searchCabDetails(@PathVariable("fromDate") String fromDate, 
                                @PathVariable("locationId") long locationId,
                                @PathVariable("isdeleted") byte isdeleted,
                                @PathVariable("hourforbooking")int hourforbooking);
    }

This interface is autowired in one service

@Autowired
SearchCabMsClient restService;

Added EnableFeignClients to SpringBootApplication

@EnableFeignClients(basePackages = {"com.gp.cabbooking.services.feign"})

Dependencies,parent etc in pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.5.RELEASE</version>
</parent>

dependency

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-feign</artifactId>
</dependency>

I can able to see while debugging spring create proxy for my feign client i tried calling this service with the help of ribbon and it is working fine but when i execute method define in my feign client . i am getting feign.FeignException: status 404 reading

feign.FeignException: status 404 reading SearchCabMsClient#searchCabDetails(String,long,byte,int)
    at feign.FeignException.errorStatus(FeignException.java:62) ~[feign-core-8.16.2.jar:8.16.2]
    at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:91) ~[feign-core-8.16.2.jar:8.16.2]
    at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:134) ~[feign-core-8.16.2.jar:8.16.2]
    at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76) ~[feign-core-8.16.2.jar:8.16.2]
    at feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:97) ~[feign-hystrix-8.16.2.jar:8.16.2]
    at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:293) ~[hystrix-core-1.5.3.jar:1.5.3]
    at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:289) ~[hystrix-core-1.5.3.jar:1.5.3]
    at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46) ~[rxjava-1.1.5.jar:1.1.5]
    at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35) ~[rxjava-1.1.5.jar:1.1.5]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50) ~[rxjava-1.1.5.jar:1.1.5]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[rxjava-1.1.5.jar:1.1.5]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50) ~[rxjava-1.1.5.jar:1.1.5]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[rxjava-1.1.5.jar:1.1.5]
    at rx.Observable.unsafeSubscribe(Observable.java:8460) ~[rxjava-1.1.5.jar:1.1.5]
    at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51) ~[rxjava-1.1.5.jar:1.1.5]
    at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35) ~[rxjava-1.1.5.jar:1.1.5]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50) ~[rxjava-1.1.5.jar:1.1.5]
like image 526
Ganesh Pol Avatar asked Aug 12 '16 05:08

Ganesh Pol


2 Answers

You need to create a feign.ErrorDecoder. Please read this for more information https://github.com/spring-cloud/spring-cloud-openfeign/issues/118

You can also add decode404=true in your FeignClient annotation definition.

like image 55
The_Cute_Hedgehog Avatar answered Sep 19 '22 23:09

The_Cute_Hedgehog


Have you defined the url of the service you reach to using this feign client? 404 is a not found issue.

  @FeignClient(name = "SEARCHCABMS", url = "${SEARCHCABMS.service.url}", 
  configuration = ClientConfiguration.class)
  public interface SearchCabMsClient {

  }

Having a reference holder in url helps to externalize it and configure for each environment.

If you did configured the URL, double the check the rest endpoint.

like image 25
Seetharamani Tmr Avatar answered Sep 22 '22 23:09

Seetharamani Tmr