From: <hr...@rh...> - 2009-03-01 19:05:51
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [3264] RHQ-1690 Provide a host token that stands for the hostname.</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>3264</dd> <dt>Author</dt> <dd>hrupp</dd> <dt>Date</dt> <dd>2009-03-01 13:05:48 -0600 (Sun, 01 Mar 2009)</dd> </dl> <h3>Log Message</h3> <pre>RHQ-1690 Provide a host token that stands for the hostname. This allow the user to add a vhost mapping file that picks up the hostname in a generic way. Of course, the user can always provide more specific mappings. This token could be used in the RHQ server by default.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmoduleshelpersrtfiltersrcmainjavaorgrhqhelpersrtfilterfilterRtFilterjava">rhq/trunk/modules/helpers/rtfilter/src/main/java/org/rhq/helpers/rtfilter/filter/RtFilter.java</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmoduleshelpersrtfiltersrcmainjavaorgrhqhelpersrtfilterfilterRtFilterjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/helpers/rtfilter/src/main/java/org/rhq/helpers/rtfilter/filter/RtFilter.java (3263 => 3264)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/helpers/rtfilter/src/main/java/org/rhq/helpers/rtfilter/filter/RtFilter.java 2009-03-01 04:05:15 UTC (rev 3263) +++ rhq/trunk/modules/helpers/rtfilter/src/main/java/org/rhq/helpers/rtfilter/filter/RtFilter.java 2009-03-01 19:05:48 UTC (rev 3264) </span><span class="lines">@@ -23,6 +23,7 @@ </span><span class="cx"> import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; </span><span class="add">+import java.net.InetAddress; </span><span class="cx"> import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; </span><span class="lines">@@ -85,9 +86,12 @@ </span><span class="cx"> private long lastLogFileSize = 0; private long maxLogFileSize = DEFAULT_MAX_LOG_FILE_SIZE; private String contextName; </span><span class="add">+ private String myHostName; // InetAddr.getHostname() + private String myCHostName; // InetAddr.getCanonicalHostname() </span><span class="cx"> private final Object lock = new Object(); private Properties vhostMappings = new Properties(); </span><span class="add">+ private static final String HOST_TOKEN = "%HOST%"; </span><span class="cx"> /** * Does the real magic. If a fatal exception occurs during processing, the filter will revert to an uninitialized </span><span class="lines">@@ -174,24 +178,47 @@ </span><span class="cx"> * @param serverName Name of the virtual host */ private void openFile(String serverName) { </span><span class="rem">- String vhost; - if ("localhost".equals(serverName) || "127.0.0.1".equals(serverName)) </span><span class="add">+ String vhost = ""; + boolean found = false; + + if ("localhost".equals(serverName) || "127.0.0.1".equals(serverName)) { </span><span class="cx"> vhost = ""; </span><span class="rem">- else { - // try to see if the user provided a mapping for this server name - if (vhostMappings.containsKey(serverName)) { - vhost = vhostMappings.getProperty(serverName); - if (vhost == null || vhost.equals("")) </span><span class="add">+ found = true; + } + + // try to see if the user provided a mapping for this server name + if (!found && vhostMappings.containsKey(serverName)) { + found = true; + vhost = vhostMappings.getProperty(serverName); + if (vhost == null || vhost.equals("")) + vhost = ""; // It is in the mapping, but no value set -> no vhost + else + vhost += "_"; // Otherwise take it and append the separator + if (log.isDebugEnabled()) + log.debug("Vhost determined from mapping >" + vhost + "<"); + } + + // check server name against hostname and hostname.fqdn an see if they match + if (!found && vhostMappings.containsKey(HOST_TOKEN)) { + vhost = vhostMappings.getProperty(HOST_TOKEN); + if (myHostName.startsWith(serverName) || myCHostName.startsWith(serverName)) { + // Match, so take the mapping from the file + if (vhost == null || vhost.equals("")) { </span><span class="cx"> vhost = ""; // It is in the mapping, but no value set -> no vhost </span><span class="rem">- else </span><span class="add">+ } else { </span><span class="cx"> vhost += "_"; // Otherwise take it and append the separator </span><span class="add">+ } + found = true; </span><span class="cx"> if (log.isDebugEnabled()) </span><span class="rem">- log.debug("Vhost determined from mapping >" + vhost + "<"); - } else { - vhost = serverName + "_"; // Not found in mapping? Take it literal + separator </span><span class="add">+ log.debug("Vhost determined from %HOST% token >" + vhost + "<"); </span><span class="cx"> } } </span><span class="add">+ // Nothing found? Fall back to serverName + _ as prefix + if (!found) { + vhost = serverName + "_"; // Not found in mapping? Take it literal + separator + } + </span><span class="cx"> // if this is a sub-context (e.g. news/radio), then replace the / by a _ to // prevent interpretation of the / as a dir separator. String contextFileName = contextName.replace('/', '_'); </span><span class="lines">@@ -220,6 +247,8 @@ </span><span class="cx"> public void init(FilterConfig filterConfig) throws ServletException { try { synchronized (lock) { </span><span class="add">+ myHostName = InetAddress.getLocalHost().getHostName(); + myCHostName = InetAddress.getLocalHost().getCanonicalHostName(); </span><span class="cx"> initializeParameters(filterConfig); ServletContext servletContext = filterConfig.getServletContext(); this.contextName = ServletUtility.getContextRoot(servletContext); </span> </pre> </div> </div> </body> </html> |