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= rich
and 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
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:12Does 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); }
- java : Question about Thymeleaf
- java : Using Multiple Databases in Spring Boot
- java : The List obtained from the table has only a foreign key, but I want to get the data corresponding to that key (id) and di
- java : Spring Boot does not see jsp
- Algorithm change in the evening Spring java
- How to pass an array as a parameter of a GET request string in Java (Spring)?
- I don't understand the notation to use Java (spring boot) interface without new
- java - sprin boot + mybatis + h2 does not launch the app properly
- java - is it possible to change the value of using ?
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