cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7282] Support the overriding of Application resource life-cycle when it is autodiscovered
Date Mon, 13 Mar 2017 14:40:09 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes d0fb61f79 -> 061e54769


[CXF-7282] Support the overriding of Application resource life-cycle when it is autodiscovered


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/061e5476
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/061e5476
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/061e5476

Branch: refs/heads/3.1.x-fixes
Commit: 061e54769df276424cca4eca8b1daed693e7c555
Parents: d0fb61f
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Mar 13 14:34:00 2017 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Mar 13 14:39:52 2017 +0000

----------------------------------------------------------------------
 .../jaxrs/servlet/CXFNonSpringJaxrsServlet.java    | 17 +++++++++++------
 .../sci/JaxrsServletContainerInitializer.java      | 11 +++++++++--
 2 files changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/061e5476/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
index 9c1154d..0db172b 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
@@ -415,9 +415,12 @@ public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
         return map;
     }
 
-    protected boolean isResourceLifecycleASingleton(ServletConfig servletConfig) {
+    protected boolean isAppResourceLifecycleASingleton(Application app, ServletConfig servletConfig)
{
         String scope = servletConfig.getInitParameter(SERVICE_SCOPE_PARAM);
-        return SERVICE_SCOPE_SINGLETON.equals(scope);
+        if (scope != null) {
+            scope = (String)app.getProperties().get(SERVICE_SCOPE_PARAM);
+        }
+        return SERVICE_SCOPE_SINGLETON.equals(scope);    
     }
     
     protected Object createSingletonInstance(Class<?> cls, Map<String, List<String>>
props, ServletConfig sc)
@@ -504,11 +507,12 @@ public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
         for (String cName : classNames) {
             ApplicationInfo providerApp = createApplicationInfo(cName, servletConfig);
 
+            Application app = providerApp.getProvider();
             JAXRSServerFactoryBean bean = ResourceUtils.createApplication(
-                                                providerApp.getProvider(),
+                                                app,
                                                 ignoreApplicationPath,
                                                 getStaticSubResolutionValue(servletConfig),
-                                                isResourceLifecycleASingleton(servletConfig),
+                                                isAppResourceLifecycleASingleton(app, servletConfig),
                                                 getBus());
             String splitChar = getParameterSplitChar(servletConfig);
             setAllInterceptors(bean, servletConfig, splitChar);
@@ -530,11 +534,12 @@ public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
     protected void createServerFromApplication(ServletConfig servletConfig) 
         throws ServletException {
 
+        Application app = getApplication();
         JAXRSServerFactoryBean bean = ResourceUtils.createApplication(
-                                          getApplication(),
+                                          app,
                                           isIgnoreApplicationPath(servletConfig),
                                           getStaticSubResolutionValue(servletConfig),
-                                          isResourceLifecycleASingleton(servletConfig),
+                                          isAppResourceLifecycleASingleton(app, servletConfig),
                                           getBus());
         bean.setBus(getBus());
         bean.setApplication(getApplication());

http://git-wip-us.apache.org/repos/asf/cxf/blob/061e5476/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/sci/JaxrsServletContainerInitializer.java
----------------------------------------------------------------------
diff --git a/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/sci/JaxrsServletContainerInitializer.java
b/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/sci/JaxrsServletContainerInitializer.java
index d98122a..0108a0e 100644
--- a/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/sci/JaxrsServletContainerInitializer.java
+++ b/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/sci/JaxrsServletContainerInitializer.java
@@ -21,6 +21,7 @@ package org.apache.cxf.jaxrs.servlet.sci;
 import java.lang.annotation.Annotation;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -100,8 +101,10 @@ public class JaxrsServletContainerInitializer implements ServletContainerInitial
                     // Servlet mapping is obtained from a servlet registration 
                     // with a JAX-RS Application class name
                     servletMapping = getServletMapping(ctx, servletName);
-                } 
-                
+                }
+                final Map<String, Object> appProperties = 
+                    app != null ? app.getProperties() : Collections.<String, Object>emptyMap();
+
                 app = new Application() {
                     @Override
                     public Set<Class<?>> getClasses() {
@@ -110,6 +113,10 @@ public class JaxrsServletContainerInitializer implements ServletContainerInitial
                         set.addAll(providersAndResources.get(Provider.class));
                         return set;
                     }
+                    @Override
+                    public Map<String, Object> getProperties() {
+                        return appProperties;
+                    }
                 };
             }
         }


Mime
View raw message