use of org.apache.openejb.jee.WebApp in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testFromWebAppIdJta.
/**
* Existing data source "orange-web", jta managed
*
* Application contains a web module with id "orange-id"
*
* Persistence xml like so:
*
* <persistence-unit name="orange-unit" />
*
* The orange-unit app should automatically use orange-id data source and create a new non-JtaManaged datasource
*
* @throws Exception
*/
public void testFromWebAppIdJta() throws Exception {
final ResourceInfo supplied = addDataSource("orange-id", OrangeDriver.class, "jdbc:orange-web:some:stuff", true);
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-id"));
// Create app
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
// Check results
final ResourceInfo generated = resources.get(1);
assertEquals(supplied.id + "NonJta", 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("false", generated.properties.get("JtaManaged"));
}
use of org.apache.openejb.jee.WebApp in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testFromWebAppContextThirdParty.
/**
* Existing data source "orange-web", not controlled by us
*
* Application contains a web module with root context path as "orange-web"
*
* Persistence xml like so:
*
* <persistence-unit name="orange-unit" />
*
* The orange-unit app should automatically use orange-web data source and the non-jta-datasource should be null
*
* @throws Exception
*/
public void testFromWebAppContextThirdParty() throws Exception {
final ResourceInfo supplied = addDataSource("orange-web", OrangeDriver.class, "jdbc:orange-web:some:stuff", null);
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);
final PersistenceUnitInfo unitInfo = appInfo.persistenceUnits.get(0);
// Check results
assertEquals(supplied.id, unitInfo.jtaDataSource);
assertNull(unitInfo.nonJtaDataSource);
}
use of org.apache.openejb.jee.WebApp in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testFromWebAppContextNonJta.
/**
* Existing data source "orange-web", non-jta managed
*
* Application contains a web module with root context path as "orange-web"
*
* Persistence xml like so:
*
* <persistence-unit name="orange-unit" />
*
* 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.jee.WebApp in project tomee by apache.
the class DeploymentLoader method fillEjbJar.
/**
* If the web.xml is metadata-complete and there is no ejb-jar.xml
* then per specification we use the web.xml metadata-complete setting
* to imply the same for EJBs.
*
* @param webModule WebModule
* @param ejbModule EjbModule
*/
private static void fillEjbJar(final WebModule webModule, final EjbModule ejbModule) {
final Object o = webModule.getAltDDs().get("ejb-jar.xml");
if (o != null) {
return;
}
if (ejbModule.getEjbJar() != null) {
return;
}
final EjbJar ejbJar = new EjbJar();
final WebApp webApp = webModule.getWebApp();
ejbJar.setMetadataComplete(webApp.isMetadataComplete());
ejbModule.setEjbJar(ejbJar);
}
use of org.apache.openejb.jee.WebApp in project tomee by apache.
the class DeploymentLoader method addFacesConfigs.
/**
* Finds all faces configuration files and stores them in the WebModule
*
* @param webModule WebModule
* @throws OpenEJBException
*/
private void addFacesConfigs(final WebModule webModule) throws OpenEJBException {
// *************************IMPORTANT*******************************************
// TODO : kmalhi :: Add support to scrape META-INF/faces-config.xml in jar files
// look at section 10.4.2 of the JSF v1.2 spec, bullet 1 for details
final Set<URL> facesConfigLocations = new HashSet<>();
// web.xml contains faces config locations in the context parameter javax.faces.CONFIG_FILES
final File warFile = new File(webModule.getJarLocation());
final WebApp webApp = webModule.getWebApp();
if (webApp != null) {
final String foundContextParam = webApp.contextParamsAsMap().get("javax.faces.CONFIG_FILES");
if (foundContextParam != null) {
// the value is a comma separated list of config files
final String commaDelimitedListOfFiles = foundContextParam.trim();
final String[] configFiles = commaDelimitedListOfFiles.split(",");
// trim any extra spaces in each file
final String[] trimmedConfigFiles = new String[configFiles.length];
for (int i = 0; i < configFiles.length; i++) {
trimmedConfigFiles[i] = configFiles[i].trim();
}
// convert each file to a URL and add it to facesConfigLocations
for (final String location : trimmedConfigFiles) {
if (!location.startsWith("/")) {
LOGGER.error("A faces configuration file should be context relative when specified in web.xml. Please fix the value of context parameter javax.faces.CONFIG_FILES for the file " + location);
}
try {
final File file = new File(warFile, location).getCanonicalFile().getAbsoluteFile();
final URL url = file.toURI().toURL();
facesConfigLocations.add(url);
} catch (final IOException e) {
LOGGER.error("Faces configuration file location bad: " + location, e);
}
}
} else {
LOGGER.debug("faces config file is null");
}
}
// Search for WEB-INF/faces-config.xml
final File webInf = new File(warFile, "WEB-INF");
if (webInf.isDirectory()) {
File facesConfigFile = new File(webInf, "faces-config.xml");
if (facesConfigFile.exists()) {
try {
facesConfigFile = facesConfigFile.getCanonicalFile().getAbsoluteFile();
final URL url = facesConfigFile.toURI().toURL();
facesConfigLocations.add(url);
} catch (final IOException e) {
// TODO: kmalhi:: Remove the printStackTrace after testing
e.printStackTrace();
}
}
}
// flag an error and not allow the application to be deployed.
for (final URL location : facesConfigLocations) {
final FacesConfig facesConfig = ReadDescriptors.readFacesConfig(location);
webModule.getFacesConfigs().add(facesConfig);
if ("file".equals(location.getProtocol())) {
webModule.getWatchedResources().add(URLs.toFilePath(location));
}
}
}
Aggregations