java
Java-Monitor Forum > Forum > Tomcat Administration » Using system properties in Tomcat's server.xml
Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-05-2010, 21:34
kjkoster kjkoster is offline
Forum Operator
 
Join Date: Jul 2008
Posts: 1,136
Default Using system properties in Tomcat's server.xml

Dear All,

Recently I discovered that Tomcat has support for using system properties in server.xml. This feature made deployment easier for me, since now I can use the exact same server.xml file on my test machines as on the production box.

Let me give one example of how this feature helped move to a single server.xml for all environment. I am sure that you can find many more. I use a mod_proxy_http connector to delegate the work from Apache to Tomcat. Here is what it used to look like:
Code:
    <!-- Define an HTTP Apache mod_proxy_http connector -->
    <Connector port="8081" proxyPort="80" proxyName="java-monitor.com" enableLookups="false" maxThreads="256" />
In the server.xml for my test machine I had the exact same definition, except that the proxyName was different. Just for this one little difference I had to maintain a separate server.xml for test and for production.

By using a system property instead I can now specify the domain to use for the proxyName from the command line. Server.xml now looks like this:
Code:
    <!-- Define an HTTP Apache mod_proxy_http connector -->
    <Connector port="8081" proxyPort="80" proxyName="${javamonitor.domain}" enableLookups="false" maxThreads="256" />
I was already using the system property javamonitor.domain for internal configuration of the Java-monitor monitoring system. So this properly has been set to the domain name for a long time already.

I can imagine many other uses for this, such as setting port numbers or specifying log folders for the access log valve. All things that typically change between test and production.

This feature is documented on the Tomcat configuration reference page, as the second paragraph. No wonder I never read it.

It states:
Quote:
The Tomcat configuration files support Apache Ant style variable substitution. A system property with the name propname may be used in a configuration file using the syntax ${propname}. All system properties are available including those set using the -D syntax, those automatically made available by the JVM and those configured in the $CATALINA_BASE/conf/catalina.properties file.
Kees Jan
Reply With Quote
  #2  
Old 14-12-2012, 03:02
adavidson adavidson is offline
Junior Member
 
Join Date: Nov 2012
Posts: 2
Default Probe stops reporting data randomly

Hi Kees Jan,

I have a related issue to your above post. I'm running 3 production tomcat 5.5 instances (each on its own machine) and 2 have been running for a few weeks without issue. However one of them randomly reports to be down but really it isn't. On investigating the logs I found the following error:

Code:
Dec 14, 2012 10:48:39 AM com.javamonitor.JavaMonitorCollector$CollectorDriver run
SEVERE: This probe was hit by an unexpected exception: For input string: "YOUR HTTP PROXY PORT"
java.lang.NumberFormatException: For input string: "YOUR HTTP PROXY PORT"
	at java.lang.NumberFormatException.forInputString(Unknown Source)
	at java.lang.Integer.parseInt(Unknown Source)
	at java.lang.Integer.parseInt(Unknown Source)
	at com.javamonitor.Collector.getLocalIp(Collector.java:164)
	at com.javamonitor.Collector.push(Collector.java:125)
	at com.javamonitor.JavaMonitorCollector$CollectorDriver.run(JavaMonitorCollector.java:153)
	at java.lang.Thread.run(Unknown Source)
I'm not behind a proxy and I'm not setting any proxy configuration in the server.xml or on java startup.

If I restart tomcat the server comes up in the monitoring, the probe reports data for approx 7/8hrs and then I get this error and all reporting stops for this server. The probe looks like it's still running ok but even if I restart the webapp it still doesn't start re-sending data - only with a full restart of tomcat does the probe work again but then only for a limited time.

I looked at the code and can see the error is due to the parseInt of the string "YOUR HTTP PROXY PORT" but I can't find where this would be set anywhere:

Code:
s = new Socket(getProperty("http.proxyHost"), parseInt(getProperty("http.proxyPort", "80")));
Sounds like a config default string which needs to be overridden with a real port number but I can't find it anywhere and I'm not behind a proxy?

Any help in resolving this issue would be much appreciated. Many thanks in advance.

Andrew.
Reply With Quote
  #3  
Old 14-12-2012, 08:44
kjkoster kjkoster is offline
Forum Operator
 
Join Date: Jul 2008
Posts: 1,136
Default

Dear Andrew,

Interesting. So this Tomcat runs for almost a day before it happens? Is this your own code or not? Do you use custom libraries that you have no source code for?

The proxy configuration is taken from a system property. Since it is checked every time Java-monitor is deployed, the error should come up immediately when Tomcat starts. What that tells me is that your Tomcat configuration is very probably fine. Otherwise your Tomcat would never show up in Java-monitor.

This leaves programmatic setting of system properties as a route for this text to get into your JVM. You can scour your code for setting system properties or you can set a security manager to flat-out deny setting system properties. That is a good idea for shared environments anyway. Are you using a Java security manager?

Kees Jan
Reply With Quote
  #4  
Old 18-12-2012, 04:43
adavidson adavidson is offline
Junior Member
 
Join Date: Nov 2012
Posts: 2
Default

Hi Kees Jan,

Fantastic ! I found this in some client code:

Code:
    System.setProperty("http.proxyHost", "YOUR HTTP PROXY SERVER");
    System.setProperty("https.proxyHost", "YOUR HTTPS PROXY SERVER");
    System.setProperty("http.proxyPort", "YOUR HTTP PROXY PORT");
    System.setProperty("https.proxyPort", "YOUR HTTPS PROXY PORT");
    System.setProperty("http.nonProxyHosts", "LOCAL|ADDRESSES|TO|IGNORE|FOR|HTTP|REQUESTS");
    System.setProperty("https.nonProxyHosts", "LOCAL|ADDRESSES|TO|IGNORE|FOR|HTTPS|REQUESTS");
Of course only when this code is accessed, the problem occurs which explains why it randomly goes down. Looks like some template code has been left in place over-riding the proxy setting and causing the issue. Once removed I think this will resolve the issue. Many thanks.

Andrew.
Reply With Quote
  #5  
Old 18-12-2012, 09:11
kjkoster kjkoster is offline
Forum Operator
 
Join Date: Jul 2008
Posts: 1,136
Default

Dear Andrew,

Glad you found this. Good news. Makes me wonder what else is in that code.

To avoid this in the future, the security manager can help.

Kees Jan
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump