cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1505717 - in /cxf/trunk: rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests/jaxrs/src/test/resources/jaxrs_spring_providers/WEB-INF/
Date Mon, 22 Jul 2013 15:25:53 GMT
Author: sergeyb
Date: Mon Jul 22 15:25:52 2013
New Revision: 1505717

URL: http://svn.apache.org/r1505717
Log:
[CXF-5144] Reusing the original ServletConfig reference

Added:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java
  (with props)
Modified:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_providers/WEB-INF/beans.xml
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_providers/WEB-INF/web.xml

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java?rev=1505717&r1=1505716&r2=1505717&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
Mon Jul 22 15:25:52 2013
@@ -22,10 +22,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Method;
 import java.util.Collection;
-import java.util.Enumeration;
 
 import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
 import org.apache.cxf.Bus;
@@ -50,18 +48,18 @@ public class CXFServlet extends CXFNonSp
     }
 
     @Override
-    protected void loadBus(ServletConfig sc) {
+    protected void loadBus(ServletConfig servletConfig) {
         ApplicationContext wac = WebApplicationContextUtils.
-            getWebApplicationContext(sc.getServletContext());
+            getWebApplicationContext(servletConfig.getServletContext());
         
         if (wac instanceof AbstractApplicationContext) {
             addListener((AbstractApplicationContext)wac);
         }
         
-        String configLocation = sc.getInitParameter("config-location");
+        String configLocation = servletConfig.getInitParameter("config-location");
         if (configLocation == null) {
             try {
-                InputStream is = sc.getServletContext().getResourceAsStream("/WEB-INF/cxf-servlet.xml");
+                InputStream is = servletConfig.getServletContext().getResourceAsStream("/WEB-INF/cxf-servlet.xml");
                 if (is != null && is.available() > 0) {
                     is.close();
                     configLocation = "/WEB-INF/cxf-servlet.xml";
@@ -71,7 +69,7 @@ public class CXFServlet extends CXFNonSp
             }
         }
         if (configLocation != null) {
-            wac = createSpringContext(wac, sc.getServletContext(), configLocation);
+            wac = createSpringContext(wac, servletConfig, configLocation);
         }
         if (wac != null) {
             setBus((Bus)wac.getBean("cxf", Bus.class));
@@ -104,24 +102,12 @@ public class CXFServlet extends CXFNonSp
      * @return
      */
     private ApplicationContext createSpringContext(ApplicationContext ctx,
-                                                   final ServletContext sc,
+                                                   ServletConfig servletConfig,
                                                    String location) {
         XmlWebApplicationContext ctx2 = new XmlWebApplicationContext();
         createdContext = ctx2;
-        ctx2.setServletConfig(new ServletConfig() {
-            public String getServletName() {
-                return "CXF";
-            }
-            public ServletContext getServletContext() {
-                return sc;
-            }
-            public String getInitParameter(String name) {
-                return sc.getInitParameter(name);
-            }
-            public Enumeration<String> getInitParameterNames() {
-                return sc.getInitParameterNames();
-            }
-        });
+        
+        ctx2.setServletConfig(servletConfig);
         Resource r = ctx2.getResource(location);
         try {
             InputStream in = r.getInputStream();

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java?rev=1505717&r1=1505716&r2=1505717&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
Mon Jul 22 15:25:52 2013
@@ -82,7 +82,7 @@ public class JAXRSClientServerResourceCr
     @Test
     public void testMultipleRootsWadl() throws Exception {
         List<Element> resourceEls = getWadlResourcesInfo("http://localhost:" + PORT
+ "/webapp/resources",
-                                                         "http://localhost:" + PORT + "/webapp/resources",
2);
+                                                         "http://localhost:" + PORT + "/webapp/resources",
3);
         String path1 = resourceEls.get(0).getAttribute("path");
         int bookStoreInd = path1.contains("/bookstore") ? 0 : 1;
         int petStoreInd = bookStoreInd == 0 ? 1 : 0;
@@ -149,6 +149,17 @@ public class JAXRSClientServerResourceCr
     }
     
     @Test
+    public void testServletConfigInitParam() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/webapp/resources/servlet/config/a"; 
+        WebClient wc = WebClient.create(endpointAddress);
+        wc.accept("text/plain");
+
+        assertEquals("avalue", wc.get(String.class));
+    }
+    
+    @Test
     public void testGetBook123() throws Exception {
         
         String endpointAddress =

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java?rev=1505717&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java
Mon Jul 22 15:25:52 2013
@@ -0,0 +1,42 @@
+/**
+ * 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.systest.jaxrs;
+
+import javax.servlet.ServletConfig;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+import org.springframework.web.context.ServletConfigAware;
+
+@Path("servlet")
+public class SpringServletConfigStore implements ServletConfigAware {
+    private ServletConfig servletConfig;
+    public void setServletConfig(ServletConfig sc) {
+        this.servletConfig = sc;
+    }
+
+    @GET
+    @Produces("text/plain")
+    @Path("config/{name}")
+    public String getServletConfigInitParam(@PathParam("name") String name) {
+        return servletConfig.getInitParameter(name);
+    }
+}

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_providers/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_providers/WEB-INF/beans.xml?rev=1505717&r1=1505716&r2=1505717&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_providers/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_providers/WEB-INF/beans.xml Mon
Jul 22 15:25:52 2013
@@ -32,6 +32,7 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
         <jaxrs:serviceBeans>
             <ref bean="petstore"/>
             <ref bean="bookstore"/>
+            <ref bean="servletconfigstore"/>
         </jaxrs:serviceBeans>
         <jaxrs:providers>
             <bean class="org.apache.cxf.systest.jaxrs.BadgerFishProvider"/>
@@ -40,8 +41,9 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
             <ref bean="plainTextProvider"/>
         </jaxrs:providers>
     </jaxrs:server>
-    <bean id="bookstore" scope="prototype" class="org.apache.cxf.systest.jaxrs.BookStore"/>
-    <bean id="petstore" scope="prototype" class="org.apache.cxf.systest.jaxrs.PetStore"/>
+    <bean id="bookstore" class="org.apache.cxf.systest.jaxrs.BookStore"/>
+    <bean id="petstore" class="org.apache.cxf.systest.jaxrs.PetStore"/>
+    <bean id="servletconfigstore" class="org.apache.cxf.systest.jaxrs.SpringServletConfigStore"/>
     <bean id="exceptionMapper" class="org.apache.cxf.systest.jaxrs.BookExceptionMapper">
         <property name="toHandle" value="true"/>
     </bean>   

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_providers/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_providers/WEB-INF/web.xml?rev=1505717&r1=1505716&r2=1505717&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_providers/WEB-INF/web.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_providers/WEB-INF/web.xml Mon
Jul 22 15:25:52 2013
@@ -32,6 +32,10 @@
 			org.apache.cxf.transport.servlet.CXFServlet
 		</servlet-class>
 		<init-param>
+		      <param-name>a</param-name>
+		      <param-value>avalue</param-value>    
+		</init-param>
+		<init-param>
 		      <param-name>config-location</param-name>
 		      <param-value>/WEB-INF/beans.xml</param-value>    
 		</init-param>



Mime
View raw message