cxf git commit: [CXF-6132] More changes to JaxrsServletContainerInitializer
Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 8a06e66a3 -> 94fd3cfdf [CXF-6132] More changes to JaxrsServletContainerInitializer Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/94fd3cfd Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/94fd3cfd Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/94fd3cfd Branch: refs/heads/3.0.x-fixes Commit: 94fd3cfdf6c6896482ae48a8e90006f214967fa3 Parents: 8a06e66 Author: Sergey Beryozkin Authored: Wed Jan 28 13:32:51 2015 + Committer: Sergey Beryozkin Committed: Wed Feb 11 10:26:55 2015 + -- .../JaxrsServletContainerInitializer.java | 125 +++ 1 file changed, 99 insertions(+), 26 deletions(-) -- http://git-wip-us.apache.org/repos/asf/cxf/blob/94fd3cfd/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java -- diff --git a/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java b/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java index 4eb3575..4f7f42b 100644 --- a/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java +++ b/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java @@ -22,6 +22,7 @@ import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.logging.Logger; @@ -29,8 +30,10 @@ import java.util.logging.Logger; import javax.servlet.ServletContainerInitializer; import javax.servlet.ServletContext; import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; import javax.servlet.ServletRegistration.Dynamic; import javax.servlet.annotation.HandlesTypes; +import javax.ws.rs.ApplicationPath; import javax.ws.rs.Path; import javax.ws.rs.core.Application; import javax.ws.rs.ext.Provider; @@ -42,29 +45,111 @@ public class JaxrsServletContainerInitializer implements ServletContainerInitial private static final Logger LOG = LogUtils.getL7dLogger(JaxrsServletContainerInitializer.class); private static final String IGNORE_PACKAGE = "org.apache.cxf"; -private static final String IGNORE_APP_PATH_PARAM = "jaxrs.application.address.ignore"; -private static final String SERVICE_CLASSES_PARAM = "jaxrs.serviceClasses"; -private static final String PROVIDERS_PARAM = "jaxrs.providers"; private static final String JAXRS_APPLICATION_PARAM = "javax.ws.rs.Application"; - +private static final String CXF_JAXRS_APPLICATION_PARAM = "jaxrs.application"; +private static final String CXF_JAXRS_CLASSES_PARAM = "jaxrs.classes"; + @Override public void onStartup(final Set< Class< ? > > classes, final ServletContext ctx) throws ServletException { -final Dynamic servlet = ctx.addServlet("CXFServlet", CXFNonSpringJaxrsServlet.class); -servlet.addMapping("/*"); +Application app = null; +String servletName = null; +String servletMapping = null; -final Class< ? > application = findCandidate(classes); -if (application != null) { -servlet.setInitParameter(JAXRS_APPLICATION_PARAM, application.getName()); -servlet.setInitParameter(IGNORE_APP_PATH_PARAM, "false"); -} else { +final Class< ? > appClass = findCandidate(classes); +if (appClass != null) { +// The best effort at detecting a CXFNonSpringJaxrsServlet handling this application. +// Custom servlets using non-standard mechanisms to create Application will not be detected +if (isApplicationServletAvailable(ctx, appClass)) { +return; +} +try { +app = (Application)appClass.newInstance(); +} catch (Throwable t) { +throw new ServletException(t); +} +// Servlet name is the application class name +servletName = appClass.getName(); +ApplicationPath appPath = appClass.getAnnotation(ApplicationPath.class); +// If ApplicationPath is available - use its value as a mapping otherwise get it from +// a servlet registration with an application implementation class name +if (appPath != null) { +servletMapping = appPath.value() + "/*"; +} else { +servletMapping = getServletMapping(ctx, servletName); +} +} +// If application is null or empty then try to create a new application from
cxf git commit: [CXF-6132] More changes to JaxrsServletContainerInitializer
Repository: cxf Updated Branches: refs/heads/master 2cb99eed1 -> d021b9041 [CXF-6132] More changes to JaxrsServletContainerInitializer Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d021b904 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d021b904 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d021b904 Branch: refs/heads/master Commit: d021b9041e00518099947274455b2027326a3c7c Parents: 2cb99ee Author: Sergey Beryozkin Authored: Wed Jan 28 13:32:51 2015 + Committer: Sergey Beryozkin Committed: Wed Jan 28 13:32:51 2015 + -- .../JaxrsServletContainerInitializer.java | 125 +++ 1 file changed, 99 insertions(+), 26 deletions(-) -- http://git-wip-us.apache.org/repos/asf/cxf/blob/d021b904/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java -- diff --git a/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java b/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java index 4eb3575..4f7f42b 100644 --- a/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java +++ b/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java @@ -22,6 +22,7 @@ import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.logging.Logger; @@ -29,8 +30,10 @@ import java.util.logging.Logger; import javax.servlet.ServletContainerInitializer; import javax.servlet.ServletContext; import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; import javax.servlet.ServletRegistration.Dynamic; import javax.servlet.annotation.HandlesTypes; +import javax.ws.rs.ApplicationPath; import javax.ws.rs.Path; import javax.ws.rs.core.Application; import javax.ws.rs.ext.Provider; @@ -42,29 +45,111 @@ public class JaxrsServletContainerInitializer implements ServletContainerInitial private static final Logger LOG = LogUtils.getL7dLogger(JaxrsServletContainerInitializer.class); private static final String IGNORE_PACKAGE = "org.apache.cxf"; -private static final String IGNORE_APP_PATH_PARAM = "jaxrs.application.address.ignore"; -private static final String SERVICE_CLASSES_PARAM = "jaxrs.serviceClasses"; -private static final String PROVIDERS_PARAM = "jaxrs.providers"; private static final String JAXRS_APPLICATION_PARAM = "javax.ws.rs.Application"; - +private static final String CXF_JAXRS_APPLICATION_PARAM = "jaxrs.application"; +private static final String CXF_JAXRS_CLASSES_PARAM = "jaxrs.classes"; + @Override public void onStartup(final Set< Class< ? > > classes, final ServletContext ctx) throws ServletException { -final Dynamic servlet = ctx.addServlet("CXFServlet", CXFNonSpringJaxrsServlet.class); -servlet.addMapping("/*"); +Application app = null; +String servletName = null; +String servletMapping = null; -final Class< ? > application = findCandidate(classes); -if (application != null) { -servlet.setInitParameter(JAXRS_APPLICATION_PARAM, application.getName()); -servlet.setInitParameter(IGNORE_APP_PATH_PARAM, "false"); -} else { +final Class< ? > appClass = findCandidate(classes); +if (appClass != null) { +// The best effort at detecting a CXFNonSpringJaxrsServlet handling this application. +// Custom servlets using non-standard mechanisms to create Application will not be detected +if (isApplicationServletAvailable(ctx, appClass)) { +return; +} +try { +app = (Application)appClass.newInstance(); +} catch (Throwable t) { +throw new ServletException(t); +} +// Servlet name is the application class name +servletName = appClass.getName(); +ApplicationPath appPath = appClass.getAnnotation(ApplicationPath.class); +// If ApplicationPath is available - use its value as a mapping otherwise get it from +// a servlet registration with an application implementation class name +if (appPath != null) { +servletMapping = appPath.value() + "/*"; +} else { +servletMapping = getServletMapping(ctx, servletName); +} +} +// If application is null or empty then try to create a new application from available