You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2013/05/26 22:08:08 UTC

svn commit: r1486465 - in /tomee/tomee/trunk: container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/ server/openejb-webservices/src/main/java/org/apache/openejb/server/webservices/ tomee/tomee-catalina/src/main/java/org/apache...

Author: rmannibucau
Date: Sun May 26 20:08:08 2013
New Revision: 1486465

URL: http://svn.apache.org/r1486465
Log:
TOMEE-948 ejb webservices in ear deployment

Added:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/NewEjbAvailableAfterApplicationCreated.java
Modified:
    tomee/tomee/trunk/server/openejb-webservices/src/main/java/org/apache/openejb/server/webservices/WsService.java
    tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java

Added: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/NewEjbAvailableAfterApplicationCreated.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/NewEjbAvailableAfterApplicationCreated.java?rev=1486465&view=auto
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/NewEjbAvailableAfterApplicationCreated.java (added)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/NewEjbAvailableAfterApplicationCreated.java Sun May 26 20:08:08 2013
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.assembler.classic.event;
+
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.observer.Event;
+
+import java.util.Collection;
+
+@Event
+public class NewEjbAvailableAfterApplicationCreated {
+    private final AppInfo app;
+    private final Collection<BeanContext> beanContexts;
+
+    public NewEjbAvailableAfterApplicationCreated(final AppInfo appInfo, final Collection<BeanContext> beanContexts) {
+        this.app = appInfo;
+        this.beanContexts = beanContexts;
+    }
+
+    public AppInfo getApp() {
+        return app;
+    }
+
+    public Collection<BeanContext> getBeanContexts() {
+        return beanContexts;
+    }
+
+    @Override
+    public String toString() {
+        return "NewEjbAvailableAfterApplicationCreated{" +
+                "app=" + app +
+                ", beanContexts=" + beanContexts +
+            '}';
+    }
+}

Modified: tomee/tomee/trunk/server/openejb-webservices/src/main/java/org/apache/openejb/server/webservices/WsService.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-webservices/src/main/java/org/apache/openejb/server/webservices/WsService.java?rev=1486465&r1=1486464&r2=1486465&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-webservices/src/main/java/org/apache/openejb/server/webservices/WsService.java (original)
+++ tomee/tomee/trunk/server/openejb-webservices/src/main/java/org/apache/openejb/server/webservices/WsService.java Sun May 26 20:08:08 2013
@@ -33,6 +33,7 @@ import org.apache.openejb.assembler.clas
 import org.apache.openejb.assembler.classic.WsBuilder;
 import org.apache.openejb.assembler.classic.event.AssemblerAfterApplicationCreated;
 import org.apache.openejb.assembler.classic.event.AssemblerBeforeApplicationDestroyed;
+import org.apache.openejb.assembler.classic.event.NewEjbAvailableAfterApplicationCreated;
 import org.apache.openejb.assembler.classic.util.PojoUtil;
 import org.apache.openejb.assembler.classic.util.ServiceConfiguration;
 import org.apache.openejb.core.CoreContainerSystem;
@@ -213,111 +214,121 @@ public abstract class WsService implemen
 
     protected abstract void destroyPojoWsContainer(String serviceId);
 
-    public void afterApplicationCreated(
-                                               @Observes
-                                               final AssemblerAfterApplicationCreated event) {
+    // handle webapp ejbs of ears
+    public void newEjbToDeploy(final @Observes NewEjbAvailableAfterApplicationCreated event) {
+        deployApp(event.getApp(), event.getBeanContexts());
+    }
+
+    public void afterApplicationCreated(final @Observes AssemblerAfterApplicationCreated event) {
         final AppInfo appInfo = event.getApp();
         if (deployedApplications.add(appInfo)) {
-            final Map<String, String> webContextByEjb = new HashMap<String, String>();
-            for (final WebAppInfo webApp : appInfo.webApps) {
-                for (final String ejb : webApp.ejbWebServices) {
-                    webContextByEjb.put(ejb, webApp.contextRoot);
-                }
+            deployApp(appInfo, null);
+        }
+    }
+
+    private void deployApp(final AppInfo appInfo, final Collection<BeanContext> ejbs) {
+        final Map<String, String> webContextByEjb = new HashMap<String, String>();
+        for (final WebAppInfo webApp : appInfo.webApps) {
+            for (final String ejb : webApp.ejbWebServices) {
+                webContextByEjb.put(ejb, webApp.contextRoot);
             }
+        }
 
-            final Map<String, String> contextData = new HashMap<String, String>();
-            contextData.put("appId", appInfo.path);
-            for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
-                final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
-                for (final PortInfo port : ejbJar.portInfos) {
-                    ports.put(port.serviceLink, port);
-                }
+        final Map<String, String> contextData = new HashMap<String, String>();
+        contextData.put("appId", appInfo.path);
+        for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
+            final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
+            for (final PortInfo port : ejbJar.portInfos) {
+                ports.put(port.serviceLink, port);
+            }
 
-                URL moduleBaseUrl = null;
-                if (ejbJar.path != null) {
-                    try {
-                        moduleBaseUrl = new File(ejbJar.path).toURI().toURL();
-                    } catch (MalformedURLException e) {
-                        logger.error("Invalid ejb jar location " + ejbJar.path, e);
-                    }
+            URL moduleBaseUrl = null;
+            if (ejbJar.path != null) {
+                try {
+                    moduleBaseUrl = new File(ejbJar.path).toURI().toURL();
+                } catch (MalformedURLException e) {
+                    logger.error("Invalid ejb jar location " + ejbJar.path, e);
                 }
+            }
 
-                StringTemplate deploymentIdTemplate = this.wsAddressTemplate;
-                if (ejbJar.properties.containsKey(WS_ADDRESS_FORMAT)) {
-                    final String format = ejbJar.properties.getProperty(WS_ADDRESS_FORMAT);
-                    logger.info("Using " + WS_ADDRESS_FORMAT + " '" + format + "'");
-                    deploymentIdTemplate = new StringTemplate(format);
-                }
-                contextData.put("ejbJarId", ejbJar.moduleName);
+            StringTemplate deploymentIdTemplate = this.wsAddressTemplate;
+            if (ejbJar.properties.containsKey(WS_ADDRESS_FORMAT)) {
+                final String format = ejbJar.properties.getProperty(WS_ADDRESS_FORMAT);
+                logger.info("Using " + WS_ADDRESS_FORMAT + " '" + format + "'");
+                deploymentIdTemplate = new StringTemplate(format);
+            }
+            contextData.put("ejbJarId", ejbJar.moduleName);
 
-                for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
-                    if (bean instanceof StatelessBeanInfo || bean instanceof SingletonBeanInfo) {
+            for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
+                if (bean instanceof StatelessBeanInfo || bean instanceof SingletonBeanInfo) {
 
-                        final BeanContext beanContext = containerSystem.getBeanContext(bean.ejbDeploymentId);
-                        if (beanContext == null)
-                            continue;
+                    final BeanContext beanContext = containerSystem.getBeanContext(bean.ejbDeploymentId);
+                    if (beanContext == null || (ejbs != null && !ejbs.contains(beanContext))) {
+                        continue;
+                    }
 
-                        final PortInfo portInfo = ports.get(bean.ejbName);
-                        if (portInfo == null)
-                            continue;
+                    final PortInfo portInfo = ports.get(bean.ejbName);
+                    if (portInfo == null)
+                        continue;
 
-                        final ClassLoader old = Thread.currentThread().getContextClassLoader();
-                        Thread.currentThread().setContextClassLoader(beanContext.getClassLoader());
-                        try {
-                            final PortData port = WsBuilder.toPortData(portInfo, beanContext.getInjections(), moduleBaseUrl, beanContext.getClassLoader());
+                    final ClassLoader old = Thread.currentThread().getContextClassLoader();
+                    Thread.currentThread().setContextClassLoader(beanContext.getClassLoader());
+                    try {
+                        final PortData port = WsBuilder.toPortData(portInfo, beanContext.getInjections(), moduleBaseUrl, beanContext.getClassLoader());
+
+                        final HttpListener container = createEjbWsContainer(moduleBaseUrl, port, beanContext, new ServiceConfiguration(beanContext.getProperties(), appInfo.services));
 
-                            final HttpListener container = createEjbWsContainer(moduleBaseUrl, port, beanContext, new ServiceConfiguration(beanContext.getProperties(), appInfo.services));
+                        // generate a location if one was not assigned
+                        String location = port.getLocation();
+                        if (location == null) {
+                            location = autoAssignWsLocation(bean, port, contextData, deploymentIdTemplate);
+                        }
+                        if (!location.startsWith("/"))
+                            location = "/" + location;
+                        ejbLocations.put(bean.ejbDeploymentId, location);
+
+                        final ClassLoader classLoader = beanContext.getClassLoader();
+                        if (wsRegistry != null) {
+                            String auth = authMethod;
+                            String realm = realmName;
+                            String transport = transportGuarantee;
+
+                            if ("BASIC".equals(portInfo.authMethod) || "DIGEST".equals(portInfo.authMethod) || "CLIENT-CERT".equals(portInfo.authMethod)) {
+                                auth = portInfo.authMethod;
+                                realm = portInfo.realmName;
+                                transport = portInfo.transportGuarantee;
+                            }
 
-                            // generate a location if one was not assigned
-                            String location = port.getLocation();
-                            if (location == null) {
-                                location = autoAssignWsLocation(bean, port, contextData, deploymentIdTemplate);
+                            String context = webContextByEjb.get(bean.ejbClass);
+                            if (context == null && !OLD_WEBSERVICE_DEPLOYMENT) {
+                                context = ejbJar.moduleName;
                             }
-                            if (!location.startsWith("/"))
-                                location = "/" + location;
-                            ejbLocations.put(bean.ejbDeploymentId, location);
-
-                            final ClassLoader classLoader = beanContext.getClassLoader();
-                            if (wsRegistry != null) {
-                                String auth = authMethod;
-                                String realm = realmName;
-                                String transport = transportGuarantee;
-
-                                if ("BASIC".equals(portInfo.authMethod) || "DIGEST".equals(portInfo.authMethod) || "CLIENT-CERT".equals(portInfo.authMethod)) {
-                                    auth = portInfo.authMethod;
-                                    realm = portInfo.realmName;
-                                    transport = portInfo.transportGuarantee;
-                                }
-
-                                String context = webContextByEjb.get(bean.ejbClass);
-                                if (context == null && !OLD_WEBSERVICE_DEPLOYMENT) {
-                                    context = ejbJar.moduleName;
-                                }
-                                final List<String> addresses = wsRegistry.addWsContainer(context, location, container, virtualHost, realm, transport, auth, classLoader);
-
-                                // one of the registered addresses to be the canonical address
-                                final String address = HttpUtil.selectSingleAddress(addresses);
-
-                                if (address != null) {
-                                    // register wsdl location
-                                    portAddressRegistry.addPort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.wsdlPort, portInfo.seiInterfaceName, address);
-                                    logger.info("Webservice(wsdl=" + address + ", qname=" + port.getWsdlService() + ") --> Ejb(id=" + portInfo.portId + ")");
-                                    ejbAddresses.put(bean.ejbDeploymentId, address);
-                                    addressesForApp(appInfo.appId).add(new EndpointInfo(address, port.getWsdlService(), beanContext.getBeanClass().getName()));
-                                }
+                            final List<String> addresses = wsRegistry.addWsContainer(context, location, container, virtualHost, realm, transport, auth, classLoader);
+
+                            // one of the registered addresses to be the canonical address
+                            final String address = HttpUtil.selectSingleAddress(addresses);
+
+                            if (address != null) {
+                                // register wsdl location
+                                portAddressRegistry.addPort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.wsdlPort, portInfo.seiInterfaceName, address);
+                                logger.info("Webservice(wsdl=" + address + ", qname=" + port.getWsdlService() + ") --> Ejb(id=" + portInfo.portId + ")");
+                                ejbAddresses.put(bean.ejbDeploymentId, address);
+                                addressesForApp(appInfo.appId).add(new EndpointInfo(address, port.getWsdlService(), beanContext.getBeanClass().getName()));
                             }
-                        } catch (Throwable e) {
-                            logger.error("Error deploying JAX-WS Web Service for EJB " + beanContext.getDeploymentID(), e);
-                        } finally {
-                            Thread.currentThread().setContextClassLoader(old);
                         }
+                    } catch (Throwable e) {
+                        logger.error("Error deploying JAX-WS Web Service for EJB " + beanContext.getDeploymentID(), e);
+                    } finally {
+                        Thread.currentThread().setContextClassLoader(old);
                     }
                 }
             }
+        }
+        if (ejbs == null) {
             for (final WebAppInfo webApp : appInfo.webApps) {
                 afterApplicationCreated(appInfo, webApp);
             }
-        }
+        } // else called because of ear case where new ejbs are deployed in webapps
     }
 
     private List<EndpointInfo> addressesForApp(final String appId) {

Modified: tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java?rev=1486465&r1=1486464&r2=1486465&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java (original)
+++ tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java Sun May 26 20:08:08 2013
@@ -83,6 +83,7 @@ import org.apache.openejb.assembler.clas
 import org.apache.openejb.assembler.classic.ServletInfo;
 import org.apache.openejb.assembler.classic.WebAppBuilder;
 import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.assembler.classic.event.NewEjbAvailableAfterApplicationCreated;
 import org.apache.openejb.cdi.CdiBuilder;
 import org.apache.openejb.config.AppModule;
 import org.apache.openejb.config.ConfigurationFactory;
@@ -1223,6 +1224,8 @@ public class TomcatWebAppBuilder impleme
                     assembler.startEjbs(true, beanContexts);
                     assembler.bindGlobals(appContext.getBindings());
                     eagerInitOfLocalBeanProxies(beanContexts, standardContext.getLoader().getClassLoader());
+
+                    deployWebServicesIfEjbCreatedHere(contextInfo.appInfo, beanContexts);
                 }
 
                 // jndi bindings
@@ -1259,6 +1262,13 @@ public class TomcatWebAppBuilder impleme
         }
     }
 
+    private static void deployWebServicesIfEjbCreatedHere(final AppInfo info, final Collection<BeanContext> beanContexts) {
+        if (beanContexts == null || beanContexts.isEmpty()) {
+            return;
+        }
+        SystemInstance.get().fireEvent(new NewEjbAvailableAfterApplicationCreated(info, beanContexts));
+    }
+
     private static void eagerInitOfLocalBeanProxies(final Collection<BeanContext> beans, final ClassLoader classLoader) {
         for (final BeanContext deployment : beans) {
             if (deployment.isLocalbean() && !deployment.isDynamicallyImplemented()) { // init proxy eagerly otherwise deserialization of serialized object can't work