Configuring Tomcat to work behind an Internet proxy

We encourage to consider do not configure Internet connection in Servers behing an Internet proxy.

It have some disadvantages like:

  • You will need to use your proxy data each time you will upgrade the application with OpenKM automatic updater tools.
  • It's need to configure JVM parameters with your Internet proxy data for the application be able to connect to Internet.

Is not much clear what are the advantatges for this kind of configuration on Production Servers, what are not the same scenario than end users. Take it as is, only a suggestion.

Linux

Configuration below is based on setting proxy configuration parameters in the JVM environment. There's another option what is configuring proxy at OS level, here are several option one of them is:

Edit your "/etc/bash.bashrc" file as root and put these lines at the end of your "/etc/bash.bashrc" file:

export http_proxy=http://username:password@proxyserver.net:port/
export ftp_proxy=http://username:password@proxyserver.net:port/

  • Stop OpenKM.
  • Edit the $TOMCAT_HOME/bin/setenv.sh file and add the lines:

The http://proxy.url.com value must be your own url host of the proxy.

The "user" value must be the user for getting connection to the proxy. If your proxy does not require authentication you can remove the entire line where are set these parameters.

The "password" values must be the password of the user for getting connection to the proxy. If your proxy does not require authentication you can remove the entire line where are set these parameters.

set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyHost=http://proxy.url.com -Dhttps.proxyHost=http://proxy.url.com
set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyUser=user -Dhttps.proxyUser=user
set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyPassword=password -Dhttps.proxyPassword=password

At the end your setenv.sh should looking something like that :

JAVA_OPTS="$JAVA_OPTS -Xms256m -Xmx2048m -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true"
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -Dmail.mime.ignoreunknownencoding=true"
set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyHost=http://proxy.url.com -Dhttps.proxyHost=http://proxy.url.com
set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyUser=user -Dhttps.proxyUser=user
set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyPassword=password -Dhttps.proxyPassword=password
CATALINA_PID=$CATALINA_HOME/catalina.pid
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib/sigar

If you have issues resolving DNS you can also try with this configuration what is trying to use Google DNS:

set JAVA_OPTS=%JAVA_OPTS% -Dsun.net.spi.nameservice.nameservers=8.8.8.8
set JAVA_OPTS=%JAVA_OPTS% -Dsun.net.spi.nameservice.provider.1=dns,sun

  • Start OpenKM.
  • Go to Administration > ToolsScripting and execute the script below ( should be shown google html code ).
import java.net.URL;
import java.net.HttpURLConnection;
import java.io.BufferedReader;

URL url = new URL("http://www.google.com");
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestMethod("GET");
BufferedReader input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String line;
StringBuilder sb = new StringBuilder();
while ((line = input.readLine()) != null) {
	sb.append(line);
}
input.close();
print(sb.toString().replaceAll("\n","<br/>"));

Windows

Configuration below is based on setting proxy configuration parameters in the JVM environment. There's another option what is configuring proxy at OS level, consider looking for this information at Microsoft technet website.

Step one

Check starting and stopping OpenKM from the command line.

  • First stop OpenKM service.
  • Edit $TOMCAT_HOME/bin/seten.bat file and add the lines:

The http://proxy.url.com value must be your own url host of the proxy.

The "user" value must be the user for getting connection to the proxy. If your proxy does not require authentication you can remove the entire line where are set these parameters.

The "password" values must be the password of the user for getting connection to the proxy. If your proxy does not require authentication you can remove the entire line where are set these parameters.

set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyHost=http://proxy.url.com -Dhttps.proxyHost=http://proxy.url.com
set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyUser=user -Dhttps.proxyUser=user
set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyPassword=password -Dhttps.proxyPassword=password

At the end your setenv.bat should looking something like that:

JAVA_OPTS="$JAVA_OPTS -Xms256m -Xmx2048m -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true"
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -Dmail.mime.ignoreunknownencoding=true"
set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyHost=http://proxy.url.com -Dhttps.proxyHost=http://proxy.url.com
set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyUser=user -Dhttps.proxyUser=user
set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyPassword=password -Dhttps.proxyPassword=password
CATALINA_PID=$CATALINA_HOME/catalina.pid
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib/sigar

If you have issues resolving DNS you can also try with this configuration what is trying to use Google DNS:

set JAVA_OPTS=%JAVA_OPTS% -Dsun.net.spi.nameservice.nameservers=8.8.8.8
set JAVA_OPTS=%JAVA_OPTS% -Dsun.net.spi.nameservice.provider.1=dns,sun

  • Start OpenKM from the command line.

c:\tomcat-8.5.24\bin\> catalina.bat run

  • Go to Administration > ToolsScripting and execute the script below ( should be shown google html code ).
import java.net.URL;
import java.net.HttpURLConnection;
import java.io.BufferedReader;

URL url = new URL("http://www.google.com");
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestMethod("GET");
BufferedReader input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String line;
StringBuilder sb = new StringBuilder();
while ((line = input.readLine()) != null) {
	sb.append(line);
}
input.close();
print(sb.toString().replaceAll("\n","<br/>"));

Step two

If all has gone right in step one, now you can configure parameters into the OpenKM service.

  • Stop OpenKM.
  • Go to $TOMCAT_HOME/bin and execute the next command line:

The command lines below does not registering the parameters for DNS resolving. If you need it, simply add them.

c:\tomcat-8.5.24\bin\> OpenKM //US//OpenKM ++JvmOptions="-Dhttp.proxyHost=http://proxy.url.com"
c:\tomcat-8.5.24\bin\> OpenKM //US//OpenKM ++JvmOptions="-Dhttps.proxyHost=http://proxy.url.com"
c:\tomcat-8.5.24\bin\> OpenKM //US//OpenKM ++JvmOptions="-Dhttp.proxyUser=user"
c:\tomcat-8.5.24\bin\> OpenKM //US//OpenKM ++JvmOptions="-Dhttps.proxyUser=user"
c:\tomcat-8.5.24\bin\> OpenKM //US//OpenKM ++JvmOptions="-Dhttp.proxyPassword=password"
c:\tomcat-8.5.24\bin\> OpenKM //US//OpenKM ++JvmOptions="-Dhttps.proxyPassword=password

  • Start OpenKM from services.
  • Go to Administration > ToolsScripting and execute the script below ( should be shown google html code ).
import java.net.URL;
import java.net.HttpURLConnection;
import java.io.BufferedReader;

URL url = new URL("http://www.google.com");
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestMethod("GET");
BufferedReader input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String line;
StringBuilder sb = new StringBuilder();
while ((line = input.readLine()) != null) {
	sb.append(line);
}
input.close();
print(sb.toString().replaceAll("\n","<br/>"));