Search in sources :

Example 26 with OpenEJBException

use of org.apache.openejb.OpenEJBException in project tomee by apache.

the class ConfigurationFactory method configureApplication.

public AppInfo configureApplication(final AppModule appModule) throws OpenEJBException {
    try {
        final Collection<Class<?>> extensions = new HashSet<>();
        final Collection<String> notLoaded = new HashSet<>();
        final List<URL> libs = appModule.getAdditionalLibraries();
        if (libs != null && libs.size() > 0) {
            final Extensions.Finder finder = new Extensions.Finder("META-INF", false, libs.toArray(new URL[libs.size()]));
            extensions.addAll(Extensions.findExtensions(finder));
            notLoaded.addAll(finder.getResourcesNotLoaded());
        }
        for (final EjbModule ejb : appModule.getEjbModules()) {
            try {
                final URI uri = ejb.getModuleUri();
                if (uri.isAbsolute()) {
                    final URL url = uri.toURL();
                    if (libs != null && !libs.contains(url)) {
                        final Extensions.Finder finder = new Extensions.Finder("META-INF", false, url);
                        extensions.addAll(Extensions.findExtensions(finder));
                        notLoaded.addAll(finder.getResourcesNotLoaded());
                    }
                }
            } catch (final IllegalArgumentException | MalformedURLException iae) {
                logger.debug("can't look for server event listener for module " + ejb.getModuleUri(), iae);
            } catch (final Exception e) {
                logger.error("can't look for server event listener for module " + ejb.getJarLocation());
            }
        }
        for (final WebModule web : appModule.getWebModules()) {
            final List<URL> webLibs = web.getScannableUrls();
            if (webLibs != null && webLibs.size() > 0) {
                final Extensions.Finder finder = new Extensions.Finder("META-INF", false, webLibs.toArray(new URL[webLibs.size()]));
                extensions.addAll(Extensions.findExtensions(finder));
                notLoaded.addAll(finder.getResourcesNotLoaded());
            }
        }
        // add it as early as possible, the ones needing the app classloader will be added later
        Extensions.addExtensions(extensions);
        final String location = appModule.getJarLocation();
        logger.info("config.configApp", null != location ? location : appModule.getModuleId());
        deployer.deploy(appModule);
        final AppInfoBuilder appInfoBuilder = new AppInfoBuilder(this);
        final AppInfo info = appInfoBuilder.build(appModule);
        info.eventClassesNeedingAppClassloader.addAll(notLoaded);
        return info;
    } finally {
        destroy(appModule.getEarLibFinder());
        for (final EjbModule ejb : appModule.getEjbModules()) {
            destroy(ejb.getFinder());
        }
        for (final WebModule web : appModule.getWebModules()) {
            destroy(web.getFinder());
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ParentClassLoaderFinder(org.apache.openejb.core.ParentClassLoaderFinder) IAnnotationFinder(org.apache.xbean.finder.IAnnotationFinder) Extensions(org.apache.openejb.Extensions) URI(java.net.URI) URL(java.net.URL) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException) AppInfo(org.apache.openejb.assembler.classic.AppInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) MetaAnnotatedClass(org.apache.xbean.finder.MetaAnnotatedClass) HashSet(java.util.HashSet)

Example 27 with OpenEJBException

use of org.apache.openejb.OpenEJBException in project tomee by apache.

the class ConfigurationFactory method getDefaultService.

private <T extends ServiceInfo> org.apache.openejb.config.Service getDefaultService(final Class<? extends T> type) throws OpenEJBException {
    final DefaultService defaultService = defaultProviders.get(type);
    if (defaultService == null) {
        return null;
    }
    final org.apache.openejb.config.Service service;
    try {
        service = JaxbOpenejb.create(defaultService.type);
        service.setType(defaultService.id);
    } catch (final Exception e) {
        final String name = defaultService.type == null ? "null" : defaultService.type.getName();
        throw new OpenEJBException("Cannot instantiate class " + name, e);
    }
    return service;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException)

Example 28 with OpenEJBException

use of org.apache.openejb.OpenEJBException in project tomee by apache.

the class ConfigurationFactory method configureService.

/**
 * This is the major piece of code that configures services.
 * It merges the data from the <ServiceProvider> declaration
 * with the data from the openejb.xml file (say <Resource>)
 *
 * The end result is a canonical (i.e. flattened) ServiceInfo
 * The ServiceInfo will be of a specific type (ContainerInfo, ResourceInfo, etc)
 *
 * @param service  Service
 * @param infoType Class
 * @param <T>      infoType
 * @return ServiceInfo
 * @throws OpenEJBException On error
 */
public <T extends ServiceInfo> T configureService(org.apache.openejb.config.Service service, final Class<? extends T> infoType) throws OpenEJBException {
    try {
        if (infoType == null) {
            throw new NullPointerException("type");
        }
        if (service == null) {
            service = getDefaultService(infoType);
            if (service == null) {
                throw new OpenEJBException(messages.format("configureService.noDefaultService", infoType.getName()));
            }
        }
        {
            String template = service.getTemplate();
            if (template == null) {
                template = SystemInstance.get().getProperty(Template.class.getName());
            }
            if (template != null) {
                template = unaliasPropertiesProvider(template);
                // don't trim them, user wants to handle it himself, let him do it
                final ObjectRecipe recipe = newObjectRecipe(template);
                recipe.setProperty("serviceId", service.getId());
                // note: we can also use reflection if needed to limit the dependency
                Template.class.cast(recipe.create()).configure(service);
            }
        }
        final ServiceProvider provider = getServiceProvider(service, infoType);
        if (service.getId() == null) {
            service.setId(provider.getId());
        }
        final Properties overrides = trim(getSystemProperties(overrideKey(service), provider.getService()));
        final Properties serviceProperties = service.getProperties();
        trim(serviceProperties);
        trim(provider.getProperties());
        logger.info("configureService.configuring", service.getId(), provider.getService(), provider.getId());
        if (logger.isDebugEnabled()) {
            for (final Map.Entry<Object, Object> entry : serviceProperties.entrySet()) {
                final Object key = entry.getKey();
                Object value = entry.getValue();
                if (key instanceof String && "password".equalsIgnoreCase((String) key)) {
                    value = "<hidden>";
                }
                logger.debug("[" + key + "=" + value + "]");
            }
            for (final Map.Entry<Object, Object> entry : overrides.entrySet()) {
                final Object key = entry.getKey();
                Object value = entry.getValue();
                if (key instanceof String && "password".equalsIgnoreCase((String) key)) {
                    value = "<hidden>";
                }
                logger.debug("Override [" + key + "=" + value + "]");
            }
        }
        final Properties props = new SuperProperties().caseInsensitive(true);
        // weird hack but sometimes we don't want default values when we want null for instance
        if (serviceProperties == null || "false".equals(serviceProperties.getProperty(IGNORE_DEFAULT_VALUES_PROP, "false"))) {
            props.putAll(provider.getProperties());
        }
        if (serviceProperties != null) {
            props.putAll(serviceProperties);
        }
        props.putAll(overrides);
        {
            // force user properties last
            String propertiesProvider = service.getPropertiesProvider();
            if (propertiesProvider == null) {
                propertiesProvider = SystemInstance.get().getProperty(PropertiesResourceProvider.class.getName());
            }
            if (propertiesProvider != null) {
                propertiesProvider = unaliasPropertiesProvider(propertiesProvider);
                // don't trim them, user wants to handle it himself, let him do it
                final ObjectRecipe recipe = newObjectRecipe(propertiesProvider);
                recipe.setFactoryMethod("provides");
                recipe.setProperty("serviceId", service.getId());
                recipe.setProperties(props);
                // let user get all config
                recipe.setProperty("properties", props);
                final Properties p = Properties.class.cast(recipe.create());
                props.putAll(p);
            }
        }
        props.remove(IGNORE_DEFAULT_VALUES_PROP);
        final T info;
        try {
            info = infoType.newInstance();
        } catch (final Exception e) {
            throw new OpenEJBException(messages.format("configureService.cannotInstantiateClass", infoType.getName()), e);
        }
        // some jndi adjustment
        if (service.getId().startsWith("java:/")) {
            service.setId(service.getId().substring("java:/".length()));
        }
        info.service = provider.getService();
        info.types.addAll(provider.getTypes());
        info.description = provider.getDescription();
        info.displayName = provider.getDisplayName();
        info.className = provider.getClassName();
        info.factoryMethod = provider.getFactoryName();
        info.id = service.getId();
        info.properties = props;
        info.constructorArgs.addAll(parseConstructorArgs(provider));
        if (info instanceof ResourceInfo && service instanceof Resource) {
            final ResourceInfo ri = ResourceInfo.class.cast(info);
            final Resource resource = Resource.class.cast(service);
            ri.jndiName = resource.getJndi();
            ri.postConstruct = resource.getPostConstruct();
            ri.preDestroy = resource.getPreDestroy();
            ri.aliases.addAll(resource.getAliases());
            ri.dependsOn.addAll(resource.getDependsOn());
        }
        if (service.getClasspath() != null && service.getClasspath().length() > 0) {
            info.classpath = resolveClasspath(service.getClasspath());
        }
        info.classpathAPI = service.getClasspathAPI();
        specialProcessing(info);
        return info;
    } catch (final NoSuchProviderException e) {
        final String message = logger.fatal("configureService.failed", e, (null != service ? service.getId() : ""));
        throw new OpenEJBException(message + ": " + e.getMessage());
    } catch (final Throwable e) {
        final String message = logger.fatal("configureService.failed", e, (null != service ? service.getId() : ""));
        throw new OpenEJBException(message, e);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) Resource(org.apache.openejb.config.sys.Resource) Properties(java.util.Properties) SuperProperties(org.apache.openejb.util.SuperProperties) SuperProperties(org.apache.openejb.util.SuperProperties) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException) Template(org.apache.openejb.api.resource.Template) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) ServiceProvider(org.apache.openejb.config.sys.ServiceProvider) PropertiesResourceProvider(org.apache.openejb.api.resource.PropertiesResourceProvider) Map(java.util.Map) HashMap(java.util.HashMap)

Example 29 with OpenEJBException

use of org.apache.openejb.OpenEJBException in project tomee by apache.

the class EjbJarInfoBuilder method initSessionBean.

private EnterpriseBeanInfo initSessionBean(final SessionBean s, final EjbJarInfo ejbJar, final Map m) throws OpenEJBException {
    EnterpriseBeanInfo bean;
    if (s.getSessionType() == SessionType.STATEFUL) {
        bean = new StatefulBeanInfo();
        bean.passivable = s.getPassivationCapable() == null || s.getPassivationCapable();
        final StatefulBeanInfo stateful = (StatefulBeanInfo) bean;
        copyCallbacks(s.getPostActivate(), stateful.postActivate);
        copyCallbacks(s.getPrePassivate(), stateful.prePassivate);
        copyCallbacks(s.getAfterBegin(), stateful.afterBegin);
        copyCallbacks(s.getBeforeCompletion(), stateful.beforeCompletion);
        copyCallbacks(s.getAfterCompletion(), stateful.afterCompletion);
        for (final InitMethod initMethod : s.getInitMethod()) {
            final InitMethodInfo init = new InitMethodInfo();
            init.beanMethod = toInfo(initMethod.getBeanMethod());
            init.createMethod = toInfo(initMethod.getCreateMethod());
            stateful.initMethods.add(init);
        }
        for (final RemoveMethod removeMethod : s.getRemoveMethod()) {
            final RemoveMethodInfo remove = new RemoveMethodInfo();
            remove.beanMethod = toInfo(removeMethod.getBeanMethod());
            remove.retainIfException = removeMethod.getRetainIfException();
            stateful.removeMethods.add(remove);
        }
        copyConcurrentMethods(s, ejbJar, m);
    } else if (s.getSessionType() == SessionType.MANAGED) {
        bean = new ManagedBeanInfo();
        final ManagedBeanInfo managed = (ManagedBeanInfo) bean;
        // this way we support managed beans in ejb-jar.xml (not in the spec but can be useful)
        managed.hidden = !(s instanceof ManagedBean) || ((ManagedBean) s).isHidden();
        copyCallbacks(s.getPostActivate(), managed.postActivate);
        copyCallbacks(s.getPrePassivate(), managed.prePassivate);
        for (final RemoveMethod removeMethod : s.getRemoveMethod()) {
            final RemoveMethodInfo remove = new RemoveMethodInfo();
            remove.beanMethod = toInfo(removeMethod.getBeanMethod());
            remove.retainIfException = removeMethod.getRetainIfException();
            managed.removeMethods.add(remove);
        }
    } else if (s.getSessionType() == SessionType.SINGLETON) {
        bean = new SingletonBeanInfo();
        final ConcurrencyManagementType type = s.getConcurrencyManagementType();
        bean.concurrencyType = type != null ? type.toString() : ConcurrencyManagementType.CONTAINER.toString();
        bean.loadOnStartup = s.getInitOnStartup();
        copyCallbacks(s.getAroundTimeout(), bean.aroundTimeout);
        copySchedules(s.getTimer(), bean.methodScheduleInfos);
        // See JndiEncInfoBuilder.buildDependsOnRefs for processing of DependsOn
        // bean.dependsOn.addAll(s.getDependsOn());
        copyConcurrentMethods(s, ejbJar, m);
    } else {
        bean = new StatelessBeanInfo();
        copySchedules(s.getTimer(), bean.methodScheduleInfos);
    }
    if (s.getSessionType() != SessionType.STATEFUL) {
        copyCallbacks(s.getAroundTimeout(), bean.aroundTimeout);
    }
    bean.localbean = s.getLocalBean() != null;
    bean.timeoutMethod = toInfo(s.getTimeoutMethod());
    copyCallbacks(s.getAroundInvoke(), bean.aroundInvoke);
    copyCallbacks(s.getPostConstruct(), bean.postConstruct);
    copyCallbacks(s.getPreDestroy(), bean.preDestroy);
    copyAsynchronous(s.getAsyncMethod(), bean.asynchronous);
    bean.asynchronousClasses.addAll(s.getAsynchronousClasses());
    final EjbDeployment d = (EjbDeployment) m.get(s.getEjbName());
    if (d == null) {
        throw new OpenEJBException("No deployment information in openejb-jar.xml for bean " + s.getEjbName() + ". Please redeploy the jar");
    }
    bean.ejbDeploymentId = d.getDeploymentId();
    bean.containerId = d.getContainerId();
    final Icon icon = s.getIcon();
    bean.largeIcon = icon == null ? null : icon.getLargeIcon();
    bean.smallIcon = icon == null ? null : icon.getSmallIcon();
    bean.description = s.getDescription();
    bean.displayName = s.getDisplayName();
    bean.ejbClass = s.getEjbClass();
    bean.ejbName = s.getEjbName();
    bean.home = s.getHome();
    bean.remote = s.getRemote();
    bean.localHome = s.getLocalHome();
    bean.local = s.getLocal();
    bean.proxy = s.getProxy();
    bean.parents.addAll(s.getParents());
    bean.businessLocal.addAll(s.getBusinessLocal());
    bean.businessRemote.addAll(s.getBusinessRemote());
    final TransactionType txType = s.getTransactionType();
    bean.transactionType = txType != null ? txType.toString() : TransactionType.CONTAINER.toString();
    bean.serviceEndpoint = s.getServiceEndpoint();
    bean.properties.putAll(d.getProperties());
    bean.statefulTimeout = toInfo(s.getStatefulTimeout());
    bean.restService = s.isRestService() && !(s instanceof StatefulBean);
    return bean;
}
Also used : InitMethod(org.apache.openejb.jee.InitMethod) InitMethodInfo(org.apache.openejb.assembler.classic.InitMethodInfo) OpenEJBException(org.apache.openejb.OpenEJBException) TransactionType(org.apache.openejb.jee.TransactionType) ConcurrencyManagementType(org.apache.openejb.jee.ConcurrencyManagementType) StatefulBean(org.apache.openejb.jee.StatefulBean) RemoveMethodInfo(org.apache.openejb.assembler.classic.RemoveMethodInfo) StatelessBeanInfo(org.apache.openejb.assembler.classic.StatelessBeanInfo) ManagedBeanInfo(org.apache.openejb.assembler.classic.ManagedBeanInfo) SingletonBeanInfo(org.apache.openejb.assembler.classic.SingletonBeanInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) StatefulBeanInfo(org.apache.openejb.assembler.classic.StatefulBeanInfo) RemoveMethod(org.apache.openejb.jee.RemoveMethod) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Icon(org.apache.openejb.jee.Icon) ManagedBean(org.apache.openejb.jee.ManagedBean)

Example 30 with OpenEJBException

use of org.apache.openejb.OpenEJBException in project tomee by apache.

the class EjbJarInfoBuilder method initMessageBean.

private EnterpriseBeanInfo initMessageBean(final MessageDrivenBean mdb, final Map m) throws OpenEJBException {
    final MessageDrivenBeanInfo bean = new MessageDrivenBeanInfo();
    bean.timeoutMethod = toInfo(mdb.getTimeoutMethod());
    copyCallbacks(mdb.getAroundTimeout(), bean.aroundTimeout);
    copyCallbacks(mdb.getAroundInvoke(), bean.aroundInvoke);
    copyCallbacks(mdb.getPostConstruct(), bean.postConstruct);
    copyCallbacks(mdb.getPreDestroy(), bean.preDestroy);
    copySchedules(mdb.getTimer(), bean.methodScheduleInfos);
    final EjbDeployment d = (EjbDeployment) m.get(mdb.getEjbName());
    if (d == null) {
        throw new OpenEJBException("No deployment information in openejb-jar.xml for bean " + mdb.getEjbName() + ". Please redeploy the jar");
    }
    bean.ejbDeploymentId = d.getDeploymentId();
    bean.containerId = d.getContainerId();
    final Icon icon = mdb.getIcon();
    bean.largeIcon = icon == null ? null : icon.getLargeIcon();
    bean.smallIcon = icon == null ? null : icon.getSmallIcon();
    bean.description = mdb.getDescription();
    bean.displayName = mdb.getDisplayName();
    bean.ejbClass = mdb.getEjbClass();
    bean.ejbName = mdb.getEjbName();
    final TransactionType txType = mdb.getTransactionType();
    bean.transactionType = txType != null ? txType.toString() : TransactionType.CONTAINER.toString();
    bean.properties.putAll(d.getProperties());
    if (mdb.getMessagingType() != null) {
        bean.mdbInterface = mdb.getMessagingType();
    } else {
        bean.mdbInterface = "javax.jms.MessageListener";
    }
    final ResourceLink resourceLink = d.getResourceLink("openejb/destination");
    if (resourceLink != null) {
        bean.destinationId = resourceLink.getResId();
    }
    if (mdb.getMessageDestinationType() != null) {
        bean.activationProperties.put("destinationType", mdb.getMessageDestinationType());
    }
    final ActivationConfig activationConfig = mdb.getActivationConfig();
    if (activationConfig != null) {
        for (final ActivationConfigProperty property : activationConfig.getActivationConfigProperty()) {
            final String name = property.getActivationConfigPropertyName();
            final String value = property.getActivationConfigPropertyValue();
            bean.activationProperties.put(name, value);
        }
    }
    return bean;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) TransactionType(org.apache.openejb.jee.TransactionType) ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink) MessageDrivenBeanInfo(org.apache.openejb.assembler.classic.MessageDrivenBeanInfo) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Icon(org.apache.openejb.jee.Icon) ActivationConfig(org.apache.openejb.jee.ActivationConfig)

Aggregations

OpenEJBException (org.apache.openejb.OpenEJBException)192 IOException (java.io.IOException)54 NamingException (javax.naming.NamingException)35 URL (java.net.URL)31 MalformedURLException (java.net.MalformedURLException)30 BeanContext (org.apache.openejb.BeanContext)30 ApplicationException (org.apache.openejb.ApplicationException)29 ArrayList (java.util.ArrayList)28 File (java.io.File)27 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)24 Method (java.lang.reflect.Method)22 SystemException (org.apache.openejb.SystemException)22 HashMap (java.util.HashMap)18 ThreadContext (org.apache.openejb.core.ThreadContext)18 RemoteException (java.rmi.RemoteException)14 EJBException (javax.ejb.EJBException)14 EjbTransactionUtil.handleApplicationException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException)14 HashSet (java.util.HashSet)13 Properties (java.util.Properties)13 EJBAccessException (javax.ejb.EJBAccessException)13