Search in sources :

Example 11 with SessionBean$JAXB.readSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.

the class CheckRestMethodArePublic method validate.

@Override
public void validate(final AppModule appModule) {
    // valid standalone classes
    final Collection<String> standAloneClasses = new ArrayList<String>();
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    try {
        for (final EjbModule ejb : appModule.getEjbModules()) {
            Thread.currentThread().setContextClassLoader(ejb.getClassLoader());
            for (final EnterpriseBean bean : ejb.getEjbJar().getEnterpriseBeans()) {
                if (bean instanceof SessionBean && ((SessionBean) bean).isRestService()) {
                    standAloneClasses.add(bean.getEjbClass());
                    valid(ejb.getValidation(), ejb.getClassLoader(), bean.getEjbClass());
                }
            }
        }
        for (final WebModule web : appModule.getWebModules()) {
            Thread.currentThread().setContextClassLoader(web.getClassLoader());
            // build the list of classes to validate
            final Collection<String> classes = new ArrayList<String>();
            classes.addAll(web.getRestClasses());
            classes.addAll(web.getEjbRestServices());
            for (final String app : web.getRestApplications()) {
                final Class<?> clazz;
                try {
                    clazz = web.getClassLoader().loadClass(app);
                } catch (final ClassNotFoundException e) {
                    // managed elsewhere, here we just check methods
                    continue;
                }
                final Application appInstance;
                try {
                    appInstance = (Application) clazz.newInstance();
                } catch (final Exception e) {
                    // managed elsewhere
                    continue;
                }
                try {
                    for (final Class<?> rsClass : appInstance.getClasses()) {
                        classes.add(rsClass.getName());
                    }
                /* don't do it or ensure you have cdi activated! + CXF will catch it later
                        for (final Object rsSingleton : appInstance.getSingletons()) {
                            classes.add(rsSingleton.getClass().getName());
                        }
                        */
                } catch (final RuntimeException npe) {
                    if (appInstance == null) {
                        throw npe;
                    }
                // if app relies on cdi it is null here
                }
            }
            // try to avoid to valid twice the same classes
            final Iterator<String> it = classes.iterator();
            while (it.hasNext()) {
                final String current = it.next();
                if (standAloneClasses.contains(current)) {
                    it.remove();
                }
            }
            // valid
            for (final String classname : classes) {
                valid(web.getValidation(), web.getClassLoader(), classname);
            }
            classes.clear();
        }
    } finally {
        Thread.currentThread().setContextClassLoader(loader);
    }
    standAloneClasses.clear();
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) ArrayList(java.util.ArrayList) EjbModule(org.apache.openejb.config.EjbModule) WebModule(org.apache.openejb.config.WebModule) SessionBean(org.apache.openejb.jee.SessionBean) Application(javax.ws.rs.core.Application)

Example 12 with SessionBean$JAXB.readSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.

the class AnnotationDeployerTest method testLocalBean.

/**
 * For https://issues.apache.org/jira/browse/OPENEJB-1188
 *
 * @throws Exception
 */
@Test
public void testLocalBean() throws Exception {
    final EjbModule ejbModule = testModule();
    final EjbJar ejbJar = ejbModule.getEjbJar();
    AppModule appModule = new AppModule(Thread.currentThread().getContextClassLoader(), "myapp");
    appModule.getEjbModules().add(ejbModule);
    final AnnotationDeployer annotationDeployer = new AnnotationDeployer();
    appModule = annotationDeployer.deploy(appModule);
    EnterpriseBean bean = ejbJar.getEnterpriseBean("TestLocalBean");
    assert bean != null;
    assert (((SessionBean) bean).getLocalBean() != null);
    bean = ejbJar.getEnterpriseBean("InterceptedSLSBean");
    assert bean != null;
    assert (((SessionBean) bean).getLocalBean() == null);
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) SessionBean(org.apache.openejb.jee.SessionBean) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Example 13 with SessionBean$JAXB.readSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.

the class EjbJar$JAXB method _write.

public static final void _write(final XoXMLStreamWriter writer, final EjbJar ejbJar, RuntimeContext context) throws Exception {
    if (ejbJar == null) {
        writer.writeXsiNil();
        return;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
    if (EjbJar.class != ejbJar.getClass()) {
        context.unexpectedSubclass(writer, ejbJar, EjbJar.class);
        return;
    }
    context.beforeMarshal(ejbJar, LifecycleCallback.NONE);
    // ATTRIBUTE: id
    final String idRaw = ejbJar.id;
    if (idRaw != null) {
        String id = null;
        try {
            id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
        } catch (final Exception e) {
            context.xmlAdapterError(ejbJar, "id", CollapsedStringAdapter.class, String.class, String.class, e);
        }
        writer.writeAttribute("", "", "id", id);
    }
    // ATTRIBUTE: metadataComplete
    final Boolean metadataComplete = ejbJar.metadataComplete;
    if (metadataComplete != null) {
        writer.writeAttribute("", "", "metadata-complete", Boolean.toString(metadataComplete));
    }
    // ATTRIBUTE: version
    final String versionRaw = ejbJar.version;
    if (versionRaw != null) {
        String version = null;
        try {
            version = Adapters.collapsedStringAdapterAdapter.marshal(versionRaw);
        } catch (final Exception e) {
            context.xmlAdapterError(ejbJar, "version", CollapsedStringAdapter.class, String.class, String.class, e);
        }
        writer.writeAttribute("", "", "version", version);
    }
    // ELEMENT: moduleName
    final String moduleNameRaw = ejbJar.moduleName;
    String moduleName = null;
    try {
        moduleName = Adapters.collapsedStringAdapterAdapter.marshal(moduleNameRaw);
    } catch (final Exception e) {
        context.xmlAdapterError(ejbJar, "moduleName", CollapsedStringAdapter.class, String.class, String.class, e);
    }
    if (moduleName != null) {
        writer.writeStartElement(prefix, "module-name", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters(moduleName);
        writer.writeEndElement();
    }
    // ELEMENT: descriptions
    Text[] descriptions = null;
    try {
        descriptions = ejbJar.getDescriptions();
    } catch (final Exception e) {
        context.getterError(ejbJar, "descriptions", EjbJar.class, "getDescriptions", e);
    }
    if (descriptions != null) {
        for (final Text descriptionsItem : descriptions) {
            if (descriptionsItem != null) {
                writer.writeStartElement(prefix, "description", "http://java.sun.com/xml/ns/javaee");
                writeText(writer, descriptionsItem, context);
                writer.writeEndElement();
            } else {
                context.unexpectedNullValue(ejbJar, "descriptions");
            }
        }
    }
    // ELEMENT: displayNames
    Text[] displayNames = null;
    try {
        displayNames = ejbJar.getDisplayNames();
    } catch (final Exception e) {
        context.getterError(ejbJar, "displayNames", EjbJar.class, "getDisplayNames", e);
    }
    if (displayNames != null) {
        for (final Text displayNamesItem : displayNames) {
            if (displayNamesItem != null) {
                writer.writeStartElement(prefix, "display-name", "http://java.sun.com/xml/ns/javaee");
                writeText(writer, displayNamesItem, context);
                writer.writeEndElement();
            } else {
                context.unexpectedNullValue(ejbJar, "displayNames");
            }
        }
    }
    // ELEMENT: icon
    final LocalCollection<Icon> icon = ejbJar.icon;
    if (icon != null) {
        for (final Icon iconItem : icon) {
            if (iconItem != null) {
                writer.writeStartElement(prefix, "icon", "http://java.sun.com/xml/ns/javaee");
                writeIcon(writer, iconItem, context);
                writer.writeEndElement();
            } else {
                context.unexpectedNullValue(ejbJar, "icon");
            }
        }
    }
    // ELEMENT: enterpriseBeans
    EnterpriseBean[] enterpriseBeans = null;
    try {
        enterpriseBeans = ejbJar.getEnterpriseBeans();
    } catch (final Exception e) {
        context.getterError(ejbJar, "enterpriseBeans", EjbJar.class, "getEnterpriseBeans", e);
    }
    writer.writeStartElement(prefix, "enterprise-beans", "http://java.sun.com/xml/ns/javaee");
    if (enterpriseBeans != null) {
        for (final EnterpriseBean enterpriseBeansItem : enterpriseBeans) {
            if (enterpriseBeansItem instanceof org.apache.openejb.jee.EntityBean) {
                final org.apache.openejb.jee.EntityBean EntityBean = ((org.apache.openejb.jee.EntityBean) enterpriseBeansItem);
                writer.writeStartElement(prefix, "entity", "http://java.sun.com/xml/ns/javaee");
                writeEntityBean(writer, EntityBean, context);
                writer.writeEndElement();
            } else if (enterpriseBeansItem instanceof org.apache.openejb.jee.SessionBean) {
                final org.apache.openejb.jee.SessionBean SessionBean = ((org.apache.openejb.jee.SessionBean) enterpriseBeansItem);
                writer.writeStartElement(prefix, "session", "http://java.sun.com/xml/ns/javaee");
                writeSessionBean(writer, SessionBean, context);
                writer.writeEndElement();
            } else if (enterpriseBeansItem instanceof org.apache.openejb.jee.MessageDrivenBean) {
                final org.apache.openejb.jee.MessageDrivenBean MessageDrivenBean = ((org.apache.openejb.jee.MessageDrivenBean) enterpriseBeansItem);
                writer.writeStartElement(prefix, "message-driven", "http://java.sun.com/xml/ns/javaee");
                writeMessageDrivenBean(writer, MessageDrivenBean, context);
                writer.writeEndElement();
            } else if (enterpriseBeansItem == null) {
                context.unexpectedNullValue(ejbJar, "enterpriseBeans");
            } else {
                context.unexpectedElementType(writer, ejbJar, "enterpriseBeans", enterpriseBeansItem, org.apache.openejb.jee.EntityBean.class, org.apache.openejb.jee.SessionBean.class, org.apache.openejb.jee.MessageDrivenBean.class);
            }
        }
    }
    writer.writeEndElement();
    // ELEMENT: interceptors
    final Interceptors interceptors = ejbJar.interceptors;
    if (interceptors != null) {
        writer.writeStartElement(prefix, "interceptors", "http://java.sun.com/xml/ns/javaee");
        writeInterceptors(writer, interceptors, context);
        writer.writeEndElement();
    }
    // ELEMENT: relationships
    final Relationships relationships = ejbJar.relationships;
    if (relationships != null) {
        writer.writeStartElement(prefix, "relationships", "http://java.sun.com/xml/ns/javaee");
        writeRelationships(writer, relationships, context);
        writer.writeEndElement();
    }
    // ELEMENT: assemblyDescriptor
    final AssemblyDescriptor assemblyDescriptor = ejbJar.assemblyDescriptor;
    if (assemblyDescriptor != null) {
        writer.writeStartElement(prefix, "assembly-descriptor", "http://java.sun.com/xml/ns/javaee");
        writeAssemblyDescriptor(writer, assemblyDescriptor, context);
        writer.writeEndElement();
    }
    // ELEMENT: ejbClientJar
    final String ejbClientJarRaw = ejbJar.ejbClientJar;
    String ejbClientJar = null;
    try {
        ejbClientJar = Adapters.collapsedStringAdapterAdapter.marshal(ejbClientJarRaw);
    } catch (final Exception e) {
        context.xmlAdapterError(ejbJar, "ejbClientJar", CollapsedStringAdapter.class, String.class, String.class, e);
    }
    if (ejbClientJar != null) {
        writer.writeStartElement(prefix, "ejb-client-jar", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters(ejbClientJar);
        writer.writeEndElement();
    }
    context.afterMarshal(ejbJar, LifecycleCallback.NONE);
}
Also used : SessionBean$JAXB.writeSessionBean(org.apache.openejb.jee.SessionBean$JAXB.writeSessionBean) SessionBean$JAXB.readSessionBean(org.apache.openejb.jee.SessionBean$JAXB.readSessionBean) Relationships$JAXB.readRelationships(org.apache.openejb.jee.Relationships$JAXB.readRelationships) Relationships$JAXB.writeRelationships(org.apache.openejb.jee.Relationships$JAXB.writeRelationships) MessageDrivenBean$JAXB.writeMessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean$JAXB.writeMessageDrivenBean) MessageDrivenBean$JAXB.readMessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean) AssemblyDescriptor$JAXB.writeAssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor$JAXB.writeAssemblyDescriptor) AssemblyDescriptor$JAXB.readAssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor$JAXB.readAssemblyDescriptor) CollapsedStringAdapter(javax.xml.bind.annotation.adapters.CollapsedStringAdapter) Text$JAXB.readText(org.apache.openejb.jee.Text$JAXB.readText) Text$JAXB.writeText(org.apache.openejb.jee.Text$JAXB.writeText) Interceptors$JAXB.readInterceptors(org.apache.openejb.jee.Interceptors$JAXB.readInterceptors) Interceptors$JAXB.writeInterceptors(org.apache.openejb.jee.Interceptors$JAXB.writeInterceptors) EntityBean$JAXB.writeEntityBean(org.apache.openejb.jee.EntityBean$JAXB.writeEntityBean) EntityBean$JAXB.readEntityBean(org.apache.openejb.jee.EntityBean$JAXB.readEntityBean) Icon$JAXB.readIcon(org.apache.openejb.jee.Icon$JAXB.readIcon) Icon$JAXB.writeIcon(org.apache.openejb.jee.Icon$JAXB.writeIcon) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext)

Example 14 with SessionBean$JAXB.readSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.

the class MappedNameBuilderTest method testIgnoreMappedNameIfOpenejbJarModuleDoesntExist.

public void testIgnoreMappedNameIfOpenejbJarModuleDoesntExist() throws Exception {
    AppModule appModule = new AppModule(new FakeClassLoader(), "");
    final EjbJar ejbJar = new EjbJar();
    final SessionBean sessionBean = new SessionBean("SessionBean", "org.superbiz.SessionBean", SessionType.STATELESS);
    sessionBean.setMappedName("MappedName");
    ejbJar.addEnterpriseBean(sessionBean);
    appModule.getEjbModules().add(new EjbModule(ejbJar, null));
    appModule = new MappedNameBuilder().deploy(appModule);
    final OpenejbJar openejbJar = appModule.getEjbModules().get(0).getOpenejbJar();
    assertNull(openejbJar);
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) SessionBean(org.apache.openejb.jee.SessionBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 15 with SessionBean$JAXB.readSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.

the class MappedNameBuilderTest method testShouldIgnoreMappedNameIfDeploymentDoesntExist.

public void testShouldIgnoreMappedNameIfDeploymentDoesntExist() throws Exception {
    AppModule appModule = new AppModule(new FakeClassLoader(), "");
    final EjbJar ejbJar = new EjbJar();
    final OpenejbJar openejbJar = new OpenejbJar();
    final SessionBean sessionBean = new SessionBean("SessionBean", "org.superbiz.SessionBean", SessionType.STATELESS);
    sessionBean.setMappedName("MappedName");
    ejbJar.addEnterpriseBean(sessionBean);
    appModule.getEjbModules().add(new EjbModule(ejbJar, openejbJar));
    appModule = new MappedNameBuilder().deploy(appModule);
    final EjbDeployment deployment = appModule.getEjbModules().get(0).getOpenejbJar().getDeploymentsByEjbName().get("SessionBean");
    assertNull(deployment);
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) SessionBean(org.apache.openejb.jee.SessionBean) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

SessionBean (org.apache.openejb.jee.SessionBean)22 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)12 EjbJar (org.apache.openejb.jee.EjbJar)10 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)8 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)7 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)4 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 PortInfo (org.apache.openejb.assembler.classic.PortInfo)3 EjbModule (org.apache.openejb.config.EjbModule)3 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2 Beans (org.apache.openejb.jee.Beans)2 EntityBean (org.apache.openejb.jee.EntityBean)2 Interceptor (org.apache.openejb.jee.Interceptor)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1