Search in sources :

Example 41 with OpenEJBException

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

the class SystemAppInfo method preComputedInfo.

// 
// 
// DONT MODIFY IT WITHOUT UPDATING org.apache.openejb.config.SystemApps
// 
// 
public static AppInfo preComputedInfo(final ConfigurationFactory factory) {
    final String singletonContainerId;
    try {
        singletonContainerId = findSingletonContainer(factory);
    } catch (final OpenEJBException e) {
        throw new IllegalStateException(e);
    }
    final EjbJarInfo ejbJarInfo = new EjbJarInfo();
    ejbJarInfo.moduleId = "openejb";
    ejbJarInfo.moduleName = ejbJarInfo.moduleId;
    ejbJarInfo.moduleUri = URI.create(ejbJarInfo.moduleId);
    ejbJarInfo.properties.setProperty("openejb.deploymentId.format", "{ejbName}");
    ejbJarInfo.properties.setProperty("openejb.jndiname.format", "{deploymentId}{interfaceType.openejbLegacyName}");
    final SingletonBeanInfo deployer = new SingletonBeanInfo();
    deployer.ejbDeploymentId = "openejb/Deployer";
    deployer.ejbName = deployer.ejbDeploymentId;
    deployer.ejbClass = "org.apache.openejb.assembler.DeployerEjb";
    deployer.businessRemote.add("org.apache.openejb.assembler.Deployer");
    deployer.parents.add(deployer.ejbClass);
    deployer.transactionType = "BEAN";
    deployer.concurrencyType = "CONTAINER";
    deployer.containerId = singletonContainerId;
    ejbJarInfo.enterpriseBeans.add(deployer);
    final SingletonBeanInfo configuration = new SingletonBeanInfo();
    configuration.ejbDeploymentId = "openejb/ConfigurationInfo";
    configuration.ejbName = deployer.ejbDeploymentId;
    configuration.ejbClass = "org.apache.openejb.assembler.classic.cmd.ConfigurationInfoEjb";
    configuration.businessRemote.add("org.apache.openejb.assembler.classic.cmd.ConfigurationInfo");
    configuration.parents.add(deployer.ejbClass);
    configuration.transactionType = "CONTAINER";
    configuration.concurrencyType = "CONTAINER";
    configuration.containerId = singletonContainerId;
    ejbJarInfo.enterpriseBeans.add(configuration);
    final SingletonBeanInfo mejb = new SingletonBeanInfo();
    mejb.ejbDeploymentId = "MEJB";
    mejb.ejbName = deployer.ejbDeploymentId;
    mejb.ejbClass = "org.apache.openejb.mgmt.MEJBBean";
    mejb.home = "javax.management.j2ee.ManagementHome";
    mejb.remote = "javax.management.j2ee.Management";
    mejb.parents.add(deployer.ejbClass);
    mejb.transactionType = "CONTAINER";
    mejb.concurrencyType = "CONTAINER";
    mejb.containerId = singletonContainerId;
    ejbJarInfo.enterpriseBeans.add(mejb);
    for (final EnterpriseBeanInfo ebi : ejbJarInfo.enterpriseBeans) {
        final MethodInfo methodInfo = new MethodInfo();
        methodInfo.ejbDeploymentId = ebi.ejbDeploymentId;
        methodInfo.ejbName = ebi.ejbName;
        methodInfo.methodName = "*";
        methodInfo.className = ebi.ejbClass;
        final MethodConcurrencyInfo methodConcurrencyInfo = new MethodConcurrencyInfo();
        methodConcurrencyInfo.concurrencyAttribute = "READ";
        methodConcurrencyInfo.methods.add(methodInfo);
        ejbJarInfo.methodConcurrency.add(methodConcurrencyInfo);
    }
    final CallbackInfo callbackInfo = new CallbackInfo();
    callbackInfo.className = "org.apache.openejb.security.internal.InternalSecurityInterceptor";
    callbackInfo.method = "invoke";
    final InterceptorInfo interceptorInfo = new InterceptorInfo();
    interceptorInfo.clazz = "org.apache.openejb.security.internal.InternalSecurityInterceptor";
    interceptorInfo.aroundInvoke.add(callbackInfo);
    ejbJarInfo.interceptors.add(interceptorInfo);
    final InterceptorBindingInfo interceptorBindingInfo = new InterceptorBindingInfo();
    interceptorBindingInfo.ejbName = "*";
    interceptorBindingInfo.interceptors.add("org.apache.openejb.security.internal.InternalSecurityInterceptor");
    ejbJarInfo.interceptorBindings.add(interceptorBindingInfo);
    ejbJarInfo.mbeans.add("org.apache.openejb.assembler.monitoring.JMXDeployer");
    // we start at 1 so no conflict using 0
    ejbJarInfo.uniqueId = "0";
    final AppInfo appInfo = new AppInfo();
    appInfo.appId = ejbJarInfo.moduleId;
    appInfo.path = appInfo.appId;
    appInfo.ejbJars.add(ejbJarInfo);
    return appInfo;
}
Also used : EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) OpenEJBException(org.apache.openejb.OpenEJBException) CallbackInfo(org.apache.openejb.assembler.classic.CallbackInfo) InterceptorBindingInfo(org.apache.openejb.assembler.classic.InterceptorBindingInfo) InterceptorInfo(org.apache.openejb.assembler.classic.InterceptorInfo) MethodInfo(org.apache.openejb.assembler.classic.MethodInfo) SingletonBeanInfo(org.apache.openejb.assembler.classic.SingletonBeanInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) MethodConcurrencyInfo(org.apache.openejb.assembler.classic.MethodConcurrencyInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 42 with OpenEJBException

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

the class WsDeployer method getHandlerChains.

public static HandlerChains getHandlerChains(Class<?> declaringClass, final String serviceEndpoint, final ClassLoader classLoader) throws OpenEJBException {
    HandlerChain handlerChain = declaringClass.getAnnotation(HandlerChain.class);
    if (handlerChain == null && serviceEndpoint != null) {
        try {
            declaringClass = classLoader.loadClass(serviceEndpoint);
            handlerChain = declaringClass.getAnnotation(HandlerChain.class);
        } catch (final ClassNotFoundException ignored) {
        // no-op
        }
    }
    HandlerChains handlerChains = null;
    if (handlerChain != null) {
        try {
            final URL handlerFileURL = declaringClass.getResource(handlerChain.file());
            handlerChains = ReadDescriptors.readHandlerChains(handlerFileURL);
        } catch (final Throwable e) {
            throw new OpenEJBException("Unable to load handler chain file: " + handlerChain.file(), e);
        }
    }
    return handlerChains;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) HandlerChain(javax.jws.HandlerChain) HandlerChains(org.apache.openejb.jee.HandlerChains) URL(java.net.URL)

Example 43 with OpenEJBException

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

the class WsDeployer method processPorts.

private void processPorts(final EjbModule ejbModule) throws OpenEJBException {
    // map existing webservice port declarations by servlet link
    Webservices webservices = ejbModule.getWebservices();
    final Map<String, PortComponent> portMap = new TreeMap<>();
    if (webservices != null) {
        for (final WebserviceDescription webserviceDescription : webservices.getWebserviceDescription()) {
            for (final PortComponent portComponent : webserviceDescription.getPortComponent()) {
                final ServiceImplBean serviceImplBean = portComponent.getServiceImplBean();
                if (serviceImplBean != null && serviceImplBean.getEjbLink() != null) {
                    portMap.put(serviceImplBean.getEjbLink(), portComponent);
                }
            }
        }
    }
    final Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
    WebserviceDescription webserviceDescription;
    for (final EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        // skip if this is not a webservices endpoint
        if (!(enterpriseBean instanceof SessionBean)) {
            continue;
        }
        final SessionBean sessionBean = (SessionBean) enterpriseBean;
        if (sessionBean.getSessionType() == SessionType.STATEFUL) {
            continue;
        }
        if (sessionBean.getSessionType() == SessionType.MANAGED) {
            continue;
        }
        if (sessionBean.getServiceEndpoint() == null) {
            continue;
        }
        final EjbDeployment deployment = deploymentsByEjbName.get(sessionBean.getEjbName());
        if (deployment == null) {
            continue;
        }
        final Class<?> ejbClass;
        try {
            ejbClass = ejbModule.getClassLoader().loadClass(sessionBean.getEjbClass());
        } catch (final ClassNotFoundException e) {
            throw new OpenEJBException("Unable to load ejb class: " + sessionBean.getEjbClass(), e);
        }
        // for now, skip all non jaxws beans
        if (!JaxWsUtils.isWebService(ejbClass)) {
            continue;
        }
        // create webservices dd if not defined
        if (webservices == null) {
            webservices = new Webservices();
            ejbModule.setWebservices(webservices);
        }
        webserviceDescription = webservices.getWebserviceDescriptionMap().get(JaxWsUtils.getServiceName(ejbClass));
        if (webserviceDescription == null) {
            webserviceDescription = new WebserviceDescription();
            if (JaxWsUtils.isWebService(ejbClass)) {
                webserviceDescription.setWebserviceDescriptionName(JaxWsUtils.getServiceName(ejbClass));
            }
            // TODO else { /* create webserviceDescription name using some sort of jaxrpc data */ }
            webservices.getWebserviceDescription().add(webserviceDescription);
        }
        // add a port component if we don't alrady have one
        PortComponent portComponent = portMap.get(sessionBean.getEjbName());
        if (portComponent == null) {
            portComponent = new PortComponent();
            if (webserviceDescription.getPortComponentMap().containsKey(JaxWsUtils.getPortQName(ejbClass).getLocalPart())) {
                // when to webservices.xml is defined and when we want to
                // publish more than one port for the same implementation by configuration
                portComponent.setPortComponentName(sessionBean.getEjbName());
            } else {
                // JAX-WS Metadata specification default
                portComponent.setPortComponentName(JaxWsUtils.getPortQName(ejbClass).getLocalPart());
            }
            webserviceDescription.getPortComponent().add(portComponent);
            final ServiceImplBean serviceImplBean = new ServiceImplBean();
            serviceImplBean.setEjbLink(sessionBean.getEjbName());
            portComponent.setServiceImplBean(serviceImplBean);
            // Checking if MTOM must be enabled
            if (portComponent.getProtocolBinding() == null) {
                portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(ejbClass));
            }
            configMtomAnnotation(ejbClass, portComponent);
            if (SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding()) || SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding())) {
                portComponent.setEnableMtom(true);
            }
        }
        // default portId == deploymentId
        if (portComponent.getId() == null) {
            portComponent.setId(deployment.getDeploymentId());
        }
        if (webserviceDescription.getId() == null) {
            webserviceDescription.setId(deployment.getDeploymentId());
        }
        // set service endpoint interface
        if (portComponent.getServiceEndpointInterface() == null) {
            portComponent.setServiceEndpointInterface(sessionBean.getServiceEndpoint());
        }
        // default location is /@WebService.serviceName/@WebService.name
        if (JaxWsUtils.isWebService(ejbClass)) {
            if (portComponent.getWsdlPort() == null) {
                portComponent.setWsdlPort(JaxWsUtils.getPortQName(ejbClass));
            }
            if (webserviceDescription.getWsdlFile() == null) {
                webserviceDescription.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(ejbClass, ejbModule.getClassLoader()));
            }
            if (portComponent.getWsdlService() == null) {
                final Definition definition = getWsdl(ejbModule, webserviceDescription.getWsdlFile());
                if (definition != null && definition.getServices().size() == 1) {
                    final QName serviceQName = (QName) definition.getServices().keySet().iterator().next();
                    portComponent.setWsdlService(serviceQName);
                } else {
                    portComponent.setWsdlService(JaxWsUtils.getServiceQName(ejbClass));
                }
            }
            if (portComponent.getLocation() == null && webserviceDescription.getWsdlFile() != null) {
                // set location based on wsdl port
                final Definition definition = getWsdl(ejbModule, webserviceDescription.getWsdlFile());
                final String locationURI = getLocationFromWsdl(definition, portComponent);
                portComponent.setLocation(locationURI);
            }
            if (portComponent.getProtocolBinding() == null) {
                portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(ejbClass));
            }
            // handlers
            if (portComponent.getHandlerChains() == null) {
                final HandlerChains handlerChains = getHandlerChains(ejbClass, sessionBean.getServiceEndpoint(), ejbModule.getClassLoader());
                portComponent.setHandlerChains(handlerChains);
            }
        }
    // TODO else { /* location JAX-RPC services comes from wsdl file */ }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) PortComponent(org.apache.openejb.jee.PortComponent) ServiceImplBean(org.apache.openejb.jee.ServiceImplBean) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) HandlerChains(org.apache.openejb.jee.HandlerChains) Webservices(org.apache.openejb.jee.Webservices) TreeMap(java.util.TreeMap) SessionBean(org.apache.openejb.jee.SessionBean) WebserviceDescription(org.apache.openejb.jee.WebserviceDescription) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment)

Example 44 with OpenEJBException

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

the class WsDeployer method processPorts.

private void processPorts(final WebModule webModule) throws OpenEJBException {
    // map existing webservice port declarations by servlet link
    Webservices webservices = webModule.getWebservices();
    final Map<String, PortComponent> portMap = new TreeMap<>();
    if (webservices != null) {
        for (final WebserviceDescription webserviceDescription : webservices.getWebserviceDescription()) {
            for (final PortComponent portComponent : webserviceDescription.getPortComponent()) {
                final ServiceImplBean serviceImplBean = portComponent.getServiceImplBean();
                if (serviceImplBean != null && serviceImplBean.getServletLink() != null) {
                    portMap.put(serviceImplBean.getServletLink(), portComponent);
                }
            }
        }
    }
    // map existing servlet-mapping declarations
    final WebApp webApp = webModule.getWebApp();
    final Map<String, ServletMapping> servletMappings = new TreeMap<>();
    for (final ServletMapping servletMapping : webApp.getServletMapping()) {
        servletMappings.put(servletMapping.getServletName(), servletMapping);
    }
    // add port declarations for Pojo webservices
    WebserviceDescription webserviceDescription;
    for (final Servlet servlet : webApp.getServlet()) {
        // the implementation class will be replaced by the WsServlet in the WsRegistry
        final String className = servlet.getServletClass();
        // Skip JSPs
        if (className == null) {
            continue;
        }
        try {
            final Class<?> clazz = webModule.getClassLoader().loadClass(className);
            if (JaxWsUtils.isWebService(clazz)) {
                // add servlet mapping if not already declared
                ServletMapping servletMapping = servletMappings.get(servlet.getServletName());
                final String serviceName = JaxWsUtils.getServiceName(clazz);
                if (servletMapping == null) {
                    servletMapping = new ServletMapping();
                    servletMapping.setServletName(servlet.getServletName());
                    final String location = "/" + serviceName;
                    servletMapping.getUrlPattern().add(location);
                    webApp.getServletMapping().add(servletMapping);
                }
                // if we don't have a webservices document yet, we're gonna need one now
                if (webservices == null) {
                    webservices = new Webservices();
                    webModule.setWebservices(webservices);
                }
                // add web service description element (maps to service)
                webserviceDescription = webservices.getWebserviceDescriptionMap().get(serviceName);
                if (webserviceDescription == null) {
                    webserviceDescription = new WebserviceDescription();
                    webserviceDescription.setWebserviceDescriptionName(serviceName);
                    webservices.getWebserviceDescription().add(webserviceDescription);
                }
                // define port if not already declared
                PortComponent portComponent = portMap.get(servlet.getServletName());
                if (portComponent == null) {
                    portComponent = new PortComponent();
                    portComponent.setPortComponentName(clazz.getSimpleName());
                    final ServiceImplBean serviceImplBean = new ServiceImplBean();
                    serviceImplBean.setServletLink(servlet.getServletName());
                    portComponent.setServiceImplBean(serviceImplBean);
                    webserviceDescription.getPortComponent().add(portComponent);
                }
                // default portId == host.moduleId.servletName
                if (portComponent.getId() == null) {
                    portComponent.setId(webModule.getHost() + "." + webModule.getModuleId() + "." + servlet.getServletName());
                }
                if (webserviceDescription.getId() == null) {
                    webserviceDescription.setId(webModule.getHost() + "." + webModule.getModuleId() + "." + servlet.getServletName());
                }
                // set port values from annotations if not already set
                if (portComponent.getServiceEndpointInterface() == null) {
                    portComponent.setServiceEndpointInterface(JaxWsUtils.getServiceInterface(clazz));
                }
                if (portComponent.getWsdlPort() == null) {
                    portComponent.setWsdlPort(JaxWsUtils.getPortQName(clazz));
                }
                if (webserviceDescription.getWsdlFile() == null) {
                    webserviceDescription.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(clazz, webModule.getClassLoader()));
                }
                if (portComponent.getWsdlService() == null) {
                    final Definition definition = getWsdl(webModule, webserviceDescription.getWsdlFile());
                    if (definition != null && definition.getServices().size() == 1) {
                        final QName serviceQName = (QName) definition.getServices().keySet().iterator().next();
                        portComponent.setWsdlService(serviceQName);
                    } else {
                        portComponent.setWsdlService(JaxWsUtils.getServiceQName(clazz));
                    }
                }
                if (portComponent.getProtocolBinding() == null) {
                    portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(clazz));
                }
                configMtomAnnotation(clazz, portComponent);
                if (SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding()) || SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding())) {
                    portComponent.setEnableMtom(true);
                }
                // handlers
                if (portComponent.getHandlerChains() == null) {
                    final HandlerChains handlerChains = getHandlerChains(clazz, portComponent.getServiceEndpointInterface(), webModule.getClassLoader());
                    portComponent.setHandlerChains(handlerChains);
                }
            }
        } catch (final Exception e) {
            throw new OpenEJBException("Unable to load servlet class: " + className, e);
        }
    }
}
Also used : ServletMapping(org.apache.openejb.jee.ServletMapping) OpenEJBException(org.apache.openejb.OpenEJBException) PortComponent(org.apache.openejb.jee.PortComponent) ServiceImplBean(org.apache.openejb.jee.ServiceImplBean) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) HandlerChains(org.apache.openejb.jee.HandlerChains) Webservices(org.apache.openejb.jee.Webservices) TreeMap(java.util.TreeMap) MalformedURLException(java.net.MalformedURLException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) WebserviceDescription(org.apache.openejb.jee.WebserviceDescription) Servlet(org.apache.openejb.jee.Servlet) WebApp(org.apache.openejb.jee.WebApp)

Example 45 with OpenEJBException

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

the class ServiceJarXmlLoader method parse.

private void parse(final String namespace) {
    try {
        // Load and try again
        final ServicesJar servicesJar = JaxbOpenejb.readServicesJar(namespace);
        for (final ServiceProvider provider : servicesJar.getServiceProvider()) {
            final ID found = new ID(namespace, provider.getId());
            loaded.put(found, provider);
        }
    } catch (final OpenEJBException e) {
        throw new IllegalStateException(e);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ServiceProvider(org.apache.openejb.config.sys.ServiceProvider) ServicesJar(org.apache.openejb.config.sys.ServicesJar)

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