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()));
etc.container.setup(configuration);
try {
etc.container.start();
if (modules instanceof File) {
etc.deployedIds.add(etc.container.deploy(appId, ((File) modules), appId != null).getId());
} else if (modules instanceof String) {
etc.deployedIds.add(etc.container.deploy(appId, new File((String) modules), appId != null).getId());
} else if (modules instanceof String[]) {
for (final String path : (String[]) modules) {
etc.deployedIds.add(etc.container.deploy(appId, new File(path), appId != null).getId());
}
} else if (modules instanceof File[]) {
for (final File file : (File[]) modules) {
etc.deployedIds.add(etc.container.deploy(appId, file, appId != null).getId());
}
} else {
SystemInstance.get().getProperties().putAll(properties);
final Collection<File> files = etc.container.getConfigurationFactory().getModulesFromClassPath(null, Thread.currentThread().getContextClassLoader());
if (files.size() == 0) {
try {
etc.close();
} catch (final Exception e) {
// no-op
}
tomEEContainer.set(null);
throw Exceptions.newNoModulesFoundException();
}
for (final File file : files) {
etc.deployedIds.add(etc.container.deploy(appId, file, appId != null).getId());
}
}
return etc;
} catch (final OpenEJBException | MalformedURLException e) {
try {
etc.close();
} catch (final Exception e1) {
//Ignore
}
throw new EJBException(e);
} catch (final ValidationException ve) {
try {
etc.close();
} catch (final Exception e1) {
//Ignore
}
throw ve;
} catch (final Exception e) {
try {
etc.close();
} catch (final Exception e1) {
//Ignore
}
if (e instanceof EJBException) {
throw (EJBException) e;
}
throw new TomEERuntimeException("initialization exception", e);
}
}