0

The requirement in my project specifies that I need to dynamically set different proxies for my rest-template. I read these proxy values from another service and if any change is made to the proxy settings - I have to adjust my resttemplate to use these proxy settings.

This is the common code through which proxy is set for resttemplate.

    SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
    InetSocketAddress address = new InetSocketAddress(host,portNr);
    Proxy proxy = new Proxy(Proxy.Type.HTTP,address);
    factory.setProxy(proxy);

    restTemplate.setRequestFactory(factory);

But given a resttemplate autowired in my controller - Is there a way by which I can get the proxy settings - proxyHost,proxyPort et al? This would help in debugging on whether the proxy changes made are actually injected to the rest template.

I tried something like

 SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();

 requestFactory.getProxy(); //However there is only setProxy here and no getProxy
vgodly
  • 3
  • 4
  • Possible duplicate of [Replace a bean inside the spring container during run-time](https://stackoverflow.com/questions/9147324/replace-a-bean-inside-the-spring-container-during-run-time) – mat.mik Dec 10 '18 at 19:08
  • 1
    You can use reflection to access the private field `proxy` from `SimpleClientHttpRequestFactory`. –  Dec 10 '18 at 20:23

0 Answers0