cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1101399 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/
Date Tue, 10 May 2011 10:53:23 GMT
Author: sergeyb
Date: Tue May 10 10:53:23 2011
New Revision: 1101399

URL: http://svn.apache.org/viewvc?rev=1101399&view=rev
Log:
[CXF-3507] Support for Application constructor injection

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java?rev=1101399&r1=1101398&r2=1101399&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
Tue May 10 10:53:23 2011
@@ -257,18 +257,7 @@ public class CXFNonSpringJaxrsServlet ex
     protected void createServerFromApplication(String cName, ServletConfig servletConfig)

         throws ServletException {
         Class<?> appClass = loadClass(cName, "Application");
-        Application app = null;
-        try {
-            app = (Application)appClass.newInstance();
-        } catch (InstantiationException ex) {
-            ex.printStackTrace();
-            throw new ServletException("Application class " + cName
-                                       + " can not be instantiated"); 
-        } catch (IllegalAccessException ex) {
-            ex.printStackTrace();
-            throw new ServletException("Application class " + cName
-                                       + " can not be instantiated due to IllegalAccessException");

-        }
+        Application app = (Application)createSingletonInstance(appClass, servletConfig);
         
         String ignoreParam = servletConfig.getInitParameter(IGNORE_APP_PATH_PARAM);
         JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, MessageUtils.isTrue(ignoreParam));

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java?rev=1101399&r1=1101398&r2=1101399&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
Tue May 10 10:53:23 2011
@@ -21,12 +21,23 @@ package org.apache.cxf.systest.jaxrs;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.servlet.ServletContext;
 import javax.ws.rs.ApplicationPath;
 import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Context;
 
 @ApplicationPath("/thebooks")
 public class BookApplication extends Application {
 
+    public BookApplication(@Context ServletContext sc) {
+        if (sc == null) {
+            throw new IllegalArgumentException("ServletContext is null");
+        }
+        if (!"contextParamValue".equals(sc.getInitParameter("contextParam"))) {
+            throw new IllegalStateException("ServletContext is not initialized");
+        }
+    }
+    
     @Override
     public Set<Class<?>> getClasses() {
         Set<Class<?>> classes = new HashSet<Class<?>>();

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml?rev=1101399&r1=1101398&r2=1101399&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml Tue May 10
10:53:23 2011
@@ -24,6 +24,10 @@
 -->
 <!-- START SNIPPET: webxml -->
 <web-app>
+    <context-param>
+      <param-name>contextParam</param-name>
+      <param-value>contextParamValue</param-value>
+    </context-param>
 	<servlet>
 		<servlet-name>CXFServlet</servlet-name>
 		<display-name>CXF Servlet</display-name>



Mime
View raw message