tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-1486 ServerCreated ServerDestroyed events for jaxws
Date Tue, 06 Jan 2015 14:38:39 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x 8b1d653aa -> 860a1aed8


TOMEE-1486 ServerCreated ServerDestroyed events for jaxws


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/860a1aed
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/860a1aed
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/860a1aed

Branch: refs/heads/tomee-1.7.x
Commit: 860a1aed8330e78a50827d1ccfff8d7fc8c3a836
Parents: 8b1d653
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Tue Jan 6 15:38:20 2015 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Tue Jan 6 15:38:20 2015 +0100

----------------------------------------------------------------------
 .../config/ConfigurableClasspathArchive.java    |  5 +-
 .../apache/openejb/server/cxf/CxfService.java   | 15 +++-
 .../openejb/server/cxf/CxfWsContainer.java      |  5 +-
 .../openejb/server/cxf/event/ServerCreated.java | 47 ++++++++++
 .../server/cxf/event/ServerDestroyed.java       | 38 +++++++++
 .../apache/openejb/server/cxf/EventTest.java    | 90 ++++++++++++++++++++
 6 files changed, 197 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/860a1aed/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurableClasspathArchive.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurableClasspathArchive.java
b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurableClasspathArchive.java
index d122ffc..938f1c9 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurableClasspathArchive.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurableClasspathArchive.java
@@ -79,7 +79,10 @@ public class ConfigurableClasspathArchive extends CompositeArchive implements
Sc
         final ClassLoader loader = module.getClassLoader();
         final String name = "META-INF/" + name();
         try {
-            final URL scanXml = new URLClassLoader(new URL[]{location}, new EmptyResourcesClassLoader()).getResource(name);
+            final URLClassLoader urlClassLoader = new URLClassLoader(new URL[]{location},
new EmptyResourcesClassLoader());
+            final URL scanXml = urlClassLoader.getResource(name);
+            urlClassLoader.close();
+
             if (scanXml == null && !forceDescriptor) {
                 return ClasspathArchive.archive(loader, location);
             } else if (scanXml == null) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/860a1aed/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java
b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java
index 78833b1..9486391 100644
--- a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java
+++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java
@@ -26,11 +26,14 @@ import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.server.cxf.client.SaajInterceptor;
 import org.apache.openejb.server.cxf.client.WebServiceInjectionConfigurator;
 import org.apache.openejb.server.cxf.ejb.EjbWsContainer;
+import org.apache.openejb.server.cxf.event.ServerCreated;
+import org.apache.openejb.server.cxf.event.ServerDestroyed;
 import org.apache.openejb.server.cxf.pojo.PojoWsContainer;
 import org.apache.openejb.server.cxf.transport.HttpTransportFactory;
 import org.apache.openejb.server.cxf.transport.util.CxfUtil;
 import org.apache.openejb.server.httpd.HttpListener;
 import org.apache.openejb.server.webservices.WsService;
+import org.apache.openejb.util.AppFinder;
 
 import javax.naming.Context;
 import java.net.URL;
@@ -89,6 +92,9 @@ public class CxfService extends WsService {
             final EjbWsContainer container = new EjbWsContainer(bus, httpTransportFactory,
port, beanContext, config);
             container.start();
             wsContainers.put(beanContext.getDeploymentID().toString(), container);
+            SystemInstance.get().fireEvent(new ServerCreated(
+                    container.getEndpoint().getServer(),
+                    beanContext.getModuleContext().getAppContext()));
             return container;
         } finally {
             if (oldLoader != null) {
@@ -97,7 +103,10 @@ public class CxfService extends WsService {
         }
     }
 
-    protected HttpListener createPojoWsContainer(final ClassLoader loader, final URL moduleBaseUrl,
final PortData port, final String serviceId, final Class target, final Context context, final
String contextRoot, final Map<String, Object> bdgs, final ServiceConfiguration services)
{
+    protected HttpListener createPojoWsContainer(final ClassLoader loader, final URL moduleBaseUrl,
final PortData port,
+                                                 final String serviceId, final Class target,
final Context context,
+                                                 final String contextRoot,
+                                                 final Map<String, Object> bdgs, final
ServiceConfiguration services) {
         final Bus bus = CxfUtil.getBus();
 
         final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
@@ -108,6 +117,9 @@ public class CxfService extends WsService {
             final PojoWsContainer container = new PojoWsContainer(loader, httpTransportFactory,
bus, port, context, target, bdgs, services);
             container.start();
             wsContainers.put(serviceId, container);
+            SystemInstance.get().fireEvent(new ServerCreated(
+                    container.getEndpoint().getServer(),
+                    AppFinder.findAppContextOrWeb(loader, AppFinder.AppContextTransformer.INSTANCE)));
             return container;
         } finally {
             if (oldLoader != null) {
@@ -131,6 +143,7 @@ public class CxfService extends WsService {
             Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader());
             try {
                 container.destroy();
+                SystemInstance.get().fireEvent(new ServerDestroyed(container.getEndpoint().getServer()));
             } finally {
                 if (oldLoader != null) {
                     CxfUtil.clearBusLoader(oldLoader);

http://git-wip-us.apache.org/repos/asf/tomee/blob/860a1aed/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfWsContainer.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfWsContainer.java
b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfWsContainer.java
index 7a36d51..f2b5b5d 100644
--- a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfWsContainer.java
+++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfWsContainer.java
@@ -55,6 +55,10 @@ public abstract class CxfWsContainer implements HttpListener {
         this.jmxName = registerMBean();
     }
 
+    public CxfEndpoint getEndpoint() {
+        return endpoint;
+    }
+
     protected String getFakeUrl() {
         return "" + endpoint.hashCode();
     }
@@ -70,7 +74,6 @@ public abstract class CxfWsContainer implements HttpListener {
 
         if (endpoint != null) {
             endpoint.stop();
-            endpoint = null;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/860a1aed/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/event/ServerCreated.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/event/ServerCreated.java
b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/event/ServerCreated.java
new file mode 100644
index 0000000..5fdfa88
--- /dev/null
+++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/event/ServerCreated.java
@@ -0,0 +1,47 @@
+/*
+ *     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.server.cxf.event;
+
+import org.apache.cxf.endpoint.Server;
+import org.apache.openejb.AppContext;
+import org.apache.openejb.observer.Event;
+
+@Event
+public class ServerCreated {
+    private final Server server;
+    private final AppContext appContext;
+
+    public ServerCreated(final Server server, final AppContext appContext) {
+        this.server = server;
+        this.appContext = appContext;
+    }
+
+    public Server getServer() {
+        return server;
+    }
+
+    public AppContext getAppContext() {
+        return appContext;
+    }
+
+    @Override
+    public String toString() {
+        return "ServerCreated{" +
+                "appContext=" + appContext.getId() +
+                '}';
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/860a1aed/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/event/ServerDestroyed.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/event/ServerDestroyed.java
b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/event/ServerDestroyed.java
new file mode 100644
index 0000000..5761262
--- /dev/null
+++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/event/ServerDestroyed.java
@@ -0,0 +1,38 @@
+/*
+ *     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.server.cxf.event;
+
+import org.apache.cxf.endpoint.Server;
+import org.apache.openejb.observer.Event;
+
+@Event
+public class ServerDestroyed {
+    private final Server server;
+
+    public ServerDestroyed(final Server server) {
+        this.server = server;
+    }
+
+    public Server getServer() {
+        return server;
+    }
+
+    @Override
+    public String toString() {
+        return "ServerCreated{}";
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/860a1aed/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/EventTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/EventTest.java
b/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/EventTest.java
new file mode 100644
index 0000000..9fbde6d
--- /dev/null
+++ b/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/EventTest.java
@@ -0,0 +1,90 @@
+/**
+ * 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.server.cxf;
+
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.observer.Observes;
+import org.apache.openejb.server.cxf.event.ServerCreated;
+import org.apache.openejb.server.cxf.event.ServerDestroyed;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.Configuration;
+import org.apache.openejb.testing.EnableServices;
+import org.apache.openejb.testing.Module;
+import org.apache.openejb.testing.RandomPort;
+import org.apache.openejb.testng.PropertiesBuilder;
+import org.junit.AfterClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.jws.WebService;
+
+import java.util.Properties;
+
+import static org.junit.Assert.assertNotNull;
+
+@EnableServices("jaxws")
+@RunWith(ApplicationComposer.class)
+public class EventTest {
+    @Module
+    @Classes(innerClassesAsBean = true)
+    public WebApp app() {
+        return new WebApp();
+    }
+
+    @RandomPort("http")
+    private int port;
+
+    @Configuration
+    public Properties config() {
+        return new PropertiesBuilder().p("listener", "new://Service?class-name=" + Observer.class.getName()).build();
+    }
+
+    @Test
+    public void run() {
+        assertNotNull(Observer.created);
+        assertNotNull(Observer.created.getServer());
+        assertNotNull(Observer.created.getServer().getEndpoint());
+    }
+
+    @AfterClass
+    public static void destroy() {
+        assertNotNull(Observer.destroyed);
+        assertNotNull(Observer.destroyed.getServer());
+        assertNotNull(Observer.destroyed.getServer().getEndpoint());
+    }
+
+    @WebService
+    public static class End {
+        public String get() {
+            return "end";
+        }
+    }
+
+    public static class Observer {
+        private static ServerCreated created;
+        private static ServerDestroyed destroyed;
+
+        public void created(@Observes final ServerCreated created) {
+            Observer.created = created;
+        }
+
+        public void destroyed(@Observes final ServerDestroyed destroyed) {
+            Observer.destroyed = destroyed;
+        }
+    }
+}


Mime
View raw message