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-1446 BeforeStartEjbs event
Date Mon, 17 Nov 2014 15:43:39 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x ea1f8892e -> 7a8c8aa8d


TOMEE-1446 BeforeStartEjbs event


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

Branch: refs/heads/tomee-1.7.x
Commit: 7a8c8aa8d756d429f72060bf78e0b986abe0d0eb
Parents: ea1f889
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Mon Nov 17 16:29:13 2014 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Mon Nov 17 16:29:13 2014 +0100

----------------------------------------------------------------------
 .../openejb/assembler/classic/Assembler.java    |  3 +
 .../classic/event/BeforeStartEjbs.java          | 47 ++++++++++
 .../ExtensionProviderRegistrationTest.java      | 95 ++++++++++++++++++++
 .../server/cxf/rs/event/ServerCreatedTest.java  | 84 +++++++++++++++++
 4 files changed, 229 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/7a8c8aa8/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index 5d70381..d5c11b6 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -43,6 +43,7 @@ import org.apache.openejb.assembler.classic.event.AssemblerAfterApplicationCreat
 import org.apache.openejb.assembler.classic.event.AssemblerBeforeApplicationDestroyed;
 import org.apache.openejb.assembler.classic.event.AssemblerCreated;
 import org.apache.openejb.assembler.classic.event.AssemblerDestroyed;
+import org.apache.openejb.assembler.classic.event.BeforeStartEjbs;
 import org.apache.openejb.assembler.classic.event.ContainerSystemPostCreate;
 import org.apache.openejb.assembler.classic.event.ContainerSystemPreDestroy;
 import org.apache.openejb.assembler.monitoring.JMXContainer;
@@ -1174,6 +1175,8 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
     public void startEjbs(final boolean start, final List<BeanContext> allDeployments)
throws OpenEJBException {
         // now that everything is configured, deploy to the container
         if (start) {
+            SystemInstance.get().fireEvent(new BeforeStartEjbs(allDeployments));
+
             final Collection<BeanContext> toStart = new ArrayList<BeanContext>();
 
             // deploy

http://git-wip-us.apache.org/repos/asf/tomee/blob/7a8c8aa8/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/BeforeStartEjbs.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/BeforeStartEjbs.java
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/BeforeStartEjbs.java
new file mode 100644
index 0000000..a73a115
--- /dev/null
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/BeforeStartEjbs.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.assembler.classic.event;
+
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.observer.Event;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * IMPORTANT NOTE: when using this event it should be compared to BeforeAppInfoBuilderEvent
which is likely better.
+ * Main reason to use BeforeStartEjbs is the need of reflection (to do filtering for instance).
All other cases shouldn't use it.
+ */
+@Event
+public class BeforeStartEjbs {
+    private final List<BeanContext> ejbs;
+
+    public BeforeStartEjbs(final List<BeanContext> allDeployments) {
+        this.ejbs = allDeployments;
+    }
+
+    public List<BeanContext> getEjbs() {
+        return Collections.unmodifiableList(ejbs);
+    }
+
+    @Override
+    public String toString() {
+        return "BeforeStartEjbs{" +
+                "#ejbs=" + ejbs.size() +
+                '}';
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/7a8c8aa8/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/event/ExtensionProviderRegistrationTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/event/ExtensionProviderRegistrationTest.java
b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/event/ExtensionProviderRegistrationTest.java
new file mode 100644
index 0000000..99edc4e
--- /dev/null
+++ b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/event/ExtensionProviderRegistrationTest.java
@@ -0,0 +1,95 @@
+/*
+ *     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.rs.event;
+
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.loader.IO;
+import org.apache.openejb.observer.Observes;
+import org.apache.openejb.server.cxf.rs.event.ExtensionProviderRegistration;
+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.testng.PropertiesBuilder;
+import org.apache.openejb.util.NetworkUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+
+@EnableServices("jaxrs")
+@RunWith(ApplicationComposer.class)
+public class ExtensionProviderRegistrationTest {
+    private static int port = -1;
+
+    @BeforeClass
+    public static void beforeClass() {
+        port = NetworkUtil.getNextAvailablePort();
+    }
+
+    @Configuration
+    public Properties props() {
+        return new PropertiesBuilder()
+                .p("httpejbd.port", Integer.toString(port))
+                .p("observer", "new://Service?class-name=" + Observer.class.getName())
+                .build();
+    }
+
+    @Module
+    @Classes(ServerCreatedEndpoint.class)
+    public WebApp war() {
+        return new WebApp().contextRoot("foo");
+    }
+
+    @Test
+    public void checkEvent() throws IOException {
+        assertEquals("foo", IO.slurp(new URL("http://localhost:" + port + "/foo/ExtensionProviderRegistrationTest/")));
+    }
+
+    @Path("ExtensionProviderRegistrationTest")
+    public static class ServerCreatedEndpoint {
+        @GET
+        public String useless() {
+            throw new IllegalArgumentException("foo");
+        }
+    }
+
+    @Provider
+    public static class MyMapper implements ExceptionMapper<IllegalArgumentException>
{
+        @Override
+        public Response toResponse(final IllegalArgumentException e) {
+            return Response.ok(e.getMessage()).build();
+        }
+    }
+
+    public static class Observer {
+        public void obs(@Observes final ExtensionProviderRegistration event) {
+            event.getProviders().add(new MyMapper());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/7a8c8aa8/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/event/ServerCreatedTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/event/ServerCreatedTest.java
b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/event/ServerCreatedTest.java
new file mode 100644
index 0000000..100a7ab
--- /dev/null
+++ b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/event/ServerCreatedTest.java
@@ -0,0 +1,84 @@
+/*
+ *     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.rs.event;
+
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.observer.Observes;
+import org.apache.openejb.server.cxf.rs.event.ServerCreated;
+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.testng.PropertiesBuilder;
+import org.apache.openejb.util.NetworkUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ws.rs.HEAD;
+import javax.ws.rs.Path;
+import java.util.Properties;
+
+import static org.junit.Assert.assertNotNull;
+
+@EnableServices("jaxrs")
+@RunWith(ApplicationComposer.class)
+public class ServerCreatedTest {
+    private static int port = -1;
+
+    @BeforeClass
+    public static void beforeClass() {
+        port = NetworkUtil.getNextAvailablePort();
+    }
+
+    @Configuration
+    public Properties props() {
+        return new PropertiesBuilder()
+                .p("httpejbd.port", Integer.toString(port))
+                .p("observer", "new://Service?class-name=" + Observer.class.getName())
+                .build();
+    }
+
+    @Module
+    @Classes(ServerCreatedEndpoint.class)
+    public WebApp war() {
+        return new WebApp().contextRoot("foo");
+    }
+
+    @Test
+    public void checkEvent() {
+        assertNotNull(Observer.event);
+        assertNotNull(Observer.event.getAppContext());
+        assertNotNull(Observer.event.getWebContext());
+        assertNotNull(Observer.event.getServer());
+    }
+
+    @Path("ServerCreatedTest")
+    public static class ServerCreatedEndpoint {
+        @HEAD
+        public void useless() {}
+    }
+
+    public static class Observer {
+        public static ServerCreated event;
+
+        public void obs(@Observes final ServerCreated event) {
+            Observer.event = event;
+        }
+    }
+}


Mime
View raw message