Author: andygumbrecht
Date: Mon Dec 24 12:45:58 2012
New Revision: 1425642
URL: http://svn.apache.org/viewvc?rev=1425642&view=rev
Log:
Fallback to a local tmp directory.
Finals.
Modified:
openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java
openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/cmd/Info2Properties.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/ProviderWrapper.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/WebArchives.java
openejb/trunk/openejb/container/openejb-javaagent/src/main/java/org/apache/openejb/javaagent/Agent.java
openejb/trunk/openejb/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java
openejb/trunk/openejb/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImpl.java
Modified:
openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java?rev=1425642&r1=1425641&r2=1425642&view=diff
==============================================================================
---
openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java
(original)
+++
openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java
Mon Dec 24 12:45:58 2012
@@ -26,9 +26,9 @@ import java.util.List;
*/
public class Files {
- public static File path(String... parts) {
+ public static File path(final String... parts) {
File dir = null;
- for (String part : parts) {
+ for (final String part : parts) {
if (dir == null) {
dir = new File(part);
} else {
@@ -39,8 +39,8 @@ public class Files {
return dir;
}
- public static File path(File dir, String... parts) {
- for (String part : parts) {
+ public static File path(File dir, final String... parts) {
+ for (final String part : parts) {
dir = new File(dir, part);
}
@@ -52,13 +52,23 @@ public class Files {
}
public static File createTempDir(final String prefix, final String suffix)
throws IOException {
- final File tempDir = File.createTempFile(prefix, suffix);
- tempDir.delete();
- tempDir.mkdirs();
+ File tempDir;
+ try {
+ tempDir = File.createTempFile(prefix, suffix);
+ } catch (Throwable e) {
+ final File tmp = new File("tmp");
+ if (!tmp.exists() && !tmp.mkdirs()) {
+ throw new IOException("Failed to create local tmp directory: "
+ tmp.getAbsolutePath());
+ }
+ tempDir = File.createTempFile(prefix, suffix, tmp);
+ }
+ if (!tempDir.delete() && tempDir.mkdirs()) {
+ throw new IOException("Failed to create temp directory: " +
tempDir.getAbsolutePath());
+ }
deleteOnExit(tempDir);
return tempDir;
}
-
+
private Files() {
// no-op
}
@@ -96,7 +106,7 @@ public class Files {
}
}
- if(!file.delete()){
+ if (!file.delete()) {
file.deleteOnExit();
}
}
Modified:
openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java?rev=1425642&r1=1425641&r2=1425642&view=diff
==============================================================================
---
openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
(original)
+++
openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
Mon Dec 24 12:45:58 2012
@@ -19,21 +19,18 @@ package org.apache.openejb.arquillian.co
import org.apache.openejb.loader.*;
import org.apache.openejb.resolver.Resolver;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.*;
import java.net.URI;
import java.util.logging.Logger;
public class MavenCache {
private static final Logger LOGGER =
Logger.getLogger(MavenCache.class.getName());
- public static File getArtifact(String artifactInfo, String altUrl) {
+ public static File getArtifact(final String artifactInfo, final String
altUrl) {
LOGGER.info("Downloading " + artifactInfo + " please wait...");
try {
- return new File(new
Resolver().resolve(artifactInfo.startsWith("mvn")? "" : "mvn:" + artifactInfo));
+ return new File(new
Resolver().resolve(artifactInfo.startsWith("mvn") ? "" : "mvn:" +
artifactInfo));
} catch (Exception e) {
// ignored
}
@@ -47,45 +44,53 @@ public class MavenCache {
throw new IllegalStateException(e1);
}
- return null;
- }
+ return null;
+ }
- public static File download(String source) throws DownloadException {
- File file = null;
- InputStream is = null;
- OutputStream os = null;
- try {
- is = ProvisioningUtil.inputStreamTryingProxies(new
URI(source));
- file = File.createTempFile("dload", ".fil");
- file.deleteOnExit();
- os = new FileOutputStream(file);
-
- int bytesRead;
- byte[] buffer = new byte[8192];
-
- while ((bytesRead = is.read(buffer)) > -1) {
- os.write(buffer, 0, bytesRead);
- }
- } catch (Exception e) {
- throw new DownloadException("Unable to download " +
source + " to " + file.getAbsolutePath(), e);
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (Exception e) {
+ public static File download(final String source) throws DownloadException {
+ File file = null;
+ InputStream is = null;
+ OutputStream os = null;
+ try {
+ is = ProvisioningUtil.inputStreamTryingProxies(new URI(source));
+ try {
+ file = File.createTempFile("dload", ".fil");
+ } catch (Throwable e) {
+ final File tmp = new File("tmp");
+ if (!tmp.exists() && !tmp.mkdirs()) {
+ throw new IOException("Failed to create local tmp
directory: " + tmp.getAbsolutePath());
+ }
+ file = File.createTempFile("dload", ".fil", tmp);
+ }
+ file.deleteOnExit();
+ os = new FileOutputStream(file);
+
+ int bytesRead;
+ final byte[] buffer = new byte[8192];
+
+ while ((bytesRead = is.read(buffer)) > -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+ } catch (Exception e) {
+ throw new DownloadException("Unable to download " + source + " to
" + file.getAbsolutePath(), e);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (Exception e) {
// no-op
- }
- }
+ }
+ }
- if (os != null) {
- try {
- os.close();
- } catch (Exception e) {
+ if (os != null) {
+ try {
+ os.close();
+ } catch (Exception e) {
// no-op
- }
- }
- }
-
- return file;
- }
+ }
+ }
+ }
+
+ return file;
+ }
}
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/cmd/Info2Properties.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/cmd/Info2Properties.java?rev=1425642&r1=1425641&r2=1425642&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/cmd/Info2Properties.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/cmd/Info2Properties.java
Mon Dec 24 12:45:58 2012
@@ -16,14 +16,7 @@
*/
package org.apache.openejb.assembler.classic.cmd;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.cli.PosixParser;
+import org.apache.commons.cli.*;
import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
import org.apache.openejb.assembler.classic.ServiceInfo;
import org.apache.openejb.loader.SystemInstance;
@@ -34,11 +27,7 @@ import org.apache.openejb.util.URISuppor
import javax.naming.Context;
import javax.naming.InitialContext;
-import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.PrintWriter;
+import java.io.*;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -52,12 +41,12 @@ public class Info2Properties {
private static final String defaultServerUrl = "ejbd://localhost:4201";
- public static void main(String[] args) {
+ public static void main(final String[] args) {
- CommandLineParser parser = new PosixParser();
+ final CommandLineParser parser = new PosixParser();
// create the Options
- Options options = new Options();
+ final Options options = new Options();
options.addOption(option("v", "version",
"cmd.properties.opt.version"));
options.addOption(option("h", "help", "cmd.properties.opt.help"));
options.addOption(option("s", "server-url", "url",
"cmd.properties.opt.server"));
@@ -79,15 +68,15 @@ public class Info2Properties {
System.exit(0);
}
- Properties p = new Properties();
+ final Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
- String serverUrl = line.getOptionValue("server-url", defaultServerUrl);
+ final String serverUrl = line.getOptionValue("server-url",
defaultServerUrl);
p.put(Context.PROVIDER_URL, serverUrl);
ConfigurationInfo configInfo = null;
try {
- InitialContext ctx = new InitialContext(p);
+ final InitialContext ctx = new InitialContext(p);
configInfo = (ConfigurationInfo)
ctx.lookup("openejb/ConfigurationInfoBusinessRemote");
} catch (javax.naming.ServiceUnavailableException e) {
System.out.println(e.getCause().getMessage());
@@ -100,7 +89,17 @@ public class Info2Properties {
File tempFile = null;
try {
- tempFile = File.createTempFile("configrequest", "txt");
+ try {
+ tempFile = File.createTempFile("configrequest", "txt");
+ } catch (Throwable e) {
+ final File tmp = new File("tmp");
+ if (!tmp.exists() && !tmp.mkdirs()) {
+ throw new IOException("Failed to create local tmp
directory: " + tmp.getAbsolutePath());
+ }
+
+ tempFile = File.createTempFile("configrequest", "txt", tmp);
+
+ }
if (!tempFile.exists()) {
throw new IllegalStateException("Failed to create tmp file: "
+ tempFile.getAbsolutePath());
}
@@ -122,8 +121,8 @@ public class Info2Properties {
}
public static void printLocalConfig() {
- OpenEjbConfiguration configuration =
SystemInstance.get().getComponent(OpenEjbConfiguration.class);
- if (configuration != null){
+ final OpenEjbConfiguration configuration =
SystemInstance.get().getComponent(OpenEjbConfiguration.class);
+ if (configuration != null) {
printConfig(configuration);
}
}
@@ -149,15 +148,15 @@ public class Info2Properties {
println(out, cr, "");
println(out, cr, "");
- for (ServiceInfo info : configuration.containerSystem.containers) {
+ for (final ServiceInfo info :
configuration.containerSystem.containers) {
print(out, cr, info);
}
- for (ServiceInfo info : configuration.facilities.connectionManagers) {
+ for (final ServiceInfo info :
configuration.facilities.connectionManagers) {
print(out, cr, info);
}
- for (ServiceInfo info : configuration.facilities.resources) {
+ for (final ServiceInfo info : configuration.facilities.resources) {
print(out, cr, info);
}
@@ -172,7 +171,7 @@ public class Info2Properties {
println(out, cr, "");
println(out, cr, "");
- for (ServiceInfo info : configuration.facilities.services) {
+ for (final ServiceInfo info : configuration.facilities.services) {
print(out, cr, info);
}
@@ -187,7 +186,7 @@ public class Info2Properties {
private static void printSystemProperties(final PrintStream out, final
String cr) {
try {
- SuperProperties p = new SuperProperties();
+ final SuperProperties p = new SuperProperties();
p.setSpaceBetweenProperties(false);
p.setKeyValueSeparator(" = ");
p.setLineSeparator(cr);
@@ -196,9 +195,9 @@ public class Info2Properties {
p.store(out, null);
- Properties p2 = System.getProperties();
- String[] misc = {"os.version", "os.name", "os.arch",
"java.version", "java.vendor"};
- for (String prop : misc) {
+ final Properties p2 = System.getProperties();
+ final String[] misc = {"os.version", "os.name", "os.arch",
"java.version", "java.vendor"};
+ for (final String prop : misc) {
comment(out, cr, prop + "=" + p2.get(prop));
}
} catch (IOException e) {
@@ -206,12 +205,12 @@ public class Info2Properties {
}
}
- private static void copyOpenEjbProperties(Properties source, Properties
dest) {
- for (Map.Entry<Object, Object> entry : source.entrySet()) {
+ private static void copyOpenEjbProperties(final Properties source, final
Properties dest) {
+ for (final Map.Entry<Object, Object> entry : source.entrySet()) {
if (!(entry.getKey() instanceof String)) continue;
if (!(entry.getValue() instanceof String)) continue;
- String key = (String) entry.getKey();
+ final String key = (String) entry.getKey();
if (key.startsWith("openejb.")) {
dest.put(entry.getKey(), entry.getValue());
}
@@ -224,7 +223,7 @@ public class Info2Properties {
println(out, cr, text);
}
- private static void print(final PrintStream out, String text) {
+ private static void print(final PrintStream out, final String text) {
out.print(text);
}
@@ -243,15 +242,15 @@ public class Info2Properties {
// TODO: the codebase value usually isn't filled in, we should do
that.
// comment("codebase: " + info.codebase);
comment(out, cr, "");
- SuperProperties p = new SuperProperties();
+ final SuperProperties p = new SuperProperties();
p.setSpaceBetweenProperties(false);
p.setKeyValueSeparator(" = ");
p.setLineSeparator(cr);
String uri = "new://" + info.service;
- if (info.service.matches("Container|Resource|Connector")){
+ if (info.service.matches("Container|Resource|Connector")) {
try {
- Map query = new HashMap();
+ final Map query = new HashMap();
query.put("type", info.types.get(0));
uri += "?" + URISupport.createQueryString(query);
} catch (Exception e) {
@@ -259,8 +258,8 @@ public class Info2Properties {
}
p.put(info.id, uri);
-
- for (Map.Entry<Object, Object> entry : info.properties.entrySet())
{
+
+ for (final Map.Entry<Object, Object> entry :
info.properties.entrySet()) {
if (!(entry.getKey() instanceof String)) continue;
if (!(entry.getValue() instanceof String)) continue;
@@ -285,11 +284,11 @@ public class Info2Properties {
static class Filter extends java.io.FilterOutputStream {
private boolean pastFirstLine;
- public Filter(OutputStream out) {
+ public Filter(final OutputStream out) {
super(out);
}
- public void write(int b) throws IOException {
+ public void write(final int b) throws IOException {
if (pastFirstLine) super.write(b);
else pastFirstLine = b == '\n';
}
@@ -298,11 +297,11 @@ public class Info2Properties {
static class CommentsFilter extends java.io.FilterOutputStream {
- public CommentsFilter(OutputStream out) {
+ public CommentsFilter(final OutputStream out) {
super(out);
}
- public void write(int b) throws IOException {
+ public void write(final int b) throws IOException {
super.write(b);
if (b == '\n') super.write('#');
@@ -310,20 +309,20 @@ public class Info2Properties {
}
- private static void help(Options options) {
- HelpFormatter formatter = new HelpFormatter();
+ private static void help(final Options options) {
+ final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("properties [options]", "\n" +
i18n("cmd.properties.description"), options, "\n");
}
- private static Option option(String shortOpt, String longOpt, String
description) {
+ private static Option option(final String shortOpt, final String longOpt,
final String description) {
return
OptionBuilder.withLongOpt(longOpt).withDescription(i18n(description)).create(shortOpt);
}
- private static Option option(String shortOpt, String longOpt, String
argName, String description) {
+ private static Option option(final String shortOpt, final String longOpt,
final String argName, final String description) {
return
OptionBuilder.withLongOpt(longOpt).withArgName(argName).hasArg().withDescription(i18n(description)).create(shortOpt);
}
- private static String i18n(String key) {
+ private static String i18n(final String key) {
return messages.format(key);
}
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=1425642&r1=1425641&r2=1425642&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
Mon Dec 24 12:45:58 2012
@@ -320,7 +320,7 @@ public class ReadDescriptors implements
File tempFile = null;
try {
tempFile = File.createTempFile("openejb-jar-",
".xml");
- } catch (IOException e) {
+ } catch (Throwable e) {
final File tmp = new File("tmp");
if (!tmp.exists() && !tmp.mkdirs()) {
throw new IOException("Failed to create local
tmp directory: " + tmp.getAbsolutePath());
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/ProviderWrapper.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/ProviderWrapper.java?rev=1425642&r1=1425641&r2=1425642&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/ProviderWrapper.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/ProviderWrapper.java
Mon Dec 24 12:45:58 2012
@@ -422,7 +422,7 @@ public class ProviderWrapper extends Pro
File tempFile = null;
try {
tempFile = File.createTempFile("openejb-jaxws-provider",
"tmp");
- } catch (IOException e) {
+ } catch (Throwable e) {
final File tmp = new File("tmp");
if (!tmp.exists() && !tmp.mkdirs()) {
throw new IOException("Failed to create local tmp
directory: " + tmp.getAbsolutePath());
Modified:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/WebArchives.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/WebArchives.java?rev=1425642&r1=1425641&r2=1425642&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/WebArchives.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/WebArchives.java
Mon Dec 24 12:45:58 2012
@@ -48,7 +48,7 @@ public class WebArchives {
File classpath;
try {
classpath = File.createTempFile(archiveNamePrefix, ".war");
- } catch (IOException e) {
+ } catch (Throwable e) {
final File tmp = new File("tmp");
if (!tmp.exists() && !tmp.mkdirs()) {
throw new IOException("Failed to create local tmp directory: "
+ tmp.getAbsolutePath());
Modified:
openejb/trunk/openejb/container/openejb-javaagent/src/main/java/org/apache/openejb/javaagent/Agent.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-javaagent/src/main/java/org/apache/openejb/javaagent/Agent.java?rev=1425642&r1=1425641&r2=1425642&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-javaagent/src/main/java/org/apache/openejb/javaagent/Agent.java
(original)
+++
openejb/trunk/openejb/container/openejb-javaagent/src/main/java/org/apache/openejb/javaagent/Agent.java
Mon Dec 24 12:45:58 2012
@@ -187,7 +187,7 @@ public class Agent {
try {
try {
file = File.createTempFile(Agent.class.getName(), ".jar");
- } catch (IOException e) {
+ } catch (Throwable e) {
final File tmp = new File("tmp");
if (!tmp.exists() && !tmp.mkdirs()) {
throw new IOException("Failed to create local tmp
directory: " + tmp.getAbsolutePath());
Modified:
openejb/trunk/openejb/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java?rev=1425642&r1=1425641&r2=1425642&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java
(original)
+++
openejb/trunk/openejb/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java
Mon Dec 24 12:45:58 2012
@@ -334,7 +334,7 @@ public class JeeTest extends TestCase {
File tempFile = null;
try {
tempFile = File.createTempFile("jaxb-output", "xml");
- } catch (IOException e) {
+ } catch (Throwable e) {
final File tmp = new File("tmp");
if (!tmp.exists() && !tmp.mkdirs()) {
throw new IOException("Failed to create local tmp
directory: " + tmp.getAbsolutePath());
Modified:
openejb/trunk/openejb/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImpl.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImpl.java?rev=1425642&r1=1425641&r2=1425642&view=diff
==============================================================================
---
openejb/trunk/openejb/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImpl.java
(original)
+++
openejb/trunk/openejb/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImpl.java
Mon Dec 24 12:45:58 2012
@@ -35,15 +35,7 @@ import org.jboss.testharness.spi.Contain
import javax.ejb.EJBException;
import javax.ejb.embeddable.EJBContainer;
import javax.validation.ValidationException;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.Flushable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.RandomAccessFile;
+import java.io.*;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.URLClassLoader;
@@ -59,6 +51,7 @@ import java.util.zip.ZipOutputStream;
/**
* @version $Rev$ $Date$
*/
+@SuppressWarnings("UnusedDeclaration")
public class ContainersImpl implements Containers {
private static String stuck;
@@ -68,7 +61,7 @@ public class ContainersImpl implements C
private ClassLoader originalClassLoader;
@Override
- public boolean deploy(InputStream archive, String name) {
+ public boolean deploy(final InputStream archive, final String name) {
if (!OpenEJB.isInitialized()) stuck = name;
else System.out.println("STUCK " + stuck);
@@ -87,7 +80,7 @@ public class ContainersImpl implements C
map.put(EJBContainer.APP_NAME, name);
originalClassLoader =
Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(new
URLClassLoader(new URL[]{ file.toURI().toURL() }, originalClassLoader));
+ Thread.currentThread().setContextClassLoader(new
URLClassLoader(new URL[]{file.toURI().toURL()}, originalClassLoader));
container = EJBContainer.createEJBContainer(map);
// final WebBeansContext webBeansContext =
ThreadSingletonServiceImpl.get();
@@ -104,11 +97,11 @@ public class ContainersImpl implements C
return true;
}
- private void dump(Object o) {
+ private void dump(final Object o) {
try {
final Class<?> clazz = o.getClass();
- for (Field field : clazz.getDeclaredFields()) {
+ for (final Field field : clazz.getDeclaredFields()) {
SetAccessible.on(field);
if (Collection.class.isAssignableFrom(field.getType())) {
@@ -121,14 +114,14 @@ public class ContainersImpl implements C
}
}
- private URL getResource(Class clazz, String path) {
+ private URL getResource(final Class clazz, final String path) {
final String resourcePath = clazz.getPackage().getName().replace(".",
"/") + "/" + path;
return clazz.getClassLoader().getResource(resourcePath);
}
- public static void main(String[] args) throws IOException {
+ public static void main(final String[] args) throws IOException {
new ContainersImpl().memoryMappedFile();
System.out.println();
@@ -136,20 +129,30 @@ public class ContainersImpl implements C
public void memoryMappedFile() throws IOException {
- FileChannel rwChannel = new RandomAccessFile(new
File("/tmp/memory-mapped.txt"), "rw").getChannel();
+ final FileChannel rwChannel = new RandomAccessFile(new
File("/tmp/memory-mapped.txt"), "rw").getChannel();
final byte[] bytes = "hello world".getBytes();
- ByteBuffer writeonlybuffer =
rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, bytes.length);
+ final ByteBuffer writeonlybuffer =
rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, bytes.length);
writeonlybuffer.put(bytes);
writeonlybuffer.compact();
}
- private File writeToFile2(InputStream archive, String name) throws
IOException {
- final File file = File.createTempFile("deploy", "-" + name);
+ private File writeToFile2(final InputStream archive, final String name)
throws IOException {
+ File file;
+ try {
+ file = File.createTempFile("deploy", "-" + name);
+ } catch (Throwable e) {
+ final File tmp = new File("tmp");
+ if (!tmp.exists() && !tmp.mkdirs()) {
+ throw new IOException("Failed to create local tmp directory: "
+ tmp.getAbsolutePath());
+ }
+
+ file = File.createTempFile("deploy", "-" + name, tmp);
+ }
final FileOutputStream outputStream = new FileOutputStream(file);
- int i = 0;
+ int i;
while ((i = archive.read()) != -1) {
outputStream.write(i);
}
@@ -157,13 +160,22 @@ public class ContainersImpl implements C
return file;
}
- private File writeToFile(InputStream archive, String name) throws
IOException {
- final File file = File.createTempFile("deploy", "-" + name);
+ private File writeToFile(final InputStream archive, final String name)
throws IOException {
+ File file;
+ try {
+ file = File.createTempFile("deploy", "-" + name);
+ } catch (Throwable e) {
+ final File tmp = new File("tmp");
+ if (!tmp.exists() && !tmp.mkdirs()) {
+ throw new IOException("Failed to create local tmp directory: "
+ tmp.getAbsolutePath());
+ }
+ file = File.createTempFile("deploy", "-" + name, tmp);
+ }
file.deleteOnExit();
try {
- Map<String, URL> resources = new HashMap<String, URL>();
+ final Map<String, URL> resources = new HashMap<String, URL>();
final Class<?> clazz =
this.getClass().getClassLoader().loadClass(name.replace(".jar", ""));
@@ -182,7 +194,7 @@ public class ContainersImpl implements C
if (clazz.isAnnotationPresent(ValidationXml.class)) {
String path = clazz.getAnnotation(ValidationXml.class).value();
if (path.contains(".jar")) {
- path = path.substring(path.indexOf( "!" ) + 2);
+ path = path.substring(path.indexOf("!") + 2);
}
final URL resource = getResource(clazz, path);
@@ -194,7 +206,7 @@ public class ContainersImpl implements C
}
if (clazz.isAnnotationPresent(Resource.class)) {
- Resource resourceAnn = clazz.getAnnotation(Resource.class);
+ final Resource resourceAnn =
clazz.getAnnotation(Resource.class);
final URL resource = getResource(clazz, resourceAnn.source());
if (resource != null) {
resources.put(resourceAnn.destination().replaceFirst("WEB-INF/classes/", ""),
resource);
@@ -202,8 +214,8 @@ public class ContainersImpl implements C
}
if (clazz.isAnnotationPresent(Resources.class)) {
- Resources resourcesAnn = clazz.getAnnotation(Resources.class);
- for (Resource resourceAnn : resourcesAnn.value()) {
+ final Resources resourcesAnn =
clazz.getAnnotation(Resources.class);
+ for (final Resource resourceAnn : resourcesAnn.value()) {
final URL resource = getResource(clazz,
resourceAnn.source());
if (resource != null) {
resources.put(resourceAnn.destination().replaceFirst("WEB-INF/classes/", ""),
resource);
@@ -235,9 +247,9 @@ public class ContainersImpl implements C
ZipUtil.copy(src, zout);
}
- for (Map.Entry<String, URL> entry : resources.entrySet()) {
+ for (final Map.Entry<String, URL> entry : resources.entrySet()) {
zout.putNextEntry(new ZipEntry(entry.getKey()));
- InputStream in = IO.read(entry.getValue());
+ final InputStream in = IO.read(entry.getValue());
ZipUtil.copy(in, zout);
in.close();
}
@@ -260,7 +272,7 @@ public class ContainersImpl implements C
return file;
}
- private void writeToFile(File file, ByteArrayOutputStream
byteArrayOutputStream) throws IOException {
+ private void writeToFile(final File file, final ByteArrayOutputStream
byteArrayOutputStream) throws IOException {
final byte[] bytes = byteArrayOutputStream.toByteArray();
final FileOutputStream fileOutputStream = new FileOutputStream(file);
@@ -268,7 +280,7 @@ public class ContainersImpl implements C
fileOutputStream.close();
}
- public static void close(Closeable closeable) throws IOException {
+ public static void close(final Closeable closeable) throws IOException {
if (closeable == null) return;
try {
if (closeable instanceof Flushable) {
@@ -291,7 +303,7 @@ public class ContainersImpl implements C
}
@Override
- public void undeploy(String name) {
+ public void undeploy(final String name) {
if (container != null) {
container.close();
}