cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Adding few CXFNonSpringJaxrsServ; et utility constructors
Date Mon, 19 Jan 2015 12:37:07 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes c1f9d044c -> fd5c804a5


Adding few CXFNonSpringJaxrsServ;et utility constructors


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

Branch: refs/heads/3.0.x-fixes
Commit: fd5c804a5041e9b57c7414442c1ad41d8c7c709a
Parents: c1f9d04
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Mon Jan 19 12:36:02 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Mon Jan 19 12:36:51 2015 +0000

----------------------------------------------------------------------
 .../jaxrs/servlet/CXFNonSpringJaxrsServlet.java | 55 +++++++++++++++++++-
 1 file changed, 53 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/fd5c804a/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 ca9aea7..db5b379 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
@@ -28,6 +28,7 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.servlet.ServletConfig;
@@ -89,11 +90,32 @@ public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
     private static final String JAXRS_APPLICATION_PARAM = "javax.ws.rs.Application";
     
     private ClassLoader classLoader;
+    private Application application;
+    
+    public CXFNonSpringJaxrsServlet() {
+        
+    }
+    
+    public CXFNonSpringJaxrsServlet(Application app) {
+        this.application = app;
+    }
+    
+    public CXFNonSpringJaxrsServlet(Object singletonService) {
+        this(Collections.singleton(singletonService));
+    }
+    public CXFNonSpringJaxrsServlet(Set<Object> applicationSingletones) {
+        this(new ApplicationImpl(applicationSingletones));
+    }
     
     @Override
     public void init(ServletConfig servletConfig) throws ServletException {
         super.init(servletConfig);
         
+        if (getApplication() != null) {
+            createServerFromApplication(servletConfig);
+            return; 
+        }
+        
         String applicationClass = servletConfig.getInitParameter(JAXRS_APPLICATION_PARAM);
         if (applicationClass != null) {
             createServerFromApplication(applicationClass, servletConfig);
@@ -463,8 +485,7 @@ public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
     protected void createServerFromApplication(String applicationNames, ServletConfig servletConfig)

         throws ServletException {
         
-        String ignoreParam = servletConfig.getInitParameter(IGNORE_APP_PATH_PARAM);
-        boolean ignoreApplicationPath = ignoreParam == null || MessageUtils.isTrue(ignoreParam);
+        boolean ignoreApplicationPath = isIgnoreApplicationPath(servletConfig);
         
         String[] classNames = StringUtils.split(applicationNames, getParameterSplitChar(servletConfig));
         
@@ -491,6 +512,22 @@ public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
         }
     }
     
+    protected boolean isIgnoreApplicationPath(ServletConfig servletConfig) {
+        String ignoreParam = servletConfig.getInitParameter(IGNORE_APP_PATH_PARAM);
+        return ignoreParam == null || MessageUtils.isTrue(ignoreParam);
+    }    
+    
+    protected void createServerFromApplication(ServletConfig servletConfig) 
+        throws ServletException {
+        
+        JAXRSServerFactoryBean bean = ResourceUtils.createApplication(getApplication(), 
+                                                                      isIgnoreApplicationPath(servletConfig),
+                                                                      getStaticSubResolutionValue(servletConfig));
+        bean.setBus(getBus());
+        bean.setApplication(getApplication());
+        bean.create();
+    }
+    
     protected Application createApplicationInstance(String appClassName, ServletConfig servletConfig)
         throws ServletException {
         return null;
@@ -546,4 +583,18 @@ public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
     public void setClassLoader(ClassLoader loader) {
         this.classLoader = loader;
     }
+    
+    protected Application getApplication() {
+        return application;
+    }
+
+    private static class ApplicationImpl extends Application {
+        private Set<Object> applicationSingletones;
+        public ApplicationImpl(Set<Object> applicationSingletones) {
+            this.applicationSingletones = applicationSingletones;
+        }
+        public Set<Object> getSingletons() {
+            return applicationSingletones;
+        }
+    }
 }


Mime
View raw message