public class TomcatWebappDeployer implements WebAppDeployer {
private static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB, TomcatWebappDeployer.class);
@Override
public AppInfo deploy(final String host, final String context, final File file) {
final TomcatWebAppBuilder tomcatWebAppBuilder = (TomcatWebAppBuilder) SystemInstance.get().getComponent(WebAppBuilder.class);
final Collection<String> alreadyDeployed = tomcatWebAppBuilder.availableApps();
try {
tomcatWebAppBuilder.deployWebApps(fakeInfo(file, host, context), null); // classloader == null -> standalone war
} catch (final Exception e) {
throw new OpenEJBRuntimeException(e);
}
TomcatWebAppBuilder.ContextInfo info = contextInfo(file);
if (info == null) { // try another time doing a diff with apps before deployment and apps after
final Collection<String> deployedNow = tomcatWebAppBuilder.availableApps();
final Iterator<String> it = deployedNow.iterator();
while (it.hasNext()) {
if (alreadyDeployed.contains(it.next())) {
it.remove();
}
}
if (deployedNow.size() == 1) {
info = contextInfo(new File(deployedNow.iterator().next()));
}
}
if (info == null || info.appInfo == null) {
LOGGER.error("Can't find of appInfo for " + (file != null ? file.getAbsolutePath() : null) + ", availables: " + tomcatWebAppBuilder.availableApps());
}
if (info == null) { // error
return null;
}