cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1089298 - in /cxf/trunk/rt: core/src/main/java/org/apache/cxf/bus/spring/ transports/http/src/main/java/org/apache/cxf/transport/servlet/
Date Wed, 06 Apr 2011 04:54:53 GMT
Author: dkulp
Date: Wed Apr  6 04:54:53 2011
New Revision: 1089298

URL: http://svn.apache.org/viewvc?rev=1089298&view=rev
Log:
Restore some compatibility with previous cxf-servlet configs

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/Jsr250BeanPostProcessor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java?rev=1089298&r1=1089297&r2=1089298&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java
Wed Apr  6 04:54:53 2011
@@ -53,6 +53,14 @@ public class BusApplicationContextResour
                 //ignore and return null
             }
         } 
+        r = context.getResource("/" + name);
+        if (r != null && r.exists()) {
+            try {
+                return r.getInputStream();
+            } catch (IOException e) {
+                //ignore and return null
+            }
+        } 
         return null;
     }
 
@@ -71,6 +79,7 @@ public class BusApplicationContextResour
             } else if (URL.class.isAssignableFrom(resourceType)) {
                 Resource r = context.getResource(resourceName);
                 if (r != null && r.exists()) {
+                    r.getInputStream().close(); //checks to see if the URL really can resolve
                     return resourceType.cast(r.getURL());
                 }
             }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/Jsr250BeanPostProcessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/Jsr250BeanPostProcessor.java?rev=1089298&r1=1089297&r2=1089298&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/Jsr250BeanPostProcessor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/Jsr250BeanPostProcessor.java
Wed Apr  6 04:54:53 2011
@@ -71,18 +71,22 @@ public class Jsr250BeanPostProcessor 
                 resourceManager.addResourceResolver(new BusApplicationContextResourceResolver(context));
             } else {
                 ResourceManager m = null;
+                Bus b = null;
                 try {
                     m = (ResourceManager)context.getBean(ResourceManager.class.getName());
                 } catch (NoSuchBeanDefinitionException t) {
                     //ignore - no resource manager
                 }
                 if (resourceManager == null && m == null) {
-                    Bus b = (Bus)context.getBean("cxf");
+                    b = (Bus)context.getBean("cxf");
                     m = b.getExtension(ResourceManager.class);
                 }
                 if (resourceManager == null && m != null) {
                     resourceManager = m;
-                    resourceManager.addResourceResolver(new BusApplicationContextResourceResolver(context));
+                    if (!(b instanceof SpringBus)) {
+                        resourceManager
+                            .addResourceResolver(new BusApplicationContextResourceResolver(context));
+                    }
                 }
             }
             isProcessing = temp;
@@ -108,7 +112,9 @@ public class Jsr250BeanPostProcessor 
         if (!isProcessing) {
             return bean;
         }
-        
+        if (bean instanceof Bus) {
+            getResourceManager(bean);
+        }
         /*
         if (bean.getClass().getName().contains("Corb")) {
             Thread.dumpStack();

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java?rev=1089298&r1=1089297&r2=1089298&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java Wed Apr  6 04:54:53
2011
@@ -23,6 +23,7 @@ import org.apache.cxf.bus.extension.Exte
 import org.apache.cxf.buslifecycle.BusLifeCycleManager;
 import org.apache.cxf.configuration.Configurer;
 import org.apache.cxf.configuration.spring.ConfigurerImpl;
+import org.apache.cxf.resource.ResourceManager;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
@@ -56,6 +57,9 @@ public class SpringBus extends Extension
             ac = ac.getParent();
         }
         setExtension(new ConfigurerImpl(applicationContext), Configurer.class);
+        
+        ResourceManager m = getExtension(ResourceManager.class);
+        m.addResourceResolver(new BusApplicationContextResourceResolver(applicationContext));
     }
 
     public void onApplicationEvent(ApplicationEvent event) {

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=1089298&r1=1089297&r2=1089298&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
Wed Apr  6 04:54:53 2011
@@ -18,18 +18,17 @@
  */
 package org.apache.cxf.transport.servlet;
 
+import java.io.IOException;
 import java.io.InputStream;
 
 import javax.servlet.ServletConfig;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-import org.springframework.context.support.GenericApplicationContext;
-import org.springframework.core.io.InputStreamResource;
+import org.springframework.core.io.Resource;
 import org.springframework.web.context.support.WebApplicationContextUtils;
+import org.springframework.web.context.support.XmlWebApplicationContext;
 
 public class CXFServlet extends CXFNonSpringServlet {
 
@@ -41,8 +40,19 @@ public class CXFServlet extends CXFNonSp
         ApplicationContext wac = WebApplicationContextUtils.
             getWebApplicationContext(sc.getServletContext());
         String configLocation = sc.getInitParameter("config-location");
-        if (wac == null && (configLocation != null)) {
-            wac = createSpringContext(sc, configLocation);
+        if (configLocation == null) {
+            try {
+                InputStream is = sc.getServletContext().getResourceAsStream("/WEB-INF/cxf-servlet.xml");
+                if (is != null && is.available() > 0) {
+                    is.close();
+                    configLocation = "/WEB-INF/cxf-servlet.xml";
+                }
+            } catch (Exception ex) {
+                //ignore
+            }
+        }
+        if (configLocation != null) {
+            wac = createSpringContext(wac, sc, configLocation);
         }
         if (wac != null) {
             setBus(wac.getBean("cxf", Bus.class));
@@ -56,22 +66,53 @@ public class CXFServlet extends CXFNonSp
      * Will first try to resolve the location using the servlet context.
      * If that does not work then the location is given as is to spring
      * 
+     * @param ctx
      * @param sc
      * @param configLocation
      * @return
      */
-    private ApplicationContext createSpringContext(ServletConfig sc, String configLocation)
{
-        InputStream is = sc.getServletContext().getResourceAsStream(configLocation);
-        if (is != null) {
-            GenericApplicationContext ctx = new GenericApplicationContext();
-            XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
-            reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
-            reader.loadBeanDefinitions(new InputStreamResource(is, configLocation));
-            ctx.refresh();
-            return ctx;
+    private ApplicationContext createSpringContext(ApplicationContext ctx,
+                                                   ServletConfig sc,
+                                                   String location) {
+        XmlWebApplicationContext ctx2 = new XmlWebApplicationContext();
+        ctx2.setServletConfig(sc);
+
+        Resource r = ctx2.getResource(location);
+        try {
+            InputStream in = r.getInputStream();
+            in.close();
+        } catch (IOException e) {
+            //ignore
+            r = ctx2.getResource("classpath:" + location);
+            try {
+                r.getInputStream().close();
+            } catch (IOException e2) {
+                //ignore
+                r = null;
+            }
+        }
+        try {
+            if (r != null) {
+                location = r.getURL().toExternalForm();
+            }
+        } catch (IOException e) {
+            //ignore
+        }        
+        if (ctx != null) {
+            ctx2.setParent(ctx);
+            String names[] = ctx.getBeanNamesForType(Bus.class);
+            if (names == null || names.length == 0) {
+                ctx2.setConfigLocations(new String[] {"classpath:/META-INF/cxf/cxf.xml",
+                                                      location});                
+            } else {
+                ctx2.setConfigLocations(new String[] {location});                       
        
+            }
         } else {
-            return new ClassPathXmlApplicationContext(configLocation);
+            ctx2.setConfigLocations(new String[] {"classpath:/META-INF/cxf/cxf.xml",
+                                                  location});            
         }
+        ctx2.refresh();
+        return ctx2;
     }
 
 }



Mime
View raw message