use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testFromWebAppContextNonJta.
/**
* Existing data source "orange-web", non-jta managed
* <p/>
* Application contains a web module with root context path as "orange-web"
* <p/>
* Persistence xml like so:
* <p/>
* <persistence-unit name="orange-unit" />
* <p/>
* The orange-unit app should automatically use orange-web data source and create a new non-JtaManaged datasource
*
* @throws Exception
*/
public void testFromWebAppContextNonJta() throws Exception {
final ResourceInfo supplied = addDataSource("orange-web", OrangeDriver.class, "jdbc:orange-web:some:stuff", false);
assertSame(supplied, resources.get(0));
final PersistenceUnit persistenceUnit = new PersistenceUnit("orange-unit");
final ClassLoader cl = this.getClass().getClassLoader();
final AppModule app = new AppModule(cl, "orange-app");
app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
final WebApp webApp = new WebApp();
webApp.setMetadataComplete(true);
app.getWebModules().add(new WebModule(webApp, "orange-web", cl, "war", "orange-web"));
// Create app
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
// Check results
final ResourceInfo generated = resources.get(1);
assertEquals(supplied.id + "Jta", generated.id);
assertEquals(supplied.service, generated.service);
assertEquals(supplied.className, generated.className);
assertEquals(supplied.properties.get("JdbcDriver"), generated.properties.get("JdbcDriver"));
assertEquals(supplied.properties.get("JdbcUrl"), generated.properties.get("JdbcUrl"));
assertEquals("true", generated.properties.get("JtaManaged"));
}
use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class ClusterObserver method deploy.
public void deploy(@Observes final AfterEvent<AssemblerAfterApplicationCreated> app) {
if (!ClUSTER_DEPLOYMENT) {
return;
}
final AppInfo appInfo = app.getEvent().getApp();
send(new DeployMessage(appInfo.path), appInfo);
}
use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class OpenEJBContextConfig method addAddedJAXWsServices.
private void addAddedJAXWsServices() {
final WebAppInfo webAppInfo = info.get();
final AppInfo appInfo = info.app();
if (webAppInfo == null || appInfo == null || "false".equalsIgnoreCase(appInfo.properties.getProperty("openejb.jaxws.add-missing-servlets", "true"))) {
return;
}
try {
// if no jaxws classes are here don't try anything
OpenEJBContextConfig.class.getClassLoader().loadClass("org.apache.openejb.server.webservices.WsServlet");
} catch (final ClassNotFoundException | NoClassDefFoundError e) {
return;
}
for (final ServletInfo servlet : webAppInfo.servlets) {
if (!servlet.mappings.iterator().hasNext()) {
// no need to do anything
continue;
}
for (final ParamValueInfo pv : servlet.initParams) {
if ("openejb-internal".equals(pv.name) && "true".equals(pv.value)) {
if (context.findChild(servlet.servletName) == null) {
final Wrapper wrapper = context.createWrapper();
wrapper.setName(servlet.servletName);
wrapper.setServletClass("org.apache.openejb.server.webservices.WsServlet");
// add servlet to context
context.addChild(wrapper);
context.addServletMappingDecoded(servlet.mappings.iterator().next(), wrapper.getName());
}
break;
}
}
}
}
use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class ClusterObserver method undeploy.
public void undeploy(@Observes final AssemblerBeforeApplicationDestroyed app) {
if (!ClUSTER_DEPLOYMENT) {
return;
}
final AppInfo appInfo = app.getApp();
send(new UndeployMessage(appInfo.path), appInfo);
}
use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class TomcatWebappDeployer method deploy.
@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();
final AppInfo appInfo = fakeInfo(file, host, context);
appInfo.properties.setProperty("tomcat.unpackWar", "false");
try {
// classloader == null -> standalone war
tomcatWebAppBuilder.deployWebApps(appInfo, null);
} catch (final Exception e) {
// tomcat lost the real exception (only in lifecycle exception string) so try to find it back
final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
if (dem != null && dem.hasDeploymentFailed()) {
Throwable lastException = dem.getLastException();
// TODO: fix it, since we dont use this appInfo clean is ignored. Not a big deal while dem stores few exceptions only.
dem.clearLastException(appInfo);
if (TomEERuntimeException.class.isInstance(lastException)) {
lastException = TomEERuntimeException.class.cast(lastException).getCause();
}
throw new OpenEJBRuntimeException(Exception.class.cast(lastException));
}
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;
}
return info.appInfo;
}
Aggregations