Configure Http Proxy for Wildfly 8.1.0

2.2k Views Asked by At

How to configure a HTTP-Proxy for Wildfly 8.1? The Wildfly Instance is running as standalone on RHEL 6.5. The machine has no direct access to the internet but one of the deployed applications should use an existing HTTP Proxy (without Authentication) to call Google Cloud Messaging restful service. So somehow I have to tell Wildfly or the application on it to tell where is the Proxy. I'm starting/stopping the instance via the default init.d scripts with service wildfly start/stop/restart.

I already got the proxy working for a Tomcat Instance by using JAVA_OPTS, so I tried the same for the wildfly:

Setting the proxy via JAVA_OPTS in standalone.sh

# Display our environment  
echo "========================================================================="  
echo ""  
echo "  JBoss Bootstrap Environment"  
echo ""  
echo "  JBOSS_HOME: $JBOSS_HOME"  
echo ""  
echo "  JAVA: $JAVA"  
echo ""  
echo "  JAVA_OPTS: $JAVA_OPTS"  
echo ""  
echo "========================================================================="  
echo ""  

JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=myproxy -Dhttp.proxyPort=3128 -Dhttps.proxyHost=myproxy -Dhttps.proxyPort=3128"  

while true; do  
   if [ "x$LAUNCH_JBOSS_IN_BACKGROUND" = "x" ]; then  
      # Execute the JVM in the foreground  
      eval \"$JAVA\" -D\"[Standalone]\" $JAVA_OPTS  \  
         \"-Dorg.jboss.boot.log.file=$JBOSS_LOG_DIR/server.log\" \  
         \"-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties\" \  
         -jar \"$JBOSS_HOME/jboss-modules.jar\" \  
         -mp \"${JBOSS_MODULEPATH}\" \  
         org.jboss.as.standalone \  
         -Djboss.home.dir=\"$JBOSS_HOME\" \  
         -Djboss.server.base.dir=\"$JBOSS_BASE_DIR\" \  
         "$SERVER_OPTS"  
      JBOSS_STATUS=$?  
   else  
      # Execute the JVM in the background  
      eval \"$JAVA\" -D\"[Standalone]\" $JAVA_OPTS \  
         \"-Dorg.jboss.boot.log.file=$JBOSS_LOG_DIR/server.log\" \  
         \"-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties\" \  
         -jar \"$JBOSS_HOME/jboss-modules.jar\" \  
         -mp \"${JBOSS_MODULEPATH}\" \  
         org.jboss.as.standalone \  
         -Djboss.home.dir=\"$JBOSS_HOME\" \  
         -Djboss.server.base.dir=\"$JBOSS_BASE_DIR\" \  
         "$SERVER_OPTS" "&"  
      JBOSS_PID=$!

The server boots without errors and running ps aux gives me the wildfly instance having the JAVA_OPTS set correctly. ps aux output

The proxy is configured correctly and works, e.g. with curl: curl example

However, in the Application which is deployed on the wildfly and tries to call the GCM Webservice, I still get the ConnectionException:

java.net.ConnectException: Connection timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method) [rt.jar:1.7.0_65]
2

There are 2 best solutions below

0
On BEST ANSWER

Issue could be solved by not setting the Proxy globally for the Application Server, but in the Sourcecode which does the REST Requests against GCM:

//this is your request-body, as byte-array
byte[] body; 
URL url = new URL("https://android.googleapis.com/gcm/send");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy-host.com", 3128));
URLConnection con = url.openConnection(proxy);
HttpURLConnection con1 = (HttpURLConnection) con;

con1.setRequestMethod("POST");
con1.setRequestProperty("Content-type", "application/json");
con1.setDoOutput(true);
con1.setUseCaches(false);
con1.setFixedLengthStreamingMode(body.length);

OutputStream out = con1.getOutputStream();
try {
   out.write(body);
} finally {
   out.close();
}
0
On

Do you have a retry mechanism? If not you can go through the documentation about Error explanations. You can try the time out steps. See if that works. It could be an issue with using a proxy without authentication.