Search in sources :

Example 6 with WebApp

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"));
}
Also used : Persistence(org.apache.openejb.jee.jpa.unit.Persistence) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) WebApp(org.apache.openejb.jee.WebApp) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 7 with WebApp

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);
}
Also used : Persistence(org.apache.openejb.jee.jpa.unit.Persistence) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo) WebApp(org.apache.openejb.jee.WebApp) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 8 with WebApp

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"));
}
Also used : Persistence(org.apache.openejb.jee.jpa.unit.Persistence) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) WebApp(org.apache.openejb.jee.WebApp) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 9 with WebApp

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);
}
Also used : EjbJar(org.apache.openejb.jee.EjbJar) WebApp(org.apache.openejb.jee.WebApp)

Example 10 with WebApp

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));
        }
    }
}
Also used : FacesConfig(org.apache.openejb.jee.FacesConfig) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) WebApp(org.apache.openejb.jee.WebApp)

Aggregations

WebApp (org.apache.openejb.jee.WebApp)26 AppInfo (org.apache.openejb.assembler.classic.AppInfo)8 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)7 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)7 File (java.io.File)6 IOException (java.io.IOException)6 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)6 URL (java.net.URL)5 WebModule (org.apache.openejb.config.WebModule)5 MalformedURLException (java.net.MalformedURLException)4 LinkedHashSet (java.util.LinkedHashSet)4 JarFile (java.util.jar.JarFile)4 EnvEntry (org.apache.openejb.jee.EnvEntry)4 HashSet (java.util.HashSet)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)3 EjbJar (org.apache.openejb.jee.EjbJar)3 Classes (org.apache.openejb.testing.Classes)3 Module (org.apache.openejb.testing.Module)3 InputStream (java.io.InputStream)2