1

I have a rest client written in Spring which uses singleton RestTemplate. I use the same restTemplate to invoke services hosted within intranet and outside of the network (internet). Requests outside of network passes via a proxy.

I have added a proxy in my code as below

SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = SimpleClientHttpRequestFactory) requestFactory;
Proxy proxy = new Proxy(Type.HTTP , new InetSocketAddress(proxyHost, StringUtils.isNotBlank(proxyPort) ? Integer.parseInt(proxyPort) : 80));
                simpleClientHttpRequestFactory.setProxy(proxy);
                restTemplate.setRequestFactory(simpleClientHttpRequestFactory);

However, with proxy sitting in between, I cannot access services hosted in the same network (intranet). Is there a way to bypass proxy conditionally while invoking actual services?

pvpkiran
  • 25,582
  • 8
  • 87
  • 134
shankulk
  • 534
  • 1
  • 4
  • 23
  • Just create two RestTemplates one for internal and one for external – pvpkiran Feb 15 '18 at 08:58
  • Wanted to avoid creating a separate RestTemplate. Could not make anything else working. Finally created two restTemplates. Thanks for your response. – shankulk Feb 16 '18 at 07:21
  • 2
    Possible duplicate of [Using RestTemplate, how to send the request to a proxy first so I can use my junits with JMeter?](https://stackoverflow.com/questions/3687670/using-resttemplate-how-to-send-the-request-to-a-proxy-first-so-i-can-use-my-jun) – Alex K Jun 29 '18 at 08:33

0 Answers0