cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r590565 - in /incubator/cxf/trunk: 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 05:40:04 GMT
Author: ningjiang
Date: Tue Oct 30 22:40:03 2007
New Revision: 590565

URL: http://svn.apache.org/viewvc?rev=590565&view=rev
Log:
CXF-1072 Added CXFNonSpringServlet for using ServletTransport without Spring

Added:
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
  (with props)
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
  (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
  (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/Messages.properties
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java

Added: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java?rev=590565&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
(added)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
Tue Oct 30 22:40:03 2007
@@ -0,0 +1,168 @@
+/**
+ * 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.transport.servlet;
+
+import java.io.IOException;
+import java.lang.ref.WeakReference;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletConfig;
+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.common.logging.LogUtils;
+import org.apache.cxf.transport.DestinationFactory;
+import org.apache.cxf.transport.DestinationFactoryManager;
+
+
+
+public abstract class AbstractCXFServlet extends HttpServlet {
+    static final Map<String, WeakReference<Bus>> BUS_MAP = new Hashtable<String,
WeakReference<Bus>>();
+    static final Logger LOG = getLogger();
+    
+    protected Bus bus;
+    protected ServletTransportFactory servletTransportFactory;
+    protected ServletController controller;
+    
+    public static Logger getLogger() {
+        return LogUtils.getL7dLogger(AbstractCXFServlet.class);
+    }
+    
+    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 void init(ServletConfig servletConfig) throws ServletException {
+        super.init(servletConfig);
+
+        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);
+                }
+            }
+            
+            loadBus(servletConfig);
+                
+            if (null != busid) {
+                BUS_MAP.put(busid, new WeakReference<Bus>(bus));
+            }
+        } finally {
+            BusFactory.setThreadDefaultBus(null);
+        }
+    }
+    
+    public abstract void loadBus(ServletConfig servletConfig) throws ServletException;  
 
+   
+    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);
+    }
+
+    protected 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 ServletController getController() {
+        return controller;
+    }
+    
+    public Bus getBus() {
+        return bus;
+    }
+    
+    public void 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);
+    }
+
+    @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);
+        }
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java?rev=590565&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
(added)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
Tue Oct 30 22:40:03 2007
@@ -0,0 +1,58 @@
+/**
+ * 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.transport.servlet;
+
+import java.util.logging.Logger;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.resource.ResourceManager;
+
+public class CXFNonSpringServlet extends AbstractCXFServlet {
+    
+    public static Logger getLogger() {
+        return LogUtils.getL7dLogger(CXFNonSpringServlet.class);
+    }
+
+    @Override
+    public void loadBus(ServletConfig servletConfig) throws ServletException {
+        loadBusNoConfig(servletConfig);
+        //TODO do we need to privde the SUN's endpoint discription file supporting      
 
+    }
+    
+    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);
+        
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java?rev=590565&r1=590564&r2=590565&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
Tue Oct 30 22:40:03 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/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/Messages.properties?rev=590565&r1=590564&r2=590565&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/Messages.properties
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/Messages.properties
Tue Oct 30 22:40:03 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/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=590565&r1=590564&r2=590565&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
Tue Oct 30 22:40:03 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;       
     }

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java?rev=590565&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
Tue Oct 30 22:40:03 2007
@@ -0,0 +1,70 @@
+/**
+ * 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.servlet;
+
+import java.lang.reflect.UndeclaredThrowableException;
+import java.net.URL;
+import javax.xml.namespace.QName;
+
+import com.meterware.httpunit.WebConversation;
+import com.meterware.httpunit.WebLink;
+import com.meterware.httpunit.WebResponse;
+
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.hello_world_soap_http.Greeter;
+import org.apache.hello_world_soap_http.SOAPService;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+
+public class NoSpringServletClientTest extends AbstractBusClientServerTestBase {
+    private final QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapPort");
+    private final String serviceURL = "http://localhost:9000/soap/";
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", launchServer(NoSpringServletServer.class));
+    }
+    
+    @Test
+    public void testBasicConnection() throws Exception {
+        SOAPService service = new SOAPService(new URL(serviceURL + "Greeter?wsdl"));
+        Greeter greeter = service.getPort(portName, Greeter.class);        
+        try {
+            String reply = greeter.greetMe("test");
+            assertNotNull("no response received from service", reply);
+            assertEquals("Hello test", reply);
+            reply = greeter.sayHi();
+            assertNotNull("no response received from service", reply);
+            assertEquals("Bonjour", reply);
+        } catch (UndeclaredThrowableException ex) {
+            throw (Exception)ex.getCause();
+        }
+    }
+    
+    @Test
+    public void testGetServiceList() throws Exception {
+        WebConversation client = new WebConversation();
+        WebResponse res = client.getResponse(serviceURL);
+        WebLink[] links = res.getLinks();
+        assertEquals("There should get two links for the service", 1, links.length);
+        assertEquals(serviceURL + "Greeter?wsdl", links[0].getURLString()); 
+        assertEquals("text/html", res.getContentType());
+    }
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java?rev=590565&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
Tue Oct 30 22:40:03 2007
@@ -0,0 +1,91 @@
+/**
+ * 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.servlet;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
+import org.apache.hello_world_soap_http.GreeterImpl;
+
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.ContextHandlerCollection;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+
+public class NoSpringServletServer extends AbstractBusTestServerBase {
+    Server httpServer;
+    @Override
+    protected void run() {
+        // setup the system properties
+        String busFactory = System.getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
+        System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME, "org.apache.cxf.bus.CXFBusFactory");
+        try {
+            httpServer = new Server(9000);
+            ContextHandlerCollection contexts = new ContextHandlerCollection();
+            httpServer.setHandler(contexts);
+            
+            Context root = new Context(contexts, "/", Context.SESSIONS);
+            
+            CXFNonSpringServlet cxf = new CXFNonSpringServlet();
+            ServletHolder servlet = new ServletHolder(cxf);
+            servlet.setName("soap");
+            servlet.setForcedPath("soap");
+            root.addServlet(servlet, "/soap/*");
+            
+            httpServer.start();
+            
+            Bus bus = cxf.getBus();
+            setBus(bus);
+            BusFactory.setDefaultBus(bus);
+            GreeterImpl impl = new GreeterImpl();
+            Endpoint.publish("/Greeter", impl);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            // clean up the system properties
+            if (busFactory != null) {
+                System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME, busFactory);
+            } else {
+                System.clearProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
+            }
+        }
+    }
+    
+    public void tearDown() throws Exception {
+        if (httpServer != null) {
+            httpServer.stop();
+        }    
+    }
+    
+    public static void main(String[] args) {
+        try {
+            NoSpringServletServer s = new NoSpringServletServer();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message