Search in sources :

Example 81 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class OpenEJBContextConfig method cleanUpRestServlets.

private void cleanUpRestServlets() {
    final WebAppInfo webAppInfo = info.get();
    final AppInfo appInfo = info.app();
    if (webAppInfo == null || appInfo == null || "false".equalsIgnoreCase(appInfo.properties.getProperty("openejb.jaxrs.on", "true"))) {
        return;
    }
    final Container[] children = context.findChildren();
    final Map<String, Container> mappedChildren = new HashMap<String, Container>();
    if (children != null) {
        // index potential rest containers by class to cleanup applications defined as servlet
        for (final Container c : children) {
            if (!(c instanceof StandardWrapper)) {
                continue;
            }
            final StandardWrapper wrapper = (StandardWrapper) c;
            final String appSpec = wrapper.getInitParameter("javax.ws.rs.Application");
            if (appSpec != null) {
                mappedChildren.put(appSpec, c);
            } else {
                final String app = wrapper.getInitParameter(Application.class.getName());
                if (app != null) {
                    mappedChildren.put(app, c);
                } else if (wrapper.getServletClass() == null) {
                    try {
                        if (Application.class.isAssignableFrom(context.getLoader().getClassLoader().loadClass(wrapper.getServletName()))) {
                            // remove directly since it is not in restApplications
                            context.removeChild(c);
                        }
                    } catch (final Exception e) {
                    // no-op
                    }
                }
            }
        }
        // cleanup
        for (final String clazz : webAppInfo.restApplications) {
            final Container child = mappedChildren.get(clazz);
            try {
                // remove only "fake" servlets to let users use their own stuff
                if (child != null) {
                    final String servletClass = StandardWrapper.class.cast(child).getServletClass();
                    if (servletClass == null || "org.apache.openejb.server.rest.OpenEJBRestServlet".equals(servletClass) || !HttpServlet.class.isAssignableFrom(info.loader().loadClass(servletClass))) {
                        context.removeChild(child);
                    }
                }
            } catch (final NoClassDefFoundError | ClassNotFoundException e) {
                context.removeChild(child);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ClassFormatException(org.apache.tomcat.util.bcel.classfile.ClassFormatException) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) Container(org.apache.catalina.Container) Application(javax.ws.rs.core.Application) StandardWrapper(org.apache.catalina.core.StandardWrapper)

Example 82 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class HessianService method start.

@Override
public void start() throws ServiceException {
    SystemInstance.get().addObserver(this);
    SystemInstance.get().setComponent(HessianService.class, this);
    registry = setRegistry();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    if (assembler != null) {
        for (final AppInfo appInfo : assembler.getDeployedApplications()) {
            deploy(new AssemblerAfterApplicationCreated(appInfo, SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(appInfo.appId), null));
        }
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) AssemblerAfterApplicationCreated(org.apache.openejb.assembler.classic.event.AssemblerAfterApplicationCreated) Assembler(org.apache.openejb.assembler.classic.Assembler) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 83 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class DeployerEjbTest method testDeployProperties.

@Test
public void testDeployProperties() throws Exception {
    final Properties p = new Properties();
    final String path = warArchive.get().getAbsolutePath();
    p.setProperty(Deployer.FILENAME, path);
    p.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.FALSE.toString());
    final Deployer deployer = getDeployer();
    final AppInfo appInfo = deployer.deploy(p);
    Assert.assertTrue("Paths do not match: " + path + " - " + appInfo.path, path.equals(appInfo.path));
}
Also used : Properties(java.util.Properties) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Test(org.junit.Test)

Example 84 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class AltDDPrefixTest method testPersistenceUnit.

/**
 * OPENEJB-1059: altdd does not work with a persistence.xml when no embedded
 * in EjbModule/Client module.
 *
 * @throws Exception if something wrong happen
 */
public void testPersistenceUnit() throws Exception {
    System.out.println("*** testPersistenceUnit ***");
    final Assembler assmbler = new Assembler();
    SystemInstance.get().setProperty("openejb.altdd.prefix", "footest, test");
    DeploymentLoader.reloadAltDD();
    final ConfigurationFactory factory = new ConfigurationFactory();
    final URL resource = AltDDPrefixTest.class.getClassLoader().getResource("altddPU1");
    final File file = URLs.toFile(resource);
    final AppInfo appInfo = factory.configureApplication(file);
    assertNotNull(appInfo);
    assertEquals(0, appInfo.ejbJars.size());
    assertEquals(1, appInfo.persistenceUnits.size());
    final PersistenceUnitInfo info = appInfo.persistenceUnits.get(0);
    // a space must be present before hashcode
    assertTrue(info.id.startsWith("footest-unit "));
// appInfo = factory.configureApplication(file);
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo) URL(java.net.URL) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 85 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class AltDDPrefixTest method testTestOnlyModule.

/**
 * This module has only a "test.ejb-jar.xml" file and no equivalent
 * non-test ejb-jar.xml file.  It should still get discovered even though
 * there is not an ejb-jar.xml file and only a test.ejb-jar.xml file
 *
 * @throws Exception
 */
public void testTestOnlyModule() throws Exception {
    System.out.println("*** testTestOnlyModule ***");
    final Assembler assmbler = new Assembler();
    SystemInstance.get().setProperty("openejb.altdd.prefix", "test");
    DeploymentLoader.reloadAltDD();
    final ConfigurationFactory factory = new ConfigurationFactory();
    final URL resource = AltDDPrefixTest.class.getClassLoader().getResource("altddapp1");
    final File file = URLs.toFile(resource);
    final AppInfo appInfo = factory.configureApplication(file);
    assertNotNull(appInfo);
    assertEquals(1, appInfo.ejbJars.size());
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) URL(java.net.URL) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Aggregations

AppInfo (org.apache.openejb.assembler.classic.AppInfo)109 File (java.io.File)49 Assembler (org.apache.openejb.assembler.classic.Assembler)49 Test (org.junit.Test)31 HashMap (java.util.HashMap)29 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)25 EjbJar (org.apache.openejb.jee.EjbJar)17 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)16 ContainerSystem (org.apache.openejb.spi.ContainerSystem)15 OpenEJBException (org.apache.openejb.OpenEJBException)14 AppModule (org.apache.openejb.config.AppModule)14 Map (java.util.Map)12 EjbModule (org.apache.openejb.config.EjbModule)11 Properties (java.util.Properties)10 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)10 ArrayList (java.util.ArrayList)9 InitialContext (javax.naming.InitialContext)9 StatelessBean (org.apache.openejb.jee.StatelessBean)9 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)9 IOException (java.io.IOException)8