cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r590640 - in /incubator/cxf/branches/2.0.x-fixes: ./ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ systests/src/test/java/org/apache/cxf/systest/servlet/
Date Wed, 31 Oct 2007 12:19:02 GMT
Author: dkulp
Date: Wed Oct 31 05:19:01 2007
New Revision: 590640

URL: http://svn.apache.org/viewvc?rev=590640&view=rev
Log:
Merged revisions 590565 via svnmerge from 
https://svn.apache.org/repos/asf/incubator/cxf/trunk

........
  r590565 | ningjiang | 2007-10-31 01:40:03 -0400 (Wed, 31 Oct 2007) | 1 line
  
  CXF-1072 Added CXFNonSpringServlet for using ServletTransport without Spring
........

Added:
    incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
      - copied unchanged from r590565, incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
    incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
      - copied unchanged from r590565, incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
    incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
      - copied unchanged from r590565, incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
    incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
      - copied unchanged from r590565, incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
    incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/Messages.properties
    incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java

Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java?rev=590640&r1=590639&r2=590640&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
Wed Oct 31 05:19:01 2007
@@ -21,29 +21,20 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.ref.WeakReference;
-import java.util.Hashtable;
-import java.util.Map;
+
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusException;
-import org.apache.cxf.BusFactory;
+
+
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.resource.ResourceManager;
 import org.apache.cxf.resource.URIResolver;
-import org.apache.cxf.transport.DestinationFactory;
-import org.apache.cxf.transport.DestinationFactoryManager;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.GenericApplicationContext;
@@ -57,82 +48,26 @@
  * to the {@link ServletController}.
  *
  */
-public class CXFServlet extends HttpServlet {
-    static final Map<String, WeakReference<Bus>> BUS_MAP = new Hashtable<String,
WeakReference<Bus>>();
-    static final Logger LOG = LogUtils.getL7dLogger(CXFServlet.class);
+public class CXFServlet extends AbstractCXFServlet {
     
-    private Bus bus;
-    private ServletTransportFactory servletTransportFactory;
-    private ServletController controller;
-    private Object childCtx;
-    private Object reader;
+    private GenericApplicationContext childCtx;
     
-   
-    public ServletController createServletController(ServletConfig servletConfig) {
-        String hideServiceList = servletConfig.getInitParameter("hide-service-list-page");
-        ServletController newController = new ServletController(servletTransportFactory,
this);
-        if (hideServiceList != null) {
-            newController.setHideServiceList(Boolean.valueOf(hideServiceList));
-        }    
-        return newController;
-    }
-
-    public ServletController getController() {
-        return controller;
+    public static Logger getLogger() {
+        return LogUtils.getL7dLogger(CXFServlet.class);
     }
     
-    public Bus getBus() {
-        return bus;
-    }
-
-    public void init(ServletConfig servletConfig) throws ServletException {
-        super.init(servletConfig);
-
+    public void loadBus(ServletConfig servletConfig) throws ServletException {
+        String springCls = "org.springframework.context.ApplicationContext";
         try {
-            BusFactory.setThreadDefaultBus(null);
-    
-            String busid = servletConfig.getInitParameter("bus.id");
-            if (null != busid) {
-                WeakReference<Bus> ref = BUS_MAP.get(busid);
-                if (null != ref) {
-                    bus = ref.get();
-                    BusFactory.setThreadDefaultBus(bus);
-                }
-            }
-            
-            String springCls = "org.springframework.context.ApplicationContext";
-            try {
-                ClassLoaderUtils.loadClass(springCls, getClass());
-                loadSpringBus(servletConfig);
-            } catch (ClassNotFoundException e) {                
-                loadBusNoConfig(servletConfig);
-            }
-                
-                
-            if (null != busid) {
-                BUS_MAP.put(busid, new WeakReference<Bus>(bus));
-            }
-        } finally {
-            BusFactory.setThreadDefaultBus(null);
+            ClassLoaderUtils.loadClass(springCls, getClass());
+            loadSpringBus(servletConfig);
+        } catch (ClassNotFoundException e) {                
+            LOG.log(Level.SEVERE, "FAILED_TO_LOAD_SPRING_BUS", new Object[]{e});
+            new ServletException("Can't load bus with Spring context class", e);
         }
     }
     
-    private void loadBusNoConfig(ServletConfig servletConfig) throws ServletException {
-        
-        if (bus == null) {
-            LOG.info("LOAD_BUS_WITHOUT_APPLICATION_CONTEXT");
-            bus = BusFactory.newInstance().createBus();
-        }
-        ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
-        resourceManager.addResourceResolver(new ServletContextResourceResolver(
-                                               servletConfig.getServletContext()));
-                        
-        replaceDestinationFactory();
-        // Set up the ServletController
-        controller = createServletController(servletConfig);
-        
-    }
-
+    
     private void loadSpringBus(ServletConfig servletConfig) throws ServletException {
         
         // try to pull an existing ApplicationContext out of the
@@ -203,90 +138,20 @@
             LOG.log(Level.INFO, "BUILD_ENDPOINTS_FROM_CONFIG_LOCATION", new Object[]{location});
             childCtx = new GenericApplicationContext(ctx);
             
-            reader = 
-                new XmlBeanDefinitionReader(
-                    (GenericApplicationContext)childCtx);
-            ((XmlBeanDefinitionReader)reader).setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
-            ((XmlBeanDefinitionReader)reader).loadBeanDefinitions(new InputStreamResource(is,
location));
+            XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(childCtx);
+            reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
+            reader.loadBeanDefinitions(new InputStreamResource(is, location));
             
-            ((GenericApplicationContext)childCtx).refresh();
+            childCtx.refresh();
         } 
     }
 
-    /**
-     * @return
-     */
-    protected DestinationFactory createServletTransportFactory() {
-        if (servletTransportFactory == null) {
-            servletTransportFactory = new ServletTransportFactory(bus);
-        }
-        return servletTransportFactory;
-    }
-
-    private void registerTransport(DestinationFactory factory, String namespace) {
-        bus.getExtension(DestinationFactoryManager.class).registerDestinationFactory(namespace,
factory);
-    }
-
-    private void replaceDestinationFactory() throws ServletException {
-       
-        DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);

-        try {
-            DestinationFactory df = dfm
-                .getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
-            if (df instanceof ServletTransportFactory) {
-                servletTransportFactory = (ServletTransportFactory)df;
-                LOG.info("DESTIONFACTORY_ALREADY_REGISTERED");
-                return;
-            }
-        } catch (BusException e) {
-            // why are we throwing a busexception if the DF isn't found?
-        }
-
-        
-        DestinationFactory factory = createServletTransportFactory();
-
-        for (String s : factory.getTransportIds()) {
-            registerTransport(factory, s);
-        }
-        LOG.info("REPLACED_HTTP_DESTIONFACTORY");
-    }
-
     public void destroy() {
         if (childCtx != null) {
-            ((GenericApplicationContext)childCtx).destroy();
+            childCtx.destroy();
         }
-        
-        String s = bus.getId();
-        BUS_MAP.remove(s);
-        bus.shutdown(true);
-    }
-
-    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
-        invoke(request, response);
-    }
-
-    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
-        invoke(request, response);
+        super.destroy();        
     }
 
-    @Override
-    protected void doDelete(HttpServletRequest request, HttpServletResponse response)
-        throws ServletException, IOException {
-        invoke(request, response);
-    }
-
-    @Override
-    protected void doPut(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
-        IOException {
-        invoke(request, response);
-    }
     
-    private  void invoke(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
-        try {
-            BusFactory.setThreadDefaultBus(getBus());
-            controller.invoke(request, response);
-        } finally {
-            BusFactory.setThreadDefaultBus(null);
-        }
-    }
 }

Modified: incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/Messages.properties?rev=590640&r1=590639&r2=590640&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/Messages.properties
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/Messages.properties
Wed Oct 31 05:19:01 2007
@@ -18,10 +18,11 @@
 #    under the License.
 #
 #
-LOAD_BUS_WITHOUT_APPLICATION_CONTEXT = load the bus without application context
-LOAD_BUS_WITH_APPLICATION_CONTEXT = load the bus with application context
-REPLACED_HTTP_DESTIONFACTORY = replaced the http destionFactory with servlet transport factory
-BUILD_ENDPOINTS_FROM_CONFIG_LOCATION = build endpoints from config-location: {0}
-DESTIONFACTORY_ALREADY_REGISTERED = servlet transport factory already registered 
+LOAD_BUS_WITHOUT_APPLICATION_CONTEXT = Load the bus without application context
+LOAD_BUS_WITH_APPLICATION_CONTEXT = Load the bus with application context
+REPLACED_HTTP_DESTIONFACTORY = Replaced the http destionFactory with servlet transport factory
+BUILD_ENDPOINTS_FROM_CONFIG_LOCATION = Build endpoints from config-location: {0}
+DESTIONFACTORY_ALREADY_REGISTERED = Servlet transport factory already registered 
 UNEXPECTED_RESPONSE_TYPE_MSG = Unexpected response type {0}
 DECOUPLED_RESPONSE_FAILED_MSG = Decouple response failed
+FAILED_TO_LOAD_SPRING_BUS = Failed to load the spring bus: {0}

Modified: incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=590640&r1=590639&r2=590640&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
Wed Oct 31 05:19:01 2007
@@ -52,11 +52,11 @@
     private static final Logger LOG = LogUtils.getL7dLogger(ServletController.class);
 
     private ServletTransportFactory transport;
-    private CXFServlet cxfServlet;
+    private AbstractCXFServlet cxfServlet;
     private String lastBase = "";
     private boolean isHideServiceList;
  
-    public ServletController(ServletTransportFactory df, CXFServlet servlet) {
+    public ServletController(ServletTransportFactory df, AbstractCXFServlet servlet) {
         this.transport = df;
         this.cxfServlet = servlet;       
     }



Mime
View raw message