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.container.deploy(appId, ((File) modules), true);
} else if (modules instanceof String) {
tomEEContainer.container.deploy(appId, new File((String) modules), true);
} else if (modules instanceof String[]) {
for (String path : (String[]) modules) {
tomEEContainer.container.deploy(appId, new File(path), true);
}
} else if (modules instanceof File[]) {
for (File file : (File[]) modules) {
tomEEContainer.container.deploy(appId, file, true);
}
} else {
try {
tomEEContainer.close();
} catch (Exception e) {
// no-op
}
tomEEContainer = null;
throw Exceptions.newNoModulesFoundException();
}
return tomEEContainer;
} catch (OpenEJBException e) {
throw new EJBException(e);
} catch (MalformedURLException e) {
throw new EJBException(e);
} catch (ValidationException ve) {
throw ve;
} catch (Exception e) {
if (e instanceof EJBException) {
throw (EJBException) e;
}
throw new TomEERuntimeException("initialization exception", e);
} finally {
if (tomEEContainer == null) {
try {
tomEEContainer.close();
} catch (Exception e) {