Coverage Report - org.apache.tomcat.maven.runner.Tomcat7Runner
 
Classes in this File Line Coverage Branch Coverage Complexity
Tomcat7Runner
0 %
0/244
0 %
0/100
4,75
Tomcat7Runner$1
0 %
0/12
0 %
0/2
4,75
 
 1  
 package org.apache.tomcat.maven.runner;
 2  
 /*
 3  
  * Licensed to the Apache Software Foundation (ASF) under one
 4  
  * or more contributor license agreements.  See the NOTICE file
 5  
  * distributed with this work for additional information
 6  
  * regarding copyright ownership.  The ASF licenses this file
 7  
  * to you under the Apache License, Version 2.0 (the
 8  
  * "License"); you may not use this file except in compliance
 9  
  * with the License.  You may obtain a copy of the License at
 10  
  *
 11  
  *   http://www.apache.org/licenses/LICENSE-2.0
 12  
  *
 13  
  * Unless required by applicable law or agreed to in writing,
 14  
  * software distributed under the License is distributed on an
 15  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 16  
  * KIND, either express or implied.  See the License for the
 17  
  * specific language governing permissions and limitations
 18  
  * under the License.
 19  
  */
 20  
 
 21  
 import org.apache.catalina.Context;
 22  
 import org.apache.catalina.Host;
 23  
 import org.apache.catalina.connector.Connector;
 24  
 import org.apache.catalina.core.StandardContext;
 25  
 import org.apache.catalina.startup.Catalina;
 26  
 import org.apache.catalina.startup.ContextConfig;
 27  
 import org.apache.catalina.startup.Tomcat;
 28  
 import org.apache.catalina.valves.AccessLogValve;
 29  
 import org.apache.tomcat.util.http.fileupload.FileUtils;
 30  
 import org.apache.tomcat.util.http.fileupload.IOUtils;
 31  
 
 32  
 import java.io.BufferedOutputStream;
 33  
 import java.io.File;
 34  
 import java.io.FileInputStream;
 35  
 import java.io.FileNotFoundException;
 36  
 import java.io.FileOutputStream;
 37  
 import java.io.IOException;
 38  
 import java.io.InputStream;
 39  
 import java.lang.reflect.InvocationTargetException;
 40  
 import java.lang.reflect.Method;
 41  
 import java.net.URL;
 42  
 import java.util.HashMap;
 43  
 import java.util.Map;
 44  
 import java.util.Properties;
 45  
 import java.util.StringTokenizer;
 46  
 
 47  
 /**
 48  
  * FIXME add junit for that but when https://issues.apache.org/bugzilla/show_bug.cgi?id=52028 fixed
 49  
  * Main class used to run the standalone wars in a Apache Tomcat instance.
 50  
  *
 51  
  * @author Olivier Lamy
 52  
  * @since 2.0
 53  
  */
 54  
 public class Tomcat7Runner
 55  
 {
 56  
     // true/false to use the server.xml located in the jar /conf/server.xml
 57  
     public static final String USE_SERVER_XML_KEY = "useServerXml";
 58  
 
 59  
     // contains war name wars=foo.war,bar.war
 60  
     public static final String WARS_KEY = "wars";
 61  
 
 62  
     public static final String ARCHIVE_GENERATION_TIMESTAMP_KEY = "generationTimestamp";
 63  
 
 64  
     public static final String ENABLE_NAMING_KEY = "enableNaming";
 65  
 
 66  
     public static final String ACCESS_LOG_VALVE_FORMAT_KEY = "accessLogValveFormat";
 67  
 
 68  
     /**
 69  
      * key of the property which contains http protocol : HTTP/1.1 or org.apache.coyote.http11.Http11NioProtocol
 70  
      */
 71  
     public static final String HTTP_PROTOCOL_KEY = "connectorhttpProtocol";
 72  
 
 73  
 
 74  
     public int httpPort;
 75  
 
 76  
     public int httpsPort;
 77  
 
 78  
     public int ajpPort;
 79  
 
 80  
     public String serverXmlPath;
 81  
 
 82  
     public Properties runtimeProperties;
 83  
 
 84  
     public boolean resetExtract;
 85  
 
 86  0
     public boolean debug = false;
 87  
 
 88  0
     public boolean clientAuth = false;
 89  
 
 90  0
     public String keyAlias = null;
 91  
 
 92  
     public String httpProtocol;
 93  
 
 94  0
     public String extractDirectory = ".extract";
 95  
 
 96  
     public File extractDirectoryFile;
 97  
 
 98  
     public String loggerName;
 99  
 
 100  
     Catalina container;
 101  
 
 102  
     Tomcat tomcat;
 103  
 
 104  0
     String uriEncoding = "ISO-8859-1";
 105  
 
 106  
     /**
 107  
      * key = context of the webapp, value = war path on file system
 108  
      */
 109  0
     Map<String, String> webappWarPerContext = new HashMap<String, String>();
 110  
 
 111  
     public Tomcat7Runner()
 112  0
     {
 113  
         // no op
 114  0
     }
 115  
 
 116  
     public void run()
 117  
         throws Exception
 118  
     {
 119  
 
 120  0
         PasswordUtil.deobfuscateSystemProps();
 121  
 
 122  0
         if ( loggerName != null && loggerName.length() > 0 )
 123  
         {
 124  0
             installLogger( loggerName );
 125  
         }
 126  
 
 127  0
         this.extractDirectoryFile = new File( this.extractDirectory );
 128  
 
 129  0
         debugMessage( "use extractDirectory:" + extractDirectoryFile.getPath() );
 130  
 
 131  0
         boolean archiveTimestampChanged = false;
 132  
 
 133  
         // compare timestamp stored during previous run if exists
 134  0
         File timestampFile = new File( extractDirectoryFile, ".tomcat_executable_archive.timestamp" );
 135  
 
 136  0
         Properties timestampProps = loadProperties( timestampFile );
 137  
 
 138  0
         if ( timestampFile.exists() )
 139  
         {
 140  0
             String timestampValue = timestampProps.getProperty( Tomcat7Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY );
 141  0
             if ( timestampValue != null )
 142  
             {
 143  0
                 long timestamp = Long.parseLong( timestampValue );
 144  0
                 archiveTimestampChanged =
 145  
                     Long.parseLong( runtimeProperties.getProperty( Tomcat7Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY ) )
 146  
                         > timestamp;
 147  
 
 148  0
                 debugMessage( "read timestamp from file " + timestampValue + ", archiveTimestampChanged: "
 149  
                                   + archiveTimestampChanged );
 150  
             }
 151  
 
 152  
         }
 153  
 
 154  
         // do we have to extract content
 155  
         {
 156  0
             if ( !extractDirectoryFile.exists() || resetExtract || archiveTimestampChanged )
 157  
             {
 158  0
                 extract();
 159  
                 //if archiveTimestampChanged or timestamp file not exists store the last timestamp from the archive
 160  0
                 if ( archiveTimestampChanged || !timestampFile.exists() )
 161  
                 {
 162  0
                     timestampProps.put( Tomcat7Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY, runtimeProperties.getProperty(
 163  
                         Tomcat7Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY ) );
 164  0
                     saveProperties( timestampProps, timestampFile );
 165  
                 }
 166  
             }
 167  
             else
 168  
             {
 169  0
                 String wars = runtimeProperties.getProperty( WARS_KEY );
 170  0
                 populateWebAppWarPerContext( wars );
 171  
             }
 172  
         }
 173  
 
 174  
         // create tomcat various paths
 175  0
         new File( extractDirectory, "conf" ).mkdirs();
 176  0
         new File( extractDirectory, "logs" ).mkdirs();
 177  0
         new File( extractDirectory, "webapps" ).mkdirs();
 178  0
         new File( extractDirectory, "work" ).mkdirs();
 179  0
         File tmpDir = new File( extractDirectory, "temp" );
 180  0
         tmpDir.mkdirs();
 181  
 
 182  0
         System.setProperty( "java.io.tmpdir", tmpDir.getAbsolutePath() );
 183  
 
 184  0
         System.setProperty( "catalina.base", extractDirectoryFile.getAbsolutePath() );
 185  0
         System.setProperty( "catalina.home", extractDirectoryFile.getAbsolutePath() );
 186  
 
 187  
         // start with a server.xml
 188  0
         if ( serverXmlPath != null || useServerXml() )
 189  
         {
 190  0
             container = new Catalina();
 191  0
             container.setUseNaming( this.enableNaming() );
 192  0
             if ( serverXmlPath != null && new File( serverXmlPath ).exists() )
 193  
             {
 194  0
                 container.setConfig( serverXmlPath );
 195  
             }
 196  
             else
 197  
             {
 198  0
                 container.setConfig( new File( extractDirectory, "conf/server.xml" ).getAbsolutePath() );
 199  
             }
 200  0
             container.start();
 201  
         }
 202  
         else
 203  
         {
 204  0
             tomcat = new Tomcat()
 205  0
             {
 206  
                 public Context addWebapp( Host host, String url, String name, String path )
 207  
                 {
 208  
 
 209  0
                     Context ctx = new StandardContext();
 210  0
                     ctx.setName( name );
 211  0
                     ctx.setPath( url );
 212  0
                     ctx.setDocBase( path );
 213  
 
 214  0
                     ContextConfig ctxCfg = new ContextConfig();
 215  0
                     ctx.addLifecycleListener( ctxCfg );
 216  
 
 217  0
                     ctxCfg.setDefaultWebXml( new File( extractDirectory, "conf/web.xml" ).getAbsolutePath() );
 218  
 
 219  0
                     if ( host == null )
 220  
                     {
 221  0
                         getHost().addChild( ctx );
 222  
                     }
 223  
                     else
 224  
                     {
 225  0
                         host.addChild( ctx );
 226  
                     }
 227  
 
 228  0
                     return ctx;
 229  
                 }
 230  
             };
 231  
 
 232  0
             if ( this.enableNaming() )
 233  
             {
 234  0
                 System.setProperty( "catalina.useNaming", "true" );
 235  0
                 tomcat.enableNaming();
 236  
             }
 237  
 
 238  0
             tomcat.getHost().setAppBase( new File( extractDirectory, "webapps" ).getAbsolutePath() );
 239  
 
 240  0
             String connectorHttpProtocol = runtimeProperties.getProperty( HTTP_PROTOCOL_KEY );
 241  
 
 242  0
             if ( httpProtocol != null && httpProtocol.trim().length() > 0 )
 243  
             {
 244  0
                 connectorHttpProtocol = httpProtocol;
 245  
             }
 246  
 
 247  0
             debugMessage( "use connectorHttpProtocol:" + connectorHttpProtocol );
 248  
 
 249  0
             if ( httpPort > 0 )
 250  
             {
 251  0
                 Connector connector = new Connector( connectorHttpProtocol );
 252  0
                 connector.setPort( httpPort );
 253  
 
 254  0
                 if ( httpsPort > 0 )
 255  
                 {
 256  0
                     connector.setRedirectPort( httpsPort );
 257  
                 }
 258  0
                 connector.setURIEncoding( uriEncoding );
 259  
 
 260  0
                 tomcat.getService().addConnector( connector );
 261  
 
 262  0
                 tomcat.setConnector( connector );
 263  
             }
 264  
 
 265  
             // add a default acces log valve
 266  0
             AccessLogValve alv = new AccessLogValve();
 267  0
             alv.setDirectory( new File( extractDirectory, "logs" ).getAbsolutePath() );
 268  0
             alv.setPattern( runtimeProperties.getProperty( Tomcat7Runner.ACCESS_LOG_VALVE_FORMAT_KEY ) );
 269  0
             tomcat.getHost().getPipeline().addValve( alv );
 270  
 
 271  
             // create https connector
 272  0
             if ( httpsPort > 0 )
 273  
             {
 274  0
                 Connector httpsConnector = new Connector( connectorHttpProtocol );
 275  0
                 httpsConnector.setPort( httpsPort );
 276  0
                 httpsConnector.setSecure( true );
 277  0
                 httpsConnector.setProperty( "SSLEnabled", "true" );
 278  0
                 httpsConnector.setProperty( "sslProtocol", "TLS" );
 279  0
                 httpsConnector.setURIEncoding( uriEncoding );
 280  
 
 281  0
                 String keystoreFile = System.getProperty( "javax.net.ssl.keyStore" );
 282  0
                 String keystorePass = System.getProperty( "javax.net.ssl.keyStorePassword" );
 283  0
                 String keystoreType = System.getProperty( "javax.net.ssl.keyStoreType", "jks" );
 284  
 
 285  0
                 if ( keystoreFile != null )
 286  
                 {
 287  0
                     httpsConnector.setAttribute( "keystoreFile", keystoreFile );
 288  
                 }
 289  0
                 if ( keystorePass != null )
 290  
                 {
 291  0
                     httpsConnector.setAttribute( "keystorePass", keystorePass );
 292  
                 }
 293  0
                 httpsConnector.setAttribute( "keystoreType", keystoreType );
 294  
 
 295  0
                 String truststoreFile = System.getProperty( "javax.net.ssl.trustStore" );
 296  0
                 String truststorePass = System.getProperty( "javax.net.ssl.trustStorePassword" );
 297  0
                 String truststoreType = System.getProperty( "javax.net.ssl.trustStoreType", "jks" );
 298  0
                 if ( truststoreFile != null )
 299  
                 {
 300  0
                     httpsConnector.setAttribute( "truststoreFile", truststoreFile );
 301  
                 }
 302  0
                 if ( truststorePass != null )
 303  
                 {
 304  0
                     httpsConnector.setAttribute( "truststorePass", truststorePass );
 305  
                 }
 306  0
                 httpsConnector.setAttribute( "truststoreType", truststoreType );
 307  
 
 308  0
                 httpsConnector.setAttribute( "clientAuth", clientAuth );
 309  0
                 httpsConnector.setAttribute( "keyAlias", keyAlias );
 310  
 
 311  0
                 tomcat.getService().addConnector( httpsConnector );
 312  
 
 313  0
                 if ( httpPort <= 0 )
 314  
                 {
 315  0
                     tomcat.setConnector( httpsConnector );
 316  
                 }
 317  
             }
 318  
 
 319  
             // create ajp connector
 320  0
             if ( ajpPort > 0 )
 321  
             {
 322  0
                 Connector ajpConnector = new Connector( "org.apache.coyote.ajp.AjpProtocol" );
 323  0
                 ajpConnector.setPort( ajpPort );
 324  0
                 ajpConnector.setURIEncoding( uriEncoding );
 325  0
                 tomcat.getService().addConnector( ajpConnector );
 326  
             }
 327  
 
 328  
             // add webapps
 329  0
             for ( Map.Entry<String, String> entry : this.webappWarPerContext.entrySet() )
 330  
             {
 331  0
                 String baseDir = null;
 332  0
                 Context context = null;
 333  0
                 if ( entry.getKey().equals( "/" ) )
 334  
                 {
 335  0
                     baseDir = new File( extractDirectory, "webapps/ROOT.war" ).getAbsolutePath();
 336  0
                     context = tomcat.addWebapp( "", baseDir );
 337  
                 }
 338  
                 else
 339  
                 {
 340  0
                     baseDir = new File( extractDirectory, "webapps/" + entry.getValue() ).getAbsolutePath();
 341  0
                     context = tomcat.addWebapp( entry.getKey(), baseDir );
 342  
                 }
 343  
 
 344  0
                 URL contextFileUrl = getContextXml( baseDir );
 345  0
                 if ( contextFileUrl != null )
 346  
                 {
 347  0
                     context.setConfigFile( contextFileUrl );
 348  
                 }
 349  0
             }
 350  
 
 351  0
             tomcat.start();
 352  
         }
 353  
 
 354  0
         waitIndefinitely();
 355  
 
 356  0
     }
 357  
 
 358  
     private URL getContextXml( String warPath )
 359  
         throws IOException
 360  
     {
 361  0
         InputStream inputStream = null;
 362  
         try
 363  
         {
 364  0
             String urlStr = "jar:file:" + warPath + "!/META-INF/context.xml";
 365  0
             debugMessage( "search context.xml in url:'" + urlStr + "'" );
 366  0
             URL url = new URL( urlStr );
 367  0
             inputStream = url.openConnection().getInputStream();
 368  0
             if ( inputStream != null )
 369  
             {
 370  0
                 return url;
 371  
             }
 372  
         }
 373  0
         catch ( FileNotFoundException e )
 374  
         {
 375  0
             return null;
 376  
         }
 377  
         finally
 378  
         {
 379  0
             IOUtils.closeQuietly( inputStream );
 380  0
         }
 381  0
         return null;
 382  
     }
 383  
 
 384  
     private void waitIndefinitely()
 385  
     {
 386  0
         Object lock = new Object();
 387  
 
 388  0
         synchronized ( lock )
 389  
         {
 390  
             try
 391  
             {
 392  0
                 lock.wait();
 393  
             }
 394  0
             catch ( InterruptedException exception )
 395  
             {
 396  0
                 throw new Error( "InterruptedException on wait Indefinitely lock:" + exception.getMessage(),
 397  
                                  exception );
 398  0
             }
 399  0
         }
 400  0
     }
 401  
 
 402  
     public void stop()
 403  
         throws Exception
 404  
     {
 405  0
         if ( container != null )
 406  
         {
 407  0
             container.stop();
 408  
         }
 409  0
         if ( tomcat != null )
 410  
         {
 411  0
             tomcat.stop();
 412  
         }
 413  0
     }
 414  
 
 415  
     protected void extract()
 416  
         throws Exception
 417  
     {
 418  
 
 419  0
         if ( extractDirectoryFile.exists() )
 420  
         {
 421  0
             debugMessage( "delete extractDirectory:" + extractDirectoryFile.getAbsolutePath() );
 422  0
             FileUtils.deleteDirectory( extractDirectoryFile );
 423  
         }
 424  
 
 425  0
         if ( !this.extractDirectoryFile.exists() )
 426  
         {
 427  0
             boolean created = this.extractDirectoryFile.mkdirs();
 428  0
             if ( !created )
 429  
             {
 430  0
                 throw new Exception( "FATAL: impossible to create directory:" + this.extractDirectoryFile.getPath() );
 431  
             }
 432  
         }
 433  
 
 434  
         // ensure webapp dir is here
 435  0
         boolean created = new File( extractDirectory, "webapps" ).mkdirs();
 436  0
         if ( !created )
 437  
         {
 438  0
             throw new Exception(
 439  
                 "FATAL: impossible to create directory:" + this.extractDirectoryFile.getPath() + "/webapps" );
 440  
 
 441  
         }
 442  
 
 443  0
         String wars = runtimeProperties.getProperty( WARS_KEY );
 444  0
         populateWebAppWarPerContext( wars );
 445  
 
 446  0
         for ( Map.Entry<String, String> entry : webappWarPerContext.entrySet() )
 447  
         {
 448  0
             debugMessage( "webappWarPerContext entry key/value: " + entry.getKey() + "/" + entry.getValue() );
 449  0
             InputStream inputStream = null;
 450  
             try
 451  
             {
 452  0
                 inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream( entry.getValue() );
 453  0
                 if ( !useServerXml() )
 454  
                 {
 455  0
                     if ( entry.getKey().equals( "/" ) )
 456  
                     {
 457  0
                         File expandFile = new File( extractDirectory, "webapps/ROOT.war" );
 458  0
                         debugMessage( "expand to file:" + expandFile.getPath() );
 459  0
                         expand( inputStream, expandFile );
 460  0
                     }
 461  
                     else
 462  
                     {
 463  0
                         File expandFile = new File( extractDirectory, "webapps/" + entry.getValue() );
 464  0
                         debugMessage( "expand to file:" + expandFile.getPath() );
 465  0
                         expand( inputStream, expandFile );
 466  0
                     }
 467  
                 }
 468  
                 else
 469  
                 {
 470  0
                     File expandFile = new File( extractDirectory, "webapps/" + entry.getValue() );
 471  0
                     debugMessage( "expand to file:" + expandFile.getPath() );
 472  0
                     expand( inputStream, new File( extractDirectory, "webapps/" + entry.getValue() ) );
 473  
                 }
 474  
             }
 475  
             finally
 476  
             {
 477  0
                 if ( inputStream != null )
 478  
                 {
 479  0
                     inputStream.close();
 480  
                 }
 481  
             }
 482  0
         }
 483  
 
 484  
         // expand tomcat configuration files if there
 485  0
         expandConfigurationFile( "catalina.properties", extractDirectoryFile );
 486  0
         expandConfigurationFile( "logging.properties", extractDirectoryFile );
 487  0
         expandConfigurationFile( "tomcat-users.xml", extractDirectoryFile );
 488  0
         expandConfigurationFile( "catalina.policy", extractDirectoryFile );
 489  0
         expandConfigurationFile( "context.xml", extractDirectoryFile );
 490  0
         expandConfigurationFile( "server.xml", extractDirectoryFile );
 491  0
         expandConfigurationFile( "web.xml", extractDirectoryFile );
 492  
 
 493  0
     }
 494  
 
 495  
     private static void expandConfigurationFile( String fileName, File extractDirectory )
 496  
         throws Exception
 497  
     {
 498  0
         InputStream inputStream = null;
 499  
         try
 500  
         {
 501  0
             inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream( "conf/" + fileName );
 502  0
             if ( inputStream != null )
 503  
             {
 504  0
                 File confDirectory = new File( extractDirectory, "conf" );
 505  0
                 if ( !confDirectory.exists() )
 506  
                 {
 507  0
                     confDirectory.mkdirs();
 508  
                 }
 509  0
                 expand( inputStream, new File( confDirectory, fileName ) );
 510  
             }
 511  
         }
 512  
         finally
 513  
         {
 514  0
             if ( inputStream != null )
 515  
             {
 516  0
                 inputStream.close();
 517  
             }
 518  
         }
 519  
 
 520  0
     }
 521  
 
 522  
     /**
 523  
      * @param warsValue we can value in format: wars=foo.war|contextpath;bar.war  ( |contextpath is optionnal if empty use the war name)
 524  
      *                  so here we return war file name and populate webappWarPerContext
 525  
      */
 526  
     private void populateWebAppWarPerContext( String warsValue )
 527  
     {
 528  0
         StringTokenizer st = new StringTokenizer( warsValue, ";" );
 529  0
         while ( st.hasMoreTokens() )
 530  
         {
 531  0
             String warValue = st.nextToken();
 532  0
             debugMessage( "populateWebAppWarPerContext warValue:" + warValue );
 533  0
             String warFileName = "";
 534  0
             String contextValue = "";
 535  0
             int separatorIndex = warValue.indexOf( "|" );
 536  0
             if ( separatorIndex >= 0 )
 537  
             {
 538  0
                 warFileName = warValue.substring( 0, separatorIndex );
 539  0
                 contextValue = warValue.substring( separatorIndex + 1, warValue.length() );
 540  
 
 541  
             }
 542  
             else
 543  
             {
 544  0
                 warFileName = contextValue;
 545  
             }
 546  0
             debugMessage( "populateWebAppWarPerContext contextValue/warFileName:" + contextValue + "/" + warFileName );
 547  0
             this.webappWarPerContext.put( contextValue, warFileName );
 548  0
         }
 549  0
     }
 550  
 
 551  
 
 552  
     /**
 553  
      * Expand the specified input stream into the specified file.
 554  
      *
 555  
      * @param input InputStream to be copied
 556  
      * @param file  The file to be created
 557  
      * @throws java.io.IOException if an input/output error occurs
 558  
      */
 559  
     private static void expand( InputStream input, File file )
 560  
         throws IOException
 561  
     {
 562  0
         BufferedOutputStream output = null;
 563  
         try
 564  
         {
 565  0
             output = new BufferedOutputStream( new FileOutputStream( file ) );
 566  0
             byte buffer[] = new byte[2048];
 567  
             while ( true )
 568  
             {
 569  0
                 int n = input.read( buffer );
 570  0
                 if ( n <= 0 )
 571  
                 {
 572  0
                     break;
 573  
                 }
 574  0
                 output.write( buffer, 0, n );
 575  0
             }
 576  
         }
 577  
         finally
 578  
         {
 579  0
             if ( output != null )
 580  
             {
 581  
                 try
 582  
                 {
 583  0
                     output.close();
 584  
                 }
 585  0
                 catch ( IOException e )
 586  
                 {
 587  
                     // Ignore
 588  0
                 }
 589  
             }
 590  
         }
 591  0
     }
 592  
 
 593  
     public boolean useServerXml()
 594  
     {
 595  0
         return Boolean.parseBoolean( runtimeProperties.getProperty( USE_SERVER_XML_KEY, Boolean.FALSE.toString() ) );
 596  
     }
 597  
 
 598  
 
 599  
     public void debugMessage( String message )
 600  
     {
 601  0
         if ( debug )
 602  
         {
 603  0
             System.out.println( message );
 604  
         }
 605  0
     }
 606  
 
 607  
 
 608  
     public boolean enableNaming()
 609  
     {
 610  0
         return Boolean.parseBoolean( runtimeProperties.getProperty( ENABLE_NAMING_KEY, Boolean.FALSE.toString() ) );
 611  
     }
 612  
 
 613  
     private void installLogger( String loggerName )
 614  
         throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
 615  
         InvocationTargetException
 616  
     {
 617  0
         if ( "slf4j".equals( loggerName ) )
 618  
         {
 619  
 
 620  
             try
 621  
             {
 622  
                 // Check class is available
 623  
 
 624  
                 //final Class<?> clazz = Class.forName( "org.slf4j.bridge.SLF4JBridgeHandler" );
 625  0
                 final Class<?> clazz =
 626  
                     Thread.currentThread().getContextClassLoader().loadClass( "org.slf4j.bridge.SLF4JBridgeHandler" );
 627  
 
 628  
                 // Remove all JUL handlers
 629  0
                 java.util.logging.LogManager.getLogManager().reset();
 630  
 
 631  
                 // Install slf4j bridge handler
 632  0
                 final Method method = clazz.getMethod( "install", null );
 633  0
                 method.invoke( null );
 634  
             }
 635  0
             catch ( ClassNotFoundException e )
 636  
             {
 637  0
                 System.out.println( "WARNING: issue configuring slf4j jul bridge, skip it" );
 638  0
             }
 639  
         }
 640  
         else
 641  
         {
 642  0
             System.out.println( "WARNING: loggerName " + loggerName + " not supported, skip it" );
 643  
         }
 644  0
     }
 645  
 
 646  
     private Properties loadProperties( File file )
 647  
         throws FileNotFoundException, IOException
 648  
     {
 649  0
         Properties properties = new Properties();
 650  0
         if ( file.exists() )
 651  
         {
 652  
 
 653  0
             FileInputStream fileInputStream = new FileInputStream( file );
 654  
             try
 655  
             {
 656  0
                 properties.load( fileInputStream );
 657  
             }
 658  
             finally
 659  
             {
 660  0
                 fileInputStream.close();
 661  0
             }
 662  
 
 663  
         }
 664  0
         return properties;
 665  
     }
 666  
 
 667  
     private void saveProperties( Properties properties, File file )
 668  
         throws FileNotFoundException, IOException
 669  
     {
 670  0
         FileOutputStream fileOutputStream = new FileOutputStream( file );
 671  
         try
 672  
         {
 673  0
             properties.store( fileOutputStream, "Timestamp file for executable war/jar" );
 674  
         }
 675  
         finally
 676  
         {
 677  0
             fileOutputStream.close();
 678  0
         }
 679  0
     }
 680  
 }