[jira] [Commented] (CXF-7610) Manage customizations of JAXRSServerFactoryBean in JAX-RS Frontend

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

[jira] [Commented] (CXF-7610) Manage customizations of JAXRSServerFactoryBean in JAX-RS Frontend

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/CXF-7610?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16355403#comment-16355403 ]

ASF GitHub Bot commented on CXF-7610:
-------------------------------------

johnament closed pull request #369: [CXF-7610] - Adding SPI to handle customizations to the server bean.
URL: https://github.com/apache/cxf/pull/369
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 25c452552e1..bc7a251cbb3 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 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 @@ private ClassifiedClasses classes2singletons(final Application application, fina
      * @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 7b5c8452b24..aabc739e786 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/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/JAXRSServerFactoryCustomizationExtension.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/JAXRSServerFactoryCustomizationExtension.java
new file mode 100644
index 00000000000..b532f2f0648
--- /dev/null
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/JAXRSServerFactoryCustomizationExtension.java
@@ -0,0 +1,33 @@
+/**
+ * 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.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, ...)
+ */
+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);
+}
\ No newline at end of file
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSServerFactoryCustomizationUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSServerFactoryCustomizationUtils.java
new file mode 100644
index 00000000000..34812febb9b
--- /dev/null
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSServerFactoryCustomizationUtils.java
@@ -0,0 +1,39 @@
+/**
+ * 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.cxf.jaxrs.utils;
+
+import java.util.ServiceLoader;
+
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension;
+
+public final class JAXRSServerFactoryCustomizationUtils {
+    private JAXRSServerFactoryCustomizationUtils() {
+    }
+    /**
+     * Looks up JAXRSServerFactoryCustomizationExtension via ServiceLoader and applies them to the passed in 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 a8d05efbf4e..7f88b8439d9 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 static JAXRSServerFactoryBean createApplication(Application app,
             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 b4fe27b30ce..b8c983308e1 100644
--- a/rt/rs/sse/pom.xml
+++ b/rt/rs/sse/pom.xml
@@ -47,12 +47,6 @@
             <version>${project.version}</version>
             <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>
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 68af13c460f..84a0a9a8051 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 74cd1004e7a..32a112deeac 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 00000000000..4abbd20689a
--- /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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


> Manage customizations of JAXRSServerFactoryBean in JAX-RS Frontend
> ------------------------------------------------------------------
>
>                 Key: CXF-7610
>                 URL: https://issues.apache.org/jira/browse/CXF-7610
>             Project: CXF
>          Issue Type: New Feature
>          Components: JAX-RS
>            Reporter: John D. Ament
>            Assignee: John D. Ament
>            Priority: Major
>
> CDI has a built in way to manage customizations to the server, via implementations of beans of type {{JAXRSServerFactoryCustomizationExtension}}.  However, it makes sense for this to be a core feature and leverage something like a {{ServiceLoader}} pattern to discover those implementations, as well as allowing CDI beans to be discovered.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)