0

I'm trying to make a rest call using feign.

How do I do a Gzip compression in Java using Feign client builder in non declarative way as I don't have application.yml to do it in traditional way.

Is there a way to using Encoder or Interceptor method of feign client builder to do the same?

samabcde
  • 6,988
  • 2
  • 25
  • 41

1 Answers1

0

From documentation Feign request/response compression, we can enable GZIP for request and response by setting below properties:

feign.compression.request.enabled=true
feign.compression.response.enabled=true

Since you don't have application.yml(quite strange when you are using spring boot), we can set the programmatically by referring to How can I override Spring Boot application.properties programmatically?.

@SpringBootApplication
public class DemoFeignApplication {

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(DemoFeignApplication.class);
        Properties properties = new Properties();
        properties.put("feign.compression.request.enabled", "true");
        properties.put("feign.compression.response.enabled", "true");
        application.setDefaultProperties(properties);
        application.run(args);
        SpringApplication.run(DemoFeignApplication.class, args);
    }
}
samabcde
  • 6,988
  • 2
  • 25
  • 41
  • We are using a shared project across multiple teams for e2e test. I need to build a feign client with Gzip compression locally in my class. setting in application.yml applies globally which is restricted. – vignesh muralidharan Sep 30 '21 at 03:08
  • So are you trying to configure 1 specific class with `@FeignClient`? Can you provide some sample code in your post? – samabcde Sep 30 '21 at 03:18