Home>

I have seen enough of different guides and documentation, but I still do not fully understand, can someone tell me what needs to be done for correct work.

Description: You need to send this http requesthttps://api.giphy.com/v1/gifs/random?api_key=hidyT0yooJt3jmgfSpg9CsPge7xEEZq& tag= richand get responsive.

Logic: The controller accepts some tag parameter in the request

@GetMapping ("/gif")
public ResponseEntity getGifByCurrency (@RequestParam ("tag") String tag) {
    return gifService.getGif (tag);
}

Next comes the service call, which adds the required api_key to the tag for further work.

public ResponseEntity getGif (String tag) {
    return gifClient.getGif (API_KEY, tag);
}

Feign-client code looks like this

@FeignClient (name= "gif-client", url= "https://api.giphy.com/v1/gifs")
public interface GifClient {
     @GetMapping (value= "/random")
     ResponseEntity getGif (@RequestParam ("api_key") String api_key, @RequestParam ("tag") String tag);
}

APPENDIX 1.

The request itself is fully working through the postman fulfills with a bang. (The token in this question has been slightly changed, it should not work for you, it is given as an example) Also, when trying to pull a responsive through my feign-client, it gives this error:

Parse Error: The response headers can't include "Content-Length" with chunked encoding

APPENDIX 2.

response headers when submitting a clean http request via postman.

APPENDIX 3.

Headers obtained from the program itself. (for convenience)

[GifClient # getGif] --->
 GET https://api.giphy.com/v1/gifs/random?api_key=hidyT0yooJt3jmgfSpg9CsPge7xEEZq&
tag= rich HTTP /1.1
[GifClient # getGif] --->
 END HTTP (0-byte body)
[GifClient # getGif] <
---HTTP /1.1 200 OK (298ms)
[GifClient # getGif] accept-ranges: bytes
[GifClient # getGif] access-control-allow-credentials: true
[GifClient # getGif] access-control-allow-headers: Authorization, Content-Type, Accept, x-requested-with, cache-control, X-GIPHY-SDK-NAME, X-GIPHY-SDK-VERSION, X-GIPHY -SDK-PLATFORM
[GifClient # getGif] access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS
[GifClient # getGif] access-control-allow-origin: *
[GifClient # getGif] connection: keep-alive
[GifClient # getGif] content-type: application /json
[GifClient # getGif] date: Mon, 22 Feb 2021 16:46:38 GMT
[GifClient # getGif] strict-transport-security: max-age= 86400
[GifClient # getGif] transfer-encoding: chunked
[GifClient # getGif] vary: Accept-Encoding
[GifClient # getGif] x-cache-hits: 0, 0
[GifClient # getGif] x-cachiness-edge-actual-ttl: 120.000
[GifClient # getGif] x-cachiness-edge-rule: giphy_api_vcl_fetch_stale_if_error_val_set
[GifClient # getGif] x-cachiness-shield-actual-ttl: 120.000
[GifClient # getGif] x-cachiness-shield-rule: giphy_api_vcl_fetch_stale_if_error_val_set
[GifClient # getGif] x-robots-tag: noindex
[GifClient # getGif] x-rule-debug: 1
[GifClient # getGif] x-served-by: cache-bwi5126-BWI, cache-fra19140-FRA
[GifClient # getGif] x-timer: S1614012398.160964, VS0, VE162
[GifClient # getGif] <
---END HTTP (9498-byte body)

APPENDIX 4.

Thanks to Roman and connecting a logger to feign-client, I also found out that the request body, some {data}, is successfully received

It is best to compare and requests that are sent. And the answers that come. It's good to use the utility en.wikipedia.org/wiki/Netcat for this. Run it locally nc -k -l 10000 and replace the URL with http: //localhost: 10000

Roman Konoval2021-02-24 00:25:12

You showed this from postman, where everything works, but you need it from the program, where it does not work :)

Roman Konoval2021-02-24 00:25:12

@RomanKonoval demonstrated response headers. The application itself crashes: Could not get response.

Sergey Ivanov2021-02-24 00:25:12

Does the server actually return the result with the Content-Length and Transfer-Encoding: chunked headers? Check it out by enabling the log cloud.spring.io/spring-cloud-netflix/multi/...

Roman Konoval2021-02-24 00:25:12

@RomanKonoval completed the question, error in getting the responsive itself.

Sergey Ivanov2021-02-24 00:25:12
  • Answer # 1

    The problem is solved by the fact that the getGif method needs to return

    ResponseEntity <
    ? >
    

    Instead of

    ResponseEntity
    

    The final view of the GifClient:

    @FeignClient (name= "gif-client", url= "https://api.giphy.com/v1/gifs")
     public interface GifClient {
         @GetMapping (value= "/random")
         ResponseEntity <
    ? >
     getGif (@RequestParam ("api_key") String api_key, @RequestParam ("tag") String tag);
     }
    

    Wildcards are needed for those cases when we have no idea what is coming, so I created some DTO:

    public class GifDTO {
       private String url;
    }
    

    And now you can get a specific response:

    @FeignClient (name= "gif-client", url= "https://api.giphy.com/v1/gifs")
     public interface GifClient {
         @GetMapping (value= "/random")
         ResponseEntity <
    GifDTO >
     getGif (@RequestParam ("api_key") String api_key, @RequestParam ("tag") String tag);
     }