[cxf] branch master updated: [CXF-7610] - Adding SPI to handle customizations to the server bean. (#369)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[cxf] branch master updated: [CXF-7610] - Adding SPI to handle customizations to the server bean. (#369)

John D. Ament-2
This is an automated email from the ASF dual-hosted git repository.

johndament pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 0a57060  [CXF-7610] - Adding SPI to handle customizations to the server bean. (#369)
0a57060 is described below

commit 0a5706078258751904d3f5aa87f4a42dace2c932
Author: John Ament <[hidden email]>
AuthorDate: Wed Feb 7 07:52:46 2018 -0500

    [CXF-7610] - Adding SPI to handle customizations to the server bean. (#369)
   
    - Register the existing SSE event handling as an extension
---
 .../apache/cxf/cdi/JAXRSCdiResourceExtension.java  |  4 +++-
 .../JAXRSServerFactoryCustomizationExtension.java  | 13 +++++------
 .../JAXRSServerFactoryCustomizationExtension.java  |  5 ++---
 .../JAXRSServerFactoryCustomizationUtils.java      | 25 +++++++++++++---------
 .../org/apache/cxf/jaxrs/utils/ResourceUtils.java  |  2 +-
 rt/rs/sse/pom.xml                                  |  6 ------
 .../SseTransportCustomizationExtension.java        |  8 +++++--
 rt/rs/sse/src/main/resources/META-INF/beans.xml    |  2 +-
 ...rs.ext.JAXRSServerFactoryCustomizationExtension |  1 +
 9 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
index 25c4525..bc7a251 100644
--- a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
@@ -54,12 +54,13 @@ import javax.ws.rs.ext.Provider;
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.extension.ExtensionManagerBus;
 import org.apache.cxf.cdi.event.DisposableCreationalContext;
-import org.apache.cxf.cdi.extension.JAXRSServerFactoryCustomizationExtension;
 import org.apache.cxf.feature.Feature;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.ext.ContextClassProvider;
+import org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension;
 import org.apache.cxf.jaxrs.provider.ServerConfigurableFactory;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSServerFactoryCustomizationUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 
 /**
@@ -418,6 +419,7 @@ public class JAXRSCdiResourceExtension implements Extension {
      * @param bean JAX-RS server factory bean about to be created
      */
     private void customize(final BeanManager beanManager, final JAXRSServerFactoryBean bean) {
+        JAXRSServerFactoryCustomizationUtils.customize(bean);
         final Collection<Bean<?>> extensionBeans = beanManager.getBeans(JAXRSServerFactoryCustomizationExtension.class);
 
         for (final Bean<?> extensionBean: extensionBeans) {
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/extension/JAXRSServerFactoryCustomizationExtension.java b/integration/cdi/src/main/java/org/apache/cxf/cdi/extension/JAXRSServerFactoryCustomizationExtension.java
index 7b5c845..aabc739 100644
--- a/integration/cdi/src/main/java/org/apache/cxf/cdi/extension/JAXRSServerFactoryCustomizationExtension.java
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/extension/JAXRSServerFactoryCustomizationExtension.java
@@ -18,17 +18,14 @@
  */
 package org.apache.cxf.cdi.extension;
 
-import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-
 /**
  * Serves as an extension point in order to allow to customize JAX-RS server
  * factory bean creation (f.e. add features, providers, assign transport, ...)
  * during the CDI beans discovery and initialization.
+ *
+ * This class is now deprecated, in favor of {@link org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension}
  */
-public interface JAXRSServerFactoryCustomizationExtension {
-    /**
-     * Customize JAX-RS server factory bean before it is being initialized
-     * @param bean JAX-RS server factory bean
-     */
-    void customize(JAXRSServerFactoryBean bean);
+@Deprecated
+public interface JAXRSServerFactoryCustomizationExtension extends
+        org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension {
 }
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/extension/JAXRSServerFactoryCustomizationExtension.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/JAXRSServerFactoryCustomizationExtension.java
similarity index 93%
copy from integration/cdi/src/main/java/org/apache/cxf/cdi/extension/JAXRSServerFactoryCustomizationExtension.java
copy to rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/JAXRSServerFactoryCustomizationExtension.java
index 7b5c845..b532f2f 100644
--- a/integration/cdi/src/main/java/org/apache/cxf/cdi/extension/JAXRSServerFactoryCustomizationExtension.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/JAXRSServerFactoryCustomizationExtension.java
@@ -16,14 +16,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.cdi.extension;
+package org.apache.cxf.jaxrs.ext;
 
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 
 /**
  * Serves as an extension point in order to allow to customize JAX-RS server
  * factory bean creation (f.e. add features, providers, assign transport, ...)
- * during the CDI beans discovery and initialization.
  */
 public interface JAXRSServerFactoryCustomizationExtension {
     /**
@@ -31,4 +30,4 @@ public interface JAXRSServerFactoryCustomizationExtension {
      * @param bean JAX-RS server factory bean
      */
     void customize(JAXRSServerFactoryBean bean);
-}
+}
\ No newline at end of file
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/extension/JAXRSServerFactoryCustomizationExtension.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSServerFactoryCustomizationUtils.java
similarity index 54%
copy from integration/cdi/src/main/java/org/apache/cxf/cdi/extension/JAXRSServerFactoryCustomizationExtension.java
copy to rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSServerFactoryCustomizationUtils.java
index 7b5c845..34812fe 100644
--- a/integration/cdi/src/main/java/org/apache/cxf/cdi/extension/JAXRSServerFactoryCustomizationExtension.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSServerFactoryCustomizationUtils.java
@@ -16,19 +16,24 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.cdi.extension;
+package org.apache.cxf.jaxrs.utils;
+
+import java.util.ServiceLoader;
 
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension;
 
-/**
- * Serves as an extension point in order to allow to customize JAX-RS server
- * factory bean creation (f.e. add features, providers, assign transport, ...)
- * during the CDI beans discovery and initialization.
- */
-public interface JAXRSServerFactoryCustomizationExtension {
+public final class JAXRSServerFactoryCustomizationUtils {
+    private JAXRSServerFactoryCustomizationUtils() {
+    }
     /**
-     * Customize JAX-RS server factory bean before it is being initialized
-     * @param bean JAX-RS server factory bean
+     * Looks up JAXRSServerFactoryCustomizationExtension via ServiceLoader and applies them to the passed in bean
      */
-    void customize(JAXRSServerFactoryBean bean);
+    public static void customize(JAXRSServerFactoryBean bean) {
+        ServiceLoader<JAXRSServerFactoryCustomizationExtension> extensions
+                = ServiceLoader.load(JAXRSServerFactoryCustomizationExtension.class);
+        for (JAXRSServerFactoryCustomizationExtension extension : extensions) {
+            extension.customize(bean);
+        }
+    }
 }
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
index a8d05ef..7f88b84 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
@@ -902,9 +902,9 @@ public final class ResourceUtils {
             bean.getProperties(true).putAll(appProps);
         }
         bean.setApplication(app);
-
         return bean;
     }
+
     public static Object createProviderInstance(Class<?> cls) {
         try {
             Constructor<?> c = ResourceUtils.findResourceConstructor(cls, false);
diff --git a/rt/rs/sse/pom.xml b/rt/rs/sse/pom.xml
index b4fe27b..b8c9833 100644
--- a/rt/rs/sse/pom.xml
+++ b/rt/rs/sse/pom.xml
@@ -48,12 +48,6 @@
             <optional>true</optional>
         </dependency>
         <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-integration-cdi</artifactId>
-            <version>${project.version}</version>
-            <optional>true</optional>
-        </dependency>
-        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
diff --git a/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/cdi/SseTransportCustomizationExtension.java b/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/ext/SseTransportCustomizationExtension.java
similarity index 76%
rename from rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/cdi/SseTransportCustomizationExtension.java
rename to rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/ext/SseTransportCustomizationExtension.java
index 68af13c..84a0a9a 100644
--- a/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/cdi/SseTransportCustomizationExtension.java
+++ b/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/ext/SseTransportCustomizationExtension.java
@@ -16,15 +16,19 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.jaxrs.sse.cdi;
+package org.apache.cxf.jaxrs.sse.ext;
 
-import org.apache.cxf.cdi.extension.JAXRSServerFactoryCustomizationExtension;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension;
+import org.apache.cxf.jaxrs.sse.SseContextProvider;
+import org.apache.cxf.jaxrs.sse.atmosphere.SseAtmosphereEventSinkContextProvider;
 import org.apache.cxf.transport.sse.SseHttpTransportFactory;
 
 public class SseTransportCustomizationExtension implements JAXRSServerFactoryCustomizationExtension {
     @Override
     public void customize(final JAXRSServerFactoryBean bean) {
         bean.setTransportId(SseHttpTransportFactory.TRANSPORT_ID);
+        bean.setProvider(new SseContextProvider());
+        bean.setProvider(new SseAtmosphereEventSinkContextProvider());
     }
 }
diff --git a/rt/rs/sse/src/main/resources/META-INF/beans.xml b/rt/rs/sse/src/main/resources/META-INF/beans.xml
index 74cd100..32a112d 100644
--- a/rt/rs/sse/src/main/resources/META-INF/beans.xml
+++ b/rt/rs/sse/src/main/resources/META-INF/beans.xml
@@ -2,5 +2,5 @@
 <beans xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
- bean-discovery-mode="all">
+ bean-discovery-mode="none">
 </beans>
diff --git a/rt/rs/sse/src/main/resources/META-INF/services/org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension b/rt/rs/sse/src/main/resources/META-INF/services/org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension
new file mode 100644
index 0000000..4abbd20
--- /dev/null
+++ b/rt/rs/sse/src/main/resources/META-INF/services/org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension
@@ -0,0 +1 @@
+org.apache.cxf.jaxrs.sse.ext.SseTransportCustomizationExtension
\ No newline at end of file

--
To stop receiving notification emails like this one, please contact
[hidden email].