Specifying an http proxy with spring-boot - spring-boot

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

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

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.

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.

need to add for authenticating proxy server
-Dhttp.proxyUser=**username**
-Dhttp.proxyPassword=**password**

Related

Changing Default Ports in Moqui

Moqui Framework Version : 2.1.3
The Framework runs on the default port 8080 just fine, i would like to change the default ports and i did read https://www.moqui.org/m/docs/framework/Run+and+Deploy#a2.RuntimeDirectoryandMoquiConfigurationXMLFile
which states > "Each of these can be system environment variables (with underscores) or Java properties (with underscores or dots) using the -D command-line argument.
i did find the webapp_ variables are referenced in MoquiDefaultConf.xml as mentioned in the above material and tried using the below start command >
$sudo nohup java -Dwebapp_http_host=localhost -Dwebapp_http_port=9080 -Dwebapp_https_port=9443 -jar moqui.war conf=conf/MoquiDevConf.xml &
However the above command does not seem to change the port, Moqui is still running on default port 8080, What could i be missing?
I also tried the solution to update the webapp tag in MoquiDevConf.xml as mentioned in Running Moqui on Tomcat over SSL (setting http-port and htts-port) - return code 302 with no joy,
Appreciate any pointers, i'm really stuck
The environment variables or Java properties you mention are for setting the ports to use when building URLs. These are the external ports used for accessing your server and if a load balancer or reverse proxy is used may be different from the ports the servlet container is running on. For more information see:
https://moqui.org/m/docs/framework/Run+and+Deploy#EnvironmentVariables
If you are running Moqui with the embedded Jetty server you can specify the port it listens on using the port argument as described in the Executable WAR File section of the Run and Deploy document:
https://moqui.org/m/docs/framework/Run+and+Deploy#a3.ExecutableWARFile
Note that the embedded Jetty server can be used in production but it does not support https and is meant to be used behind a reverse proxy like nginx or Apache httpd that forwards requests to the embedded Jetty server.
If you deploy the WAR file by dropping it in a Servlet Container (ie as an actual WAR file, not treating it as an executable JAR file) then the port configuration would be done with the Servlet Container (Tomcat, Jetty, etc).

Using spring cli behind proxy results in "Connection refused" error

I am struggling to get spring cli running behind our corporate proxy. I read some suggestions in spring blogs on how to set the proxy and tried to follow, but w/o any success so far.
I tried the following
set http.proxyHost, http.proxyPort, http.proxyUser, http.proxyPassword as windows env variable
set corresponding variables for https as well
set JAVA_OPTS env. variable with -D...
verified that JAVA_OPTS variables are correctly picked up by setting debug on
Based on the above settings, the startup script is actually using the below command to run the spring cli
"C:\Program Files\Java\jdk1.8.0_66/bin/java.exe" -Dhttp.proxyHost=http://webproxy.company.com -Dhttp.proxyPort=8080 -Dhttps.proxyHost=https://webproxy.company.com -Dhttps.proxyPort=8080 -Dhttps.proxyUser=zencv -Dhttp.proxyPassword=dadada -cp "C:\My programs\spring-1.3.5.RELEASE\bin\\..\lib\*" org.springframework.boot.loader.JarLauncher init
I am always getting the same error
Using service at https://start.spring.io
Failed to retrieve metadata from service at 'https://start.spring.io' (Connect to start.spring.io:443 [start.spring.io/141.101.112.192, start.spring.io/190.93.243.191] failed: Connection refused: conn
ect)
In-order to verify that I can reach the site from a command line using the above proxy, I used curl with proxy and was successful. Please help!

How to use socks with gradle for dependency resolving, in command line?

When jcenter is not accessible without proxy server, to resolve dependencies, and i want to use socks instead of http proxy, how i can use it in commanad line?
I know how to use http proxy:
-Dhttp.proxyHost=yourProxy -Dhttp.proxyPort=yourPort
-Dhttp.proxyUser=usernameProxy -Dhttp.proxyPassword=yourPassoword
I found answer, here you can use:
./gradlew -DsocksProxyHost=yourHost
-DsocksProxyPort=yourHostPort your-command
using above you can set socks host and port.
Gradle only documents about how to use HTTP(s) proxy, however in the ant source code it mentions, there is enough information about how to setup the SOCKS proxy.
Add the following two lines to the gradle.properties configuration file and you are done.
systemProp.socksProxyHost=your socks proxy ip
systemProp.socksProxyPort=your socks proxy port
The format of SOCKS configuration names (socksProxyHost and socksProxyPort) differs from HTTP proxy host and port configurations (http.proxyHost and http.proxyPort).
Refering to https://discuss.gradle.org/t/how-can-i-set-gradle-proxy-to-socks/15508
In the Project window change from Android to Project scope.
Then open up gradle.properties and add this line:
org.gradle.jvmargs=-DsocksProxyHost=yourHostIP -DsocksProxyPort=yourHostPort
Sync project.
i might be a little late but i found out that in ubuntu/Linux the proxy settings are cached in ~/.gradle/gradle.properties and I also found out that this gradle.properties is different from the one in your app inside android studio.
so you need to edit the credentials in there.
do a vim ~/.gradle/gradle.properties and edit the credentials there.
in my case i was using a socks proxy so i commented out all the http and https proxy hosts and ports and added one for socks. it looked like this
`systemProp.socks5ProxyHost=127.0.0.1
systemProp.socks5ProxyPort=1080`
i was able to sync gradle afterwards.

Making spring boot boostrap behind proxy

I tried to use Spring Boot using proxy.
I get the following message
$ spring init -l
Failed to retrieve help from service at 'https://start.spring.io'
(start.spring.io: unknown error)
I tried following
export http_proxy
export https_proxy
JAVA_OPTS settings
We are using commons HttpClient and we build a default instance via HttpClientBuilder
There are a bunch of system properties that are taken into account but I assume the following is the ones you're looking for:
http.proxyHost
http.proxyPort
Can you try that? If that does not work, please raise an issue on the boot tracker
Behind corporate proxy using locally installed cntlm proxy:
JAVA_OPTS
-Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128
Output:
$ spring init
Using service at https://start.spring.io
Content saved to 'demo.zip'
Use
-Dhttp.proxyHost=your.proxy.net -Dhttp.proxyPort=8080

Unable to deploy from Jenkins to Jboss

We are unable to deploy our application from our BuildServer to our appliation server.
This is the maven command we use in Jenkins:
clean install jboss-as:deploy -Pjboss7 -Dmaven.test.skip=true
We have tried the following:
Confirmed we can telnet from our BuildServer to our appliation server
Upgrade Jboss maven plugin
Started Jboss (on our application server) with
$JBOSS_HOME/bin/standalone.sh -b 0.0.0.0
Jenkins seems to hang at the following point:
INFO: JBoss Remoting version 3.2.12.GA
Authenticating against security realm: ManagementRealm
Is the JBoss AS 7 working on the same machine as Jenkins?
Currently your binding your public interface to all network interfaces on the host machine (the -b command). You should also bind your management interface of the app server to a proper network interface (Jboss allows remote deployment only by the management interface). You can do it in the $JBOSS_HOME/standalone/configuration/standalone.xml (or domain.xml for domain mode) file. Find:
and set the inet-address to the ip of the machine which hosts the application server. You can also use the -bmanagement switch to bind the management interface, as such:
$JBOSS_HOME/bin/standalone.sh -bmanagement=192.168.100.10
You also stated, that you have a potential problem with authentication. Please post your maven plugin configuration. Note that the username and password you provide for the maven plugin should match the administrator user on JBoss (you can add him by choosing Management User in the $JBOSS_HOME/bin/add-user.sh promp). This is the most likely source of your problem - but it is hard to tell without any further information (for example something from the pom.xml file).
Also if the app server is working on the same machine as Jenkins, JBoss allows the "local user authentication" which basicaly checks if the call has originated from the same machine.
Additional source for network interface binding: https://docs.jboss.org/author/display/AS71/Command+line+parameters#Commandlineparameters-bindaddress

Resources