2

/I'm trying to use a Feign-client to communicate another rest service which will return status code 204 with no body/

public interface DepartmentApi { 
    @RequestLine("GET /department/nocontent") /*Department Client*/
    @Headers("Content-Type: application/json")
    ResponseEntity<Void> getDepartment();
}


@Component
public class ClientApiFactory {
    @Bean
    @RequestScope
    public DepartmentApi getDepartmentApi() { /*Bean for Department client  */
        return HystrixFeign.builder()
                .logLevel(Logger.Level.BASIC)
                .decoder(new JacksonDecoder())
                .encoder(new JacksonEncoder())
                .target(DepartmentApi.class, "http://localhost:8080");
    }
}


@GetMapping(value = "/nocontent") /*Department Service which is running on 8080*/
ResponseEntity<Void> noContent() {
    return new ResponseEntity(HttpStatus.NO_CONTENT);
}

I would like to retrieve the status code from the response for the void methods, but with a void method there is no way to get to the status ,it's returns[ReponseEntity] null.

Is there a way to retrieve the HTTP status code from a Feign method for a resource that returns no body? They all fail with a nullpointer exception because of the lack of response body.

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34

0 Answers0