if (portValue instanceof Integer) {
port = (Integer) portValue;
} else if (portValue instanceof String) {
port = Integer.parseInt((String) portValue);
} else {
throw new TomEERuntimeException("port value should be an integer or a string");
}
if (port <= 0) {
port = NetworkUtil.getNextAvailablePort();
}
configuration.setHttpPort(port);
}
System.setProperty(TOMEE_EJBCONTAINER_HTTP_PORT, Integer.toString(configuration.getHttpPort()));
tomEEContainer.container.setup(configuration);
try {
tomEEContainer.container.start();
if (modules instanceof File) {
tomEEContainer.deployedIds.add(tomEEContainer.container.deploy(appId, ((File) modules), appId != null).getId());
} else if (modules instanceof String) {
tomEEContainer.deployedIds.add(tomEEContainer.container.deploy(appId, new File((String) modules), appId != null).getId());
} else if (modules instanceof String[]) {
for (final String path : (String[]) modules) {
tomEEContainer.deployedIds.add(tomEEContainer.container.deploy(appId, new File(path), appId != null).getId());
}
} else if (modules instanceof File[]) {
for (final File file : (File[]) modules) {
tomEEContainer.deployedIds.add(tomEEContainer.container.deploy(appId, file, appId != null).getId());
}
} else {
SystemInstance.get().getProperties().putAll(properties);
final Collection<File> files = tomEEContainer.container.getConfigurationFactory().getModulesFromClassPath(null, Thread.currentThread().getContextClassLoader());
if (files.size() == 0) {
try {
tomEEContainer.close();
} catch (final Exception e) {
// no-op
}
tomEEContainer = null;
throw Exceptions.newNoModulesFoundException();
}
for (final File file : files) {
tomEEContainer.deployedIds.add(tomEEContainer.container.deploy(appId, file, appId != null).getId());
}
}
return tomEEContainer;
} catch (final OpenEJBException e) {
tomEEContainer.close();
throw new EJBException(e);
} catch (final MalformedURLException e) {
tomEEContainer.close();
throw new EJBException(e);
} catch (final ValidationException ve) {
if (tomEEContainer != null) {
tomEEContainer.close();
}
throw ve;
} catch (final Exception e) {
if (tomEEContainer != null) {
tomEEContainer.close();
}
if (e instanceof EJBException) {
throw (EJBException) e;
}
throw new TomEERuntimeException("initialization exception", e);
}
}