Author: dain
Date: Wed Sep 19 18:50:08 2007
New Revision: 577498
URL: http://svn.apache.org/viewvc?rev=577498&view=rev
Log:
Merging 577136 from trunk
Enable logging when embedded in Tomcat
Write openejb.xml to Tomcat conf dir during install
Append logging.properties to Tomcat logging.properties file during install
Modified:
openejb/branches/3.0-beta-1/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/installer/Installer.java
openejb/branches/3.0-beta-1/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/installer/Paths.java
openejb/branches/3.0-beta-1/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java
openejb/branches/3.0-beta-1/container/openejb-core/src/main/resources/logging.properties
Modified:
openejb/branches/3.0-beta-1/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/installer/Installer.java
URL:
http://svn.apache.org/viewvc/openejb/branches/3.0-beta-1/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/installer/Installer.java?rev=577498&r1=577497&r2=577498&view=diff
==============================================================================
---
openejb/branches/3.0-beta-1/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/installer/Installer.java
(original)
+++
openejb/branches/3.0-beta-1/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/installer/Installer.java
Wed Sep 19 18:50:08 2007
@@ -32,6 +32,8 @@
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.jar.JarFile;
public class Installer {
public enum Status {
@@ -88,6 +90,8 @@
installJavaagent();
+ installConfigFiles();
+
if (!hasErrors()) {
status = Status.REBOOT_REQUIRED;
}
@@ -226,6 +230,83 @@
}
}
+ private void installConfigFiles() {
+ if (paths.getOpenEJBCoreJar() == null) {
+ // the core jar contains the config files
+ return;
+ }
+ JarFile coreJar = null;
+ try {
+ coreJar = new JarFile(paths.getOpenEJBCoreJar());
+ } catch (IOException e) {
+ return;
+ }
+
+ //
+ // conf/openejb.xml
+ //
+ File openEjbXmlFile = new File(paths.getCatalinaConfDir(),
"openejb.xml");
+ if (!openEjbXmlFile.exists()) {
+ // read in the openejb.xml file from the openejb core jar
+ String openEjbXml = readEntry(coreJar, "default.openejb.conf");
+ if (openEjbXml != null) {
+ if (writeAll(openEjbXmlFile, openEjbXml)) {
+ addInfo("Added openejb.xml to Tomcat conf directory.");
+ }
+ }
+ }
+
+
+ //
+ // conf/logging.properties
+ //
+ String openejbLoggingProps = readEntry(coreJar, "logging.properties");
+ if (openejbLoggingProps != null) {
+ File loggingPropsFile = new File(paths.getCatalinaConfDir(),
"logging.properties");
+ String newLoggingProps = null;
+ if (!loggingPropsFile.exists()) {
+ newLoggingProps = openejbLoggingProps;
+ } else {
+ String loggingPropsOriginal = readAll(loggingPropsFile);
+ if (!loggingPropsOriginal.contains("OpenEJB")) {
+ // strip off license header
+ String[] strings = openejbLoggingProps.split("## --*", 3);
+ if (strings.length == 3) {
+ openejbLoggingProps = strings[2];
+ }
+ // append our properties
+ newLoggingProps = loggingPropsOriginal +
+ "\r\n" +
+
"############################################################\r\n" +
+ "# OpenEJB Logging Configuration.\r\n" +
+
"############################################################\r\n" +
+ openejbLoggingProps + "\r\n";
+ }
+ }
+ if (newLoggingProps != null) {
+ if (writeAll(loggingPropsFile, newLoggingProps)) {
+ addInfo("Added OpenEJB logging configuration to Tomcat
logging.properties file.");
+ }
+ }
+ }
+ }
+
+ private String readEntry(JarFile jarFile, String name) {
+ ZipEntry entry = jarFile.getEntry(name);
+ if (entry == null) return null;
+ InputStream in = null;
+ try {
+ in = jarFile.getInputStream(entry);
+ String text = readAll(in);
+ return text;
+ } catch (Exception e) {
+ addError("Unable to read " + name + " from " + jarFile.getName());
+ return null;
+ } finally {
+ close(in);
+ }
+ }
+
private String replace(String inputText, String begin, String newBegin,
String end, String newEnd) throws IOException {
BeginEndTokenHandler tokenHandler = new BeginEndTokenHandler(newBegin,
newEnd);
@@ -390,6 +471,7 @@
errors.add(message);
}
+ @SuppressWarnings({"UnusedDeclaration"})
private void addError(String message, Exception e) {
// todo add exception somehow
System.out.println(message);
Modified:
openejb/branches/3.0-beta-1/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/installer/Paths.java
URL:
http://svn.apache.org/viewvc/openejb/branches/3.0-beta-1/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/installer/Paths.java?rev=577498&r1=577497&r2=577498&view=diff
==============================================================================
---
openejb/branches/3.0-beta-1/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/installer/Paths.java
(original)
+++
openejb/branches/3.0-beta-1/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/installer/Paths.java
Wed Sep 19 18:50:08 2007
@@ -73,11 +73,11 @@
public File getServerXmlFile() {
if (serverXmlFile == null) {
- File catalinaBaseDir = getCatalinaBaseDir();
- if (catalinaBaseDir == null) return null;
+ File confdir = getCatalinaConfDir();
- File catalinaConfDir = new File(catalinaBaseDir, "conf");
- serverXmlFile = new File(catalinaConfDir, "server.xml");
+ if (confdir == null) return null;
+
+ serverXmlFile = new File(confdir, "server.xml");
}
return serverXmlFile;
}
@@ -98,6 +98,14 @@
return new File(catalinaHomeDir, "lib");
}
+ public File getCatalinaConfDir() {
+ File catalinaBaseDir = getCatalinaBaseDir();
+
+ if (catalinaBaseDir == null) return null;
+
+ return new File(catalinaBaseDir, "conf");
+ }
+
public File getCatalinaBinDir() {
File catalinaHomeDir = getCatalinaHomeDir();
@@ -128,6 +136,10 @@
return findOpenEJBJar("openejb-javaagent");
}
+ public File getOpenEJBCoreJar() {
+ return findOpenEJBJar("openejb-core");
+ }
+
private File findOpenEJBJar(String namePrefix) {
File openEJBLibDir = getOpenEJBLibDir();
if (openEJBLibDir == null) return null;
@@ -159,6 +171,7 @@
}
verifyWritableDirectory("Catalina lib", getCatalinaLibDir());
+ verifyWritableDirectory("Catalina conf", getCatalinaConfDir());
verifyDirectory("Catalina bin", getCatalinaBinDir());
verifyWritableFile("Catalina server.xml", getServerXmlFile());
verifyWritableFile("Catalina catalina.sh", getCatalinaShFile());
@@ -177,6 +190,11 @@
}
verifyFile("OpenEJB javaagent jar", openejbJavaagentJar);
+ File openejbCoreJar = getOpenEJBCoreJar();
+ if (openejbCoreJar != null) {
+ verifyFile("OpenEJB core jar", openejbCoreJar);
+ }
+
return !hasErrors();
}
@@ -263,6 +281,7 @@
printFile(out, "Catalina home: ", getCatalinaHomeDir());
printFile(out, "Catalina base: ", getCatalinaBaseDir());
printFile(out, "Catalina server.xml: ", getServerXmlFile());
+ printFile(out, "Catalina conf: ", getCatalinaConfDir());
printFile(out, "Catalina lib: ", getCatalinaLibDir());
printFile(out, "Catalina bin: ", getCatalinaBinDir());
printFile(out, "Catalina catalina.sh: ", getCatalinaShFile());
Modified:
openejb/branches/3.0-beta-1/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java
URL:
http://svn.apache.org/viewvc/openejb/branches/3.0-beta-1/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java?rev=577498&r1=577497&r2=577498&view=diff
==============================================================================
---
openejb/branches/3.0-beta-1/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java
(original)
+++
openejb/branches/3.0-beta-1/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java
Wed Sep 19 18:50:08 2007
@@ -35,6 +35,7 @@
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
+import java.util.Map;
public class Logger {
@@ -125,9 +126,9 @@
boolean externalLogging = Boolean.parseBoolean(prop);
if(!externalLogging)
configureInternal();
- } catch (IOException e) {
+ } catch (Exception e) {
// The fall back here is that if log4j.configuration system property
is set, then that configuration file will be used.
-
+ e.printStackTrace();
}
}
@@ -143,7 +144,8 @@
BufferedInputStream bis = new
BufferedInputStream(new FileInputStream(loggingPropertiesFile));
Properties props = new Properties();
props.load(bis);
- PropertyConfigurator.configure(props);
+ preprocessProperties(props);
+ PropertyConfigurator.configure(props);
try{
bis.close();
}catch(IOException e){
@@ -157,13 +159,25 @@
}
}
- private static void configureEmbedded(){
+ private static void preprocessProperties(Properties props) {
+ String openejbHome =
SystemInstance.get().getHome().getDirectory().getAbsolutePath();
+ String openejbBase =
SystemInstance.get().getBase().getDirectory().getAbsolutePath();
+ for (Map.Entry<Object, Object> entry : props.entrySet()) {
+ String value = (String) entry.getValue();
+ value = value.replace("${openejb.home}", openejbHome);
+ value = value.replace("${openejb.base}", openejbBase);
+ entry.setValue(value);
+ }
+ }
+
+ private static void configureEmbedded(){
URL resource =
Thread.currentThread().getContextClassLoader().getResource(EMBEDDED_PROPERTIES_FILE);
if(resource != null)
PropertyConfigurator.configure(resource);
else
System.out.println("FATAL ERROR WHILE CONFIGURING LOGGING!!!.
MISSING embedded.logging.properties FILE ");
}
+
private static void installLoggingPropertiesFile(File
loggingPropertiesFile) throws IOException {
URL resource =
Thread.currentThread().getContextClassLoader().getResource(LOGGING_PROPERTIES_FILE);
if(resource == null){
@@ -184,6 +198,7 @@
Properties props = new Properties();
props.load(bis);
+ preprocessProperties(props);
BufferedOutputStream bout = new BufferedOutputStream(new
FileOutputStream(loggingPropertiesFile));
bout.write(byteArray);
PropertyConfigurator.configure(props);
Modified:
openejb/branches/3.0-beta-1/container/openejb-core/src/main/resources/logging.properties
URL:
http://svn.apache.org/viewvc/openejb/branches/3.0-beta-1/container/openejb-core/src/main/resources/logging.properties?rev=577498&r1=577497&r2=577498&view=diff
==============================================================================
---
openejb/branches/3.0-beta-1/container/openejb-core/src/main/resources/logging.properties
(original)
+++
openejb/branches/3.0-beta-1/container/openejb-core/src/main/resources/logging.properties
Wed Sep 19 18:50:08 2007
@@ -1,19 +1,19 @@
-#/**
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
log4j.category.OpenEJB=warn,R
log4j.category.OpenEJB.startup=debug
log4j.category.OpenEJB.server=info
@@ -28,12 +28,12 @@
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.MaxFileSize=1000KB
log4j.appender.R.MaxBackupIndex=7
-log4j.appender.R.File=logs/openejb.log
+log4j.appender.R.File=${openejb.base}/logs/openejb.log
log4j.appender.R.layout.ConversionPattern=%d - %-5p - %m%n
log4j.appender.TX=org.apache.log4j.RollingFileAppender
log4j.appender.TX.layout=org.apache.log4j.PatternLayout
log4j.appender.TX.MaxFileSize=1000KB
log4j.appender.TX.MaxBackupIndex=100
-log4j.appender.TX.File=logs/transaction.log
+log4j.appender.TX.File=${openejb.base}/logs/transaction.log
log4j.appender.TX.layout.ConversionPattern=%d - %-5p - %m%n