You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2008/07/22 19:16:50 UTC

svn commit: r678808 - in /cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet: AbstractCXFServlet.java CXFServlet.java

Author: dkulp
Date: Tue Jul 22 10:16:49 2008
New Revision: 678808

URL: http://svn.apache.org/viewvc?rev=678808&view=rev
Log:
[CXF-1709] Detect the application context refresh and make sure we update the bus and servlet controller.


Modified:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java?rev=678808&r1=678807&r2=678808&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java Tue Jul 22 10:16:49 2008
@@ -110,7 +110,7 @@
         bus.getExtension(DestinationFactoryManager.class).registerDestinationFactory(namespace, factory);
     }
 
-    protected void replaceDestinationFactory() throws ServletException {
+    protected void replaceDestinationFactory() {
        
         DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class); 
         try {

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=678808&r1=678807&r2=678808&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 Tue Jul 22 10:16:49 2008
@@ -38,6 +38,10 @@
 import org.apache.cxf.resource.URIResolver;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.context.support.GenericApplicationContext;
 import org.springframework.core.io.InputStreamResource;
 
@@ -49,9 +53,11 @@
  * to the {@link ServletController}.
  *
  */
-public class CXFServlet extends AbstractCXFServlet {
+public class CXFServlet extends AbstractCXFServlet implements ApplicationListener {
     
     private GenericApplicationContext childCtx;
+    private boolean inRefresh;
+    
     
     public static Logger getLogger() {
         return LogUtils.getL7dLogger(CXFServlet.class);
@@ -92,7 +98,14 @@
             }                   
         }
         
-        // This constructor works whether there is a context or not
+        updateContext(servletConfig, ctx);
+
+        if (ctx instanceof ConfigurableApplicationContext) {
+            ((ConfigurableApplicationContext)ctx).addApplicationListener(this);
+        }
+    }
+    private void updateContext(ServletConfig servletConfig, ApplicationContext ctx) {
+     // This constructor works whether there is a context or not
         // If the ctx is null, we just start up the default bus
         if (ctx == null) {            
             LOG.info("LOAD_BUS_WITHOUT_APPLICATION_CONTEXT");
@@ -101,7 +114,8 @@
         } else {
             LOG.info("LOAD_BUS_WITH_APPLICATION_CONTEXT");
             bus = new SpringBusFactory(ctx).createBus();
-        }
+        }        
+        
         ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
         resourceManager.addResourceResolver(new ServletContextResourceResolver(
                                                servletConfig.getServletContext()));
@@ -116,7 +130,7 @@
     }
 
     private void loadAdditionalConfig(ApplicationContext ctx, 
-                                        ServletConfig servletConfig) throws ServletException {
+                                        ServletConfig servletConfig) {
         String location = servletConfig.getInitParameter("config-location");
         if (location == null) {
             location = "/WEB-INF/cxf-servlet.xml";
@@ -155,5 +169,18 @@
         super.destroy();        
     }
 
+    public void onApplicationEvent(ApplicationEvent event) {
+        if (!inRefresh && event instanceof ContextRefreshedEvent) {
+            //need to re-do the bus/controller stuff
+            try {
+                inRefresh = true;
+                updateContext(this.getServletConfig(), 
+                          ((ContextRefreshedEvent)event).getApplicationContext());
+            } finally {
+                inRefresh = false;
+            }
+        }
+    }
+
     
 }