You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2012/12/20 12:42:57 UTC
svn commit: r1424417 - in /openejb/trunk/openejb/container:
openejb-core/src/main/java/org/apache/openejb/assembler/classic/
openejb-core/src/main/java/org/apache/openejb/core/stateful/
openejb-loader/src/main/java/org/apache/openejb/loader/
Author: andygumbrecht
Date: Thu Dec 20 11:42:56 2012
New Revision: 1424417
URL: http://svn.apache.org/viewvc?rev=1424417&view=rev
Log:
Use known path and log error - Something is wrong.
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/CmpJarBuilder.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java
openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/FileUtils.java
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/CmpJarBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/CmpJarBuilder.java?rev=1424417&r1=1424416&r2=1424417&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/CmpJarBuilder.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/CmpJarBuilder.java Thu Dec 20 11:42:56 2012
@@ -22,6 +22,9 @@ import org.apache.openejb.core.cmp.cmp2.
import org.apache.openejb.core.cmp.cmp2.Cmp2Generator;
import org.apache.openejb.core.cmp.cmp2.CmrField;
import org.apache.openejb.loader.IO;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Logger;
import org.apache.openejb.util.UrlCache;
import java.io.File;
@@ -99,7 +102,7 @@ public class CmpJarBuilder {
close(jarOutputStream);
if (threwException) {
- if (!jarFile.delete()) {
+ if (null != jarFile && !jarFile.delete()) {
jarFile.deleteOnExit();
}
jarFile = null;
@@ -240,14 +243,23 @@ public class CmpJarBuilder {
}
private static synchronized JarOutputStream openJarFile(final CmpJarBuilder instance) throws IOException {
+
if (instance.jarFile != null) {
- throw new IllegalStateException("Jar file is closed");
+ throw new IllegalStateException("Jar file exists already");
+ }
+
+ File dir = UrlCache.cacheDir;
+
+ if (null == dir) {
+ dir = SystemInstance.get().getBase().getDirectory("tmp", true);
}
// if url caching is enabled, generate the file directly in the cache dir, so it doesn't have to be recoppied
try {
- instance.jarFile = File.createTempFile("OpenEJB_Generated_", ".jar", UrlCache.cacheDir);
- } catch (IOException e) {
+ instance.jarFile = File.createTempFile("OpenEJBGenerated.", ".jar", dir).getAbsoluteFile();
+ } catch (Throwable e) {
+
+ Logger.getInstance(LogCategory.OPENEJB_STARTUP, CmpJarBuilder.class).warning("Failed to create temp jar file in: " + dir, e);
//Try
try {
@@ -255,12 +267,16 @@ public class CmpJarBuilder {
} catch (InterruptedException ie) {
//Ignore
}
- instance.jarFile = File.createTempFile("OpenEJB_Generated_", ".jar", UrlCache.cacheDir);
+
+ instance.jarFile = File.createTempFile("OpenEJBGenerated.", ".jar", dir).getAbsoluteFile();
}
Thread.yield();
instance.jarFile.deleteOnExit();
+
+ Logger.getInstance(LogCategory.OPENEJB_STARTUP, CmpJarBuilder.class).debug("Using temp jar file: " + instance.jarFile);
+
return new JarOutputStream(IO.write(instance.jarFile));
}
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java?rev=1424417&r1=1424416&r2=1424417&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java Thu Dec 20 11:42:56 2012
@@ -53,7 +53,17 @@ public class SimplePassivater implements
} else {
sessionDirectory = new File(System.getProperty("java.io.tmpdir", File.separator + "tmp"));
}
+
+ if (!sessionDirectory.exists() && !sessionDirectory.mkdirs()) {
+ throw new java.io.IOException("Failed to create session directory: " + sessionDirectory.getAbsolutePath());
+ }
+
+ if (sessionDirectory.exists() && !sessionDirectory.isDirectory()) {
+ throw new java.io.IOException("Session directory exists as a file: " + sessionDirectory.getAbsolutePath());
+ }
+
logger.info("Using directory " + sessionDirectory + " for stateful session passivation");
+
} catch (java.io.IOException e) {
throw new SystemException(getClass().getName() + ".init(): can't use directory prefix " + dir + ":" + e, e);
}
Modified: openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/FileUtils.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/FileUtils.java?rev=1424417&r1=1424416&r2=1424417&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/FileUtils.java (original)
+++ openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/FileUtils.java Thu Dec 20 11:42:56 2012
@@ -27,13 +27,15 @@ public class FileUtils {
private File home;
- private FileUtils(String homeDir, String defaultDir) {
+ private FileUtils(final String homeDir, final String defaultDir) {
this(homeDir, defaultDir, SystemInstance.get().getProperties());
}
- public FileUtils(String homeDir, String defaultDir, Hashtable env) {
- String homePath = null;
- homePath = (String) env.get(homeDir);
+ @SuppressWarnings("UseOfObsoleteCollectionType")
+ public FileUtils(final String homeDir, final String defaultDir, final Hashtable env) {
+
+ String homePath = (String) env.get(homeDir);
+
if (homePath == null) {
homePath = (String) env.get(defaultDir);
}
@@ -56,20 +58,19 @@ public class FileUtils {
}
}
- public File getDirectory(String path) throws IOException {
+ public File getDirectory(final String path) throws IOException {
return getDirectory(path, false);
}
- public boolean equals(Object obj) {
- if (!(obj instanceof FileUtils)) return false;
- FileUtils that = (FileUtils) obj;
+ public boolean equals(final Object obj) {
+ if (!(obj instanceof FileUtils))
+ return false;
+ final FileUtils that = (FileUtils) obj;
return this.getDirectory().equals(that.getDirectory());
}
- public File getDirectory(String path, boolean create) throws IOException {
- File dir = null;
-
- dir = new File(home, path);
+ public File getDirectory(final String path, final boolean create) throws IOException {
+ File dir = new File(home, path);
dir = dir.getCanonicalFile();
if (!dir.exists() && create) {
@@ -91,18 +92,16 @@ public class FileUtils {
return home;
}
- public void setDirectory(File dir) {
+ public void setDirectory(final File dir) {
this.home = dir;
}
- public File getFile(String path) throws java.io.FileNotFoundException, java.io.IOException {
+ public File getFile(final String path) throws java.io.FileNotFoundException, java.io.IOException {
return getFile(path, true);
}
- public File getFile(String path, boolean validate) throws java.io.FileNotFoundException, java.io.IOException {
- File file = null;
-
- file = new File(path);
+ public File getFile(final String path, final boolean validate) throws java.io.FileNotFoundException, java.io.IOException {
+ File file = new File(path);
if (!file.isAbsolute()) {
file = new File(home, path);
@@ -117,22 +116,21 @@ public class FileUtils {
return file;
}
- public static File createTempDirectory(String pathPrefix) throws java.io.IOException {
+ public static File createTempDirectory(final String pathPrefix) throws java.io.IOException {
for (int maxAttempts = 100; maxAttempts > 0; --maxAttempts) {
- String path = pathPrefix + _random.nextLong();
- java.io.File tmpDir = new java.io.File(path);
- if (tmpDir.exists()) {
- continue;
- } else {
- tmpDir.mkdir();
+
+ final String path = pathPrefix + _random.nextLong();
+ final java.io.File tmpDir = new java.io.File(path);
+
+ if (!tmpDir.exists() && tmpDir.mkdirs()) {
return tmpDir;
}
}
- throw new java.io.IOException("Can't create temporary directory.");
+ throw new java.io.IOException("Cannot create temporary directory at: " + pathPrefix);
}
public static File createTempDirectory() throws java.io.IOException {
- String prefix = System.getProperty("java.io.tmpdir", File.separator + "tmp") + File.separator + "openejb";
+ final String prefix = System.getProperty("java.io.tmpdir", File.separator + "tmp") + File.separator + "openejb";
return createTempDirectory(prefix);
}