27

I am currently implementing an OpenID authentication based on this example. Now I am developing behind a network proxy, therefore the server cannot connect to google. The java proxy settings seem to not have any effect. I also found this stackoverflow question, but I cannot figure out where to put the code. How can I configure the proxy for my spring boot container?

thanks

6 Answers 6

35

Not sure if this is of any use, but I'm just working through a Spring Boot tutorial currently (https://spring.io/guides/gs/integration/) and hit a similar network proxy issue. This was resolved just by providing the JVM arguments

-Dhttp.proxyHost=your.proxy.net -Dhttp.proxyPort=8080
5
  • 1
    You are right I added this and the https parameters inside my IDE and it worked. Coincidentally I figured this out yesterday, but I didn't remember asking this question.
    – KenavR
    Commented Feb 10, 2016 at 15:48
  • Perfect !. Worked for me
    – jfk
    Commented Jun 15, 2020 at 15:19
  • 1
    If authentication is needed: -Dhttp.proxyUser=<user> -Dhttp.proxyPassword=<password> and for https authentication: -Dhttps.proxyHost=<host> -Dhttp.proxyPort=<port>
    – Davi
    Commented Jul 3, 2020 at 13:03
  • 4
    is there a way to put this in the properties file? Commented Mar 31, 2021 at 4:33
  • I couldn't get them into the properties file, but these jvm arguments can be added into the pom.xml.
    – Rory
    Commented Aug 27 at 17:16
16

Adding just the two provided arguments didn't work for me. Full list that did it is this:

-Dhttp.proxyHost=somesite.com -Dhttp.proxyPort=4321 
-Dhttps.proxyHost=somesite.com -Dhttps.proxyPort=4321 -Dhttps.proxySet=true 
-Dhttp.proxySet=true
3
  • Zero effect by me.
    – peterh
    Commented May 23, 2018 at 16:34
  • server.use-forwarded-headers=true in application.properties solved the problem. I found your flags irrelevant. However, knowing that the spring boot is maybe too complex compared to its features, maybe for others your solution could help and not mine.
    – peterh
    Commented May 23, 2018 at 16:53
  • Did you test it without the proxySet options? I think that's a nonsense property from a defunct 1997 HotJava bean, though I'd love to know if someone can confirm... Commented Jun 28, 2023 at 16:04
1

If you need this to make a call to an external service, then try to set proxy to the Client you are using (RestTemplate, etc), as below:

HttpComponentsClientHttpRequestFactory requestFactory = new 
HttpComponentsClientHttpRequestFactory();
DefaultHttpClient httpClient = (DefaultHttpClient) requestFactory.getHttpClient();
HttpHost proxy = new HttpHost("proxtserver", port);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
restTemplate.setRequestFactory(requestFactory);
1

I could able to solve the problem in two methods

Through JVM args (both http & https)

-Dhttp.proxyHost=your-http-proxy-host -Dhttp.proxyPort=8080
-Dhttps.proxyHost=your-https-proxy-host -Dhttps.proxyPort=8080

Or Programatically

public static void setProxy() {
        System.setProperty("http.proxyHost", "your-http-proxy-host");
        System.setProperty("http.proxyPort", "8080");

        System.setProperty("https.proxyHost", "your-http-proxy-host");
        System.setProperty("https.proxyPort", "8080");
    }
0

For me, server.use-forwarded-headers=true in application.properties solved the problem.

3
  • But this line is when using as reverse proxy, not for outside proxy connection.
    – mafiu
    Commented Feb 25, 2021 at 20:21
  • @mafiu Spring boot apps are practically never reverse proxying, typically an apache or an nginx is proxying to them, this apache/nginx is the reverse proxy. I do not understand your comment.
    – peterh
    Commented Feb 25, 2021 at 20:55
  • If the app has no way to access the openid server, then an openid auth is impossible. But typically it can. Maybe it needs to use an outgoing proxy server for that, there are application.properties settings for that. But not this is the hard thing. The hard thing (was in SB 1) to let it accept the X-Forward-* http headers what the rev proxy gives to it.
    – peterh
    Commented Feb 25, 2021 at 21:00
0

I couldn't get them into the properties file, but these jvm arguments can be added into the pom.xml. Add the following:

<build>
   <plugins>
      <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <configuration>
              <jvmArguments>
                  -Dhttp.proxyHost=your.proxy.net -Dhttp.proxyPort=8080 
              </jvmArguments>
           </configuration>    
        </plugin>
    </plugins>
</build>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.