Roufid

Defining a proxy in Spring RestTemplate

Spring

By default, RestTemplate don’t use a proxy to make the http calls and if you work in an environment that requires one, you will encounter the following exception :

This tutorial will show two ways to fix it.

Defining the proxy in RestTemplate

The first way to solve the problem is by setting a proxy in the RestTemplate object as the following :

Defining the proxy in the System properties

Another solution to set the proxy is by defining it in the system properties as below :

Be very careful with the second solution because it will set up the proxy for all the applications that run on the same JVM

References