You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2008/08/10 04:14:42 UTC

svn commit: r684397 - in /cxf/trunk: rt/core/src/main/java/org/apache/cxf/transport/ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ systests/src/test/java/org/apache/cxf/systest/servlet/

Author: ningjiang
Date: Sat Aug  9 19:14:42 2008
New Revision: 684397

URL: http://svn.apache.org/viewvc?rev=684397&view=rev
Log:
CXF-1741 Fixed the NPE when publish the code first service in NoSpringServlet

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/DestinationFactoryManagerImpl.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/DestinationFactoryManagerImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/DestinationFactoryManagerImpl.java?rev=684397&r1=684396&r2=684397&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/DestinationFactoryManagerImpl.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/DestinationFactoryManagerImpl.java Sat Aug  9 19:14:42 2008
@@ -68,19 +68,19 @@
     public void setBus(Bus b) {
         bus = b;
     }
-    
+
     @PostConstruct
     public void register() {
         if (null != bus) {
             bus.setExtension(this, DestinationFactoryManager.class);
         }
     }
-    
+
 
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.cxf.bus.DestinationFactoryManager#registerDestinationFactory(java.lang.String,
      *      org.apache.cxf.transports.DestinationFactory)
      */
@@ -90,7 +90,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.cxf.bus.DestinationFactoryManager#deregisterDestinationFactory(java.lang.String)
      */
     public void deregisterDestinationFactory(String namespace) {
@@ -99,14 +99,14 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.cxf.bus.DestinationFactoryManager#DestinationFactory(java.lang.String)
      */
     /**
      * Returns the conduit initiator for the given namespace, constructing it
      * (and storing in the cache for future reference) if necessary, using its
      * list of factory classname to namespace mappings.
-     * 
+     *
      * @param namespace the namespace.
      */
     public DestinationFactory getDestinationFactory(String namespace) throws BusException {
@@ -123,6 +123,10 @@
     }
 
     public DestinationFactory getDestinationFactoryForUri(String uri) {
+        //If the uri is related path or has no protocol prefix , we will set it to be http
+        if (uri.startsWith("/") || uri.indexOf(":") < 0) {
+            uri = "http://" + uri;
+        }
         //first attempt the ones already registered
         for (Map.Entry<String, DestinationFactory> df : destinationFactories.entrySet()) {
             for (String prefix : df.getValue().getUriPrefixes()) {
@@ -142,7 +146,7 @@
                 }
             }
         }
-        
+
         return null;
     }
 

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java?rev=684397&r1=684396&r2=684397&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java Sat Aug  9 19:14:42 2008
@@ -37,11 +37,11 @@
 public class ServletContextResourceResolver implements ResourceResolver {
     ServletContext servletContext;
     Map<String, URL> urlMap = new ConcurrentHashMap<String, URL>();
-    
+
     public ServletContextResourceResolver(ServletContext sc) {
         servletContext = sc;
     }
-    
+
 
     public final InputStream getAsStream(final String string) {
         if (urlMap.containsKey(string)) {
@@ -55,19 +55,21 @@
     }
 
     public final <T> T resolve(final String entryName, final Class<T> clz) {
-        
+
         Object obj = null;
         try {
-            InitialContext ic = new InitialContext();
-            obj = ic.lookup(entryName);
+            if (entryName != null) {
+                InitialContext ic = new InitialContext();
+                obj = ic.lookup(entryName);
+            }
         } catch (NamingException e) {
             //do nothing
         }
-        
+
         if (obj != null && clz.isInstance(obj)) {
             return clz.cast(obj);
         }
-        
+
         if (clz.isAssignableFrom(URL.class)) {
             if (urlMap.containsKey(entryName)) {
                 return clz.cast(urlMap.get(entryName));
@@ -92,7 +94,7 @@
             }
         } else if (clz.isAssignableFrom(InputStream.class)) {
             return clz.cast(getAsStream(entryName));
-        }        
+        }
         return null;
     }
 }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java?rev=684397&r1=684396&r2=684397&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java Sat Aug  9 19:14:42 2008
@@ -26,6 +26,8 @@
 import com.meterware.httpunit.WebLink;
 import com.meterware.httpunit.WebResponse;
 
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.systest.jaxws.Hello;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.hello_world_soap_http.Greeter;
 import org.apache.hello_world_soap_http.SOAPService;
@@ -41,11 +43,11 @@
     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);        
+        Greeter greeter = service.getPort(portName, Greeter.class);
         try {
             String reply = greeter.greetMe("test");
             assertNotNull("no response received from service", reply);
@@ -57,14 +59,25 @@
             throw (Exception)ex.getCause();
         }
     }
-    
+
+    @Test
+    public void testHelloService() throws Exception {
+        JaxWsProxyFactoryBean cpfb = new JaxWsProxyFactoryBean();
+        String address = serviceURL + "Hello";
+        cpfb.setServiceClass(Hello.class);
+        cpfb.setAddress(address);
+        Hello hello = (Hello) cpfb.create();
+        String reply = hello.sayHi(" Willem");
+        assertEquals("Get the wrongreply ", reply, "get Willem");
+    }
+
     @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("There should get two links for the service", 2, links.length);
+        assertEquals(serviceURL + "Greeter?wsdl", links[0].getURLString());
         assertEquals("text/html", res.getContentType());
     }
 }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java?rev=684397&r1=684396&r2=684397&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java Sat Aug  9 19:14:42 2008
@@ -22,10 +22,10 @@
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.systest.jaxws.HelloImpl;
 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;
@@ -42,22 +42,25 @@
             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);
+            HelloImpl helloImpl = new HelloImpl();
+            Endpoint.publish("/Hello", helloImpl);
+
         } catch (Exception e) {
             throw new RuntimeException(e);
         } finally {
@@ -69,13 +72,13 @@
             }
         }
     }
-    
+
     public void tearDown() throws Exception {
         if (httpServer != null) {
             httpServer.stop();
-        }    
+        }
     }
-    
+
     public static void main(String[] args) {
         try {
             NoSpringServletServer s = new NoSpringServletServer();