Maven - how to set socks proxy via settings.xml - java

I wonder how I could set a SOCKS proxy for maven via the ~/.m2/settings.xml? Yes, I know there is a recipe to do this via MAVEN_OPTS environment variable. But I would like to set this in the settings.xml within the <proxies> section. Which kind of protocol should I use? I already tried
socks
socks5
SOCKS_5
SOCKSv5
Regs,
Gerd

This is my setting, and it worked fine for me,hope useful:
<proxy>
<id>ss</id>
<active>true</active>
<protocol>socks5</protocol>
<username></username>
<password></password>
<host>127.0.0.1</host>
<port>1080</port>
<nonProxyHosts>127.0.0.1</nonProxyHosts>
</proxy>

Related

Unable to connect to maven repository when using proxy

My machine is using proxy to connect internet. But I get the following error when running maven build command. And it works when I disable proxy. I don't understand why proxy matters here.
[ERROR] Failed to execute goal on project flink-dist_2.11: Could not resolve dependencies for project org.apache.flink:flink-
dist_2.11:jar:1.7-SNAPSHOT: Failed to collect dependencies at
org.apache.flink:flink-shaded-hadoop2-uber:jar:1.7-SNAPSHOT:
Failed to read artifact descriptor for org.apache.flink:flink-shaded-hadoop2-uber:jar:1.7-SNAPSHOT:
Could not transfer artifact
org.apache.flink:flink-shaded-hadoop2-uber:pom:1.7-SNAPSHOT from/to apache.snapshots (https://repository.
apache.org/snapshots): Remote host closed connection during handshake: SSL peer shut down incorrectly -> [Help 1]
Have you tried the settings.xml at ${user.home}/.m2/settings.xml , more guidance here https://maven.apache.org/guides/mini/guide-proxies.html
in windows7 and above it would be c:\users\user_name\.m2
Maven is trying to connect to a remote repository in order to downlod your project dependencies in its local repository. That's a network connection and obviously, your proxy configuration makes Maven fail in the attempt.
Remote host closed connection during handshake: SSL peer shut down incorrectly :
This indicates that the server host that your are trying to achieve is down, verify first if the connection is well established and try again.
May be try this by configuring Mavan accordingly for using the proxy server:- https://dzone.com/articles/how-get-maven-working-through
I faced to the same problem at my work where we have Windows workstations and NTLM2 proxy server with authentication.
The following solution works fine for me. The benefit of this solution is that it can work with Maven, Git, IntelliJ IDE as well.
Reccomended steps you need to accomplish in order to have access via NTLM2 proxy:
First you need to download, configure and run Cntlm proxy on your pc.
Start Cntlm on your localhost. This proxy will forward all your local unauthenticated HTTP/HTTPS requests to the company proxy as a authenticated requests.
Configure Maven, Git, IntelliJ, Eclipse, etc. to use your local proxy on localhost:3128. You do not need to configure authentication here.
Details:
Download Cntlm proxy from here.
Type cntlm.exe -H -d your_domain -u your_username.
It will ask your password. Enter it and Cntlm will give you the hashes, something like this:
Password:
PassLM 4E9C185932FER43543RWEFER33R4R34C
PassNT 6E9F1254353RDR34RFSDWER3443RDC9A
PassNTLMv2 43534RFWDWE3434RWFWER434C4FA224F
Edit / check your cntlm.ini file
Username <your-domain-username>
Domain <windows-donain-name>
Auth NTLMv2
PassNTLMv2 <hash>
Proxy <proxy-host:port>
NoProxy localhost, 127.0.0.*, 10.*, 192.168.*
Listen 3128
Start Cntlm with a simple script: start-proxy.cmd
cd %CNTLM_HOME%
rem verbose mode
cntlm -v -c cntlm.ini
rem verbose with logfile
rem cntlm -v -c cntlm.ini -T %CNTLM_HOME%\nctlm.log
rem test configuration
rem cntlm -c cntlm.ini -I -M http://google.com
Stop Cntlm server: stop-proxy.cmd
taskkill /IM cntlm.exe /F
Then you can create two cmd files which change Maven configuration as per your flavour:
mvn-internet.cmd
call java8.cmd
del %MAVEN_HOME%\conf\settings.xml
copy %MAVEN_HOME%\conf\settings.xml.internet %MAVEN_HOME%\conf\settings.xml
mvn-intranet.cmd
call java8.cmd
del %MAVEN_HOME%\conf\settings.xml
copy %MAVEN_HOME%\conf\settings.xml.nexus %MAVEN_HOME%\conf\settings.xml
settings.xml.internet
<settings xmlns=...>
<localRepository>...</localRepository>
<proxies>
<proxy>
<id>my-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>localhost</host>
<port>3128</port>
<nonProxyHosts>locahost</nonProxyHosts>
</proxy>
</proxies>
</settings>
settings.xml.nexus
<settings>
<localRepository>...</localRepository>
<mirrors>
<mirror>
<id>local-lalm</id>
<name>local-lalm</name>
<url>https://nexus.xxx...</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>use-local-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>LALM-global</id>
<url>https://nexus.xxx...</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>LALM-global</id>
<url>https://nexus.xxx...</url>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</profile>
</profiles>
</settings>
Do the same with Git
git-internet.cmd
call java8.cmd
rem git config --global http.proxy username:password#localhost:3128
git config --global http.proxy localhost:3128
git-intranet.cmd
call java8.cmd
git config --global --unset http.proxy
Cunfigure IntelliJ
Set up IntelliJ to use proxy on localhost:3128
Set up Maven in IntelliJ: change Maven home directory and User settings file configs.
After that you will use the same Maven configuration within IntelliJ and command line so everythink will work on the same way from IDE and comand line.
You can use your new cmd files to change between use or not proxy server on the fly.
This configuration takes 10 mins. and after that you can forgot this proxy issue.

Connection Error Running Spring Application With Maven

I am trying to run a simple Spring application through Maven.
I have followed the following guide exactly: https://spring.io/guides/gs/serving-web-content/
However, when I run: ./mvnw spring-boot:run -e -X
I get the following error:
[FATAL] Non-resolvable parent POM for org.springframework:gs-serving-web-content:0.1.0: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.2.RELEASE from/to central (https://repo.maven.apache.org/maven2): Connect to 192.168.208.51:3128
In a previous guide I was told to add this as the settings.xml file in the .m2 directory:
<settings>
<proxies>
<proxy>
<id>example-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>192.168.208.51</host>
<port>3128</port>
<nonProxyHosts>*.google.com|*example.com</nonProxyHosts>
</proxy>
</proxies>
</settings>
Which has the host IP address that the error is referring to.
I've pinged the IP address above and no response.
All I want to do is run the application locally as the Spring.io guide suggests is possible.
I don't fully understand the setup as of yet.
Can anyone suggest what I'm doing wrong. (I feel it is something to do with the IP address in the settings.xml file.
The IP you're using is in the private network range.

how to do mod_cluster or mod_jk cluster for jboss eap 6.1

I have two jboss node in same machine with different port and I installed apache server and configured the mod_cluster in apache/conf/httpd.conf as below:
<VirtualHost *:8000>
<Directory>
Order deny,allow
Allow from all
</Directory>
<Location /mod_cluster_manager>
SetHandler mod_cluster-manager
Order deny,allow
Allow from all
</Location>
</VirtualHost>
Could you please help me what else I need to configure in both jboss eap standalone-ha.xml and any other configuration file?
In configuration files specify apache server details:
subsystem xmlns="urn:jboss:domain:modcluster:1.2">
mod-cluster-config proxy-list="10.10.10.10:6666" advertise="false" connector="ajp">
Add the proxy-list attribute in the standalone-ha.xml to include httpd's mod_cluster listen ip set above:

Mapping domains to Tomcat Apps

I have a server with CentOS and zpanel installed. Zpanel installed "Apache Httpd" along many other modules. I have been hosting multiple domains without any issue.
I have two issues:
Remove port 8080 and direct all calls to 80.
Appropriate domain for each tomcat app, as well as my existing sites running independently on Apache Http.
I installed apache tomcat 8 and deployed multiple applications and I can access my applications like
http://example:8080/app1
http://example:8080/app2
http://example:8080/app3
What I want is that my tomcat apps are mapped to my domains, such that
http://example:8080/app1 => http://www.app1.com
http://example:8080/app2 => http://www.app2.com
http://example:8080/app3 => http://www.app3.com
I did tried this tutorial which somewhat does trick but not exactly what I want. i.e. after performing the steps he mentioned when I opened my example.com it redirected to my tomcat app like: example.com/app1. [It did removed 8080 and redirected to correct app] BUT if the app from the end is changed i.e. app1 is changed to someother project that is been hosting by tomcat then that project is opened.
Edit:
My virtual host file is
# DOMAIN: app1.com
<virtualhost *:80>
ServerName app1.com
ServerAlias app1.com www.app1.com
RewriteEngine On
RewriteRule ^/$ app1/ [R=301]
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /app1 http://localhost:8080/app1
ProxyPassReverse /app1 http://localhost:8080/app1
ErrorLog "/var/zpanel/logs/domains/zadmin/app1.com-error.log"
CustomLog "/var/zpanel/logs/domains/zadmin/app1.com-access.log" combined
CustomLog "/var/zpanel/logs/domains/zadmin/app1.com-bandwidth.log" common
</virtualhost>
Update 1
I tried this as well, but of no use. Am I missing something? please guide.
Have you configured properly your http server ?
For example in your apache2.conf or httpd.conf
#LoadModule directives
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
<VirtualHost *:80>
ServerName www.example.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://example.com:8080/app1
ProxyPassReverse / http://example.com:8080/app1
ProxyHTMLURLMap / /app1/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>
After 2 Days of hard search and lots of tests I was finally able to map my domain to tomcat app. Many thanks to these two guides mod_jk installation and vhost/httpd/tomcat

Glassfish Server Webservice behind Apache HTTP Server

Hi
We started to create our applications with J2EE. We now created a Webservice and deployed it to the Glassfish Server. We have written an apache proxy rule to access it via https://our.server.com/webservice-war (only https port is open to that server):
ProxyRequests Off
ProxyPass /webservice-war http://our.server.com:8080/webservice-war
ProxyPassReverse /webservice-war http://our.server.com:8080/webservice-war
Now everything works fine, but when we go to the to the ServiceEndpoint page (which is automatically generated) there is a link to the WSDL page:
http://our.server.com:8080/webservice-war/HostaliasSearchImplService?wsdl
which is obously wrong (Glassfish listens to port 8080). and also https is changed to http
Anyone an idea how I can fix it, that the automatically generated link is:
https://our.server.com/webservice-war/HostaliasSearchImplService?wsdl
BR, Rene
I discovered what I consider to be a very simple and elegant way to deal with the issue: use mod_substitute. Since those of us with this problem are already using Apache, and it's built in and simple, I liked this approach best.
I put a block similar to the below in one of my Apache conf files and found joy:
<Location />
AddOutputFilterByType SUBSTITUTE text/xml
Substitute "s|http://internal:8080/foo|https://external/foo|ni"
</Location>
Found the solution!
Anonym gave me a good hint about mod_jk. So here the complete configuration (for RHEL5).
First of all Download the mod_jk module for apache: http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.31/x86_64/
Put in in the modules directory /etc/httpd/modules and make it executeable:
chmod +x mod_jk-1.2.31-httpd-2.2.x.so
After that create /etc/httpd/conf/workers.properties:
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
The Port 8009 is the where the Glassfish jk connector listens (we come to that later).
No we have to configure mod_jk, therefore create the file: /etc/httpd/conf.d/mod_jk.conf with the following content:
LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.x.so
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk logs
JkLogFile /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Send everything for context /atsi-war to worker named worker1 (ajp13)
JkMount /yourapp-war/* worker1
(This means everything from your http://apache.webserver.com/yourapp-war/ will bi redirected to Glassfish yourapp-war application context)
Important, if you are using virtual hosts on apache, you have to set the option:
JkMountCopy On
for your virtual servers. Explication:
If this directive is set to "On" in
some virtual server, the mounts from
the global server will be copied to
this virtual server, more precisely
all mounts defined by JkMount or
JkUnMount.
Now we have to create the jk connecter in glassfish:
asadmin create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server jk-connector
asadmin set configs.config.server-config.network-config.network-listeners.network-listener.jk-connector.jk-enabled=true
Restart Glassfish, and everything sould work.
As for rewriting the https -> http, I'm not sure that's possible(yet) without using mod_jk, see here
, but see also this little guide
Though, generally, you'll need configure Glassfish and set http.proxyPort (and probably http.proxyHost too). Hopefully that should reflect in the autogenerated WSDL URL.
Here's 3 different ways to do this:
1
Use asadmin (in the Glassfish bin/ directory, run
asadmin create-jvm-options "-Dhttp.proxyPort=80"
asadmin create-jvm-options "-Dhttp.proxyHost=our.server.com"
2
Edit domain.xml and add under the <java-config> element
<jvm-options>-Dhttp.proxyPort=80</jvm-options>
<jvm-options>-Dhttp.proxyHost=our.server.com</jvm-options>
3.
Open the Glassfish admin web page, under Application Server -> VM Settings -> JVM Options and add these options
http.proxyPort=80
http.proxyHost=our.server.com
Setting
server-config.network-config.protocols.protocol.http-listener-1.http.server-name=MyHost:80
on GlassFish Server Open Source Edition 3.1.2.2 (build 5) solved problem to me.

Categories