8

How do I specify a http proxy to use when running a spring-boot fat war as a tomcat server?

I have tried the following which is not working.

java -jar my-application.war --http.proxyHost=localhost --http.proxyPort=3128 --https.proxyHost=localhost --https.proxyPort=3128

and

java -jar my-application.war -Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128
4
  • I haven't tried this so I'm not making it an answer, but try java -jar my-application.war -Dhttp.proxyHost localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost localhost -Dhttps.proxyPort=3128 Commented Nov 27, 2015 at 7:05
  • that does not work either. Commented Nov 29, 2015 at 21:53
  • 1
    From Spring Boot Documentation, it looks like you need to make sure your proxy server is adding the X-Forwarded-For and X-Forwarded-Proto headers, or customize your embedded Tomcat server by specifying the server.tomcat.remote-ip-header and server.tomcat.protocol-header settings. Also, make sure you have server.use-forward-headers=true in application.properties. From docs.spring.io/spring-boot/docs/current/reference/html/… Commented Nov 30, 2015 at 15:30
  • @dspies not sure I understand. I remember seeing these in the documentation but they don't appear to follow the traditional mechanics of specifying a proxy host, port, {username, password}. I have no control over the proxy server so can't configure custom headers. How would I use the above given my proxy is running on http://localhost:3128 Commented Dec 1, 2015 at 3:27

4 Answers 4

12

I've found that I need -Dhttps.proxySet=true in order for the proxy config to actually be used.

Sign up to request clarification or add additional context in comments.

Comments

11

Put the JVM options before -jar. This should work:

java -Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -jar my-application.war

Explanation

According to java command-line documentation, the command's syntax is:

java [ options ] -jar file.jar [ arguments ]

The arguments are the args that'll be received in your main(String[] args). So, it's totally your responsibility to use them somehow. And if you forward them to spring using SpringApplication.run(MyApplication.class, args);, then you need to find documentation that says how spring uses args in the run method.

The options, however, are not sent to your app. One of their uses is to set what java calls system properties using -Dproperty=value. According to Java Networking and Proxies, setting, e.g., http.proxyHost property makes the JVM proxy all your http request through that host.

Comments

2

You may configure all property of REMOTE DEVTOOLS (RemoteDevToolsProperties) in application.properties.

spring.devtools.remote.context-path=  # Context path used to handle the remote connection.
spring.devtools.remote.proxy.host= # The host of the proxy to use to connect to the remote application.
spring.devtools.remote.proxy.port= # The port of the proxy to use to connect to the remote application.
spring.devtools.remote.restart.enabled=true # Whether to enable remote restart.
spring.devtools.remote.secret= # A shared secret required to establish a connection (required to enable remote support).  
spring.devtools.remote.secret-header-name=X-AUTH-TOKEN # HTTP header used to transfer the shared secret.

Comments

0

need to add for authenticating proxy server

-Dhttp.proxyUser=**username**
-Dhttp.proxyPassword=**password**

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.