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 2007/10/08 21:07:55 UTC

svn commit: r582944 - in /incubator/cxf/branches/2.0.x-fixes: ./ common/common/src/main/java/org/apache/cxf/helpers/ rt/core/src/main/java/org/apache/cxf/transport/http/ systests/src/test/java/org/apache/cxf/systest/http_jetty/ systests/src/test/java/o...

Author: dkulp
Date: Mon Oct  8 12:07:51 2007
New Revision: 582944

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

........
  r582385 | dkulp | 2007-10-05 16:57:29 -0400 (Fri, 05 Oct 2007) | 2 lines
  
  [CXF-1071, CXF-948] Fix issues with WSDLQueryHandler when using urls with extra params and using catalogs for the imports
........

Added:
    incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/http_jetty/test.html
      - copied unchanged from r582385, incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/test.html
    incubator/cxf/branches/2.0.x-fixes/testutils/src/main/java/org/apache/hello_world/GreeterImpl.java
      - copied unchanged from r582385, incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world/GreeterImpl.java
    incubator/cxf/branches/2.0.x-fixes/testutils/src/main/resources/wsdl/hello_world_bindings_catalog.wsdl
      - copied unchanged from r582385, incubator/cxf/trunk/testutils/src/main/resources/wsdl/hello_world_bindings_catalog.wsdl
    incubator/cxf/branches/2.0.x-fixes/testutils/src/main/resources/wsdl/hello_world_messages_catalog.wsdl
      - copied unchanged from r582385, incubator/cxf/trunk/testutils/src/main/resources/wsdl/hello_world_messages_catalog.wsdl
    incubator/cxf/branches/2.0.x-fixes/testutils/src/main/resources/wsdl/hello_world_schema.xsd
      - copied unchanged from r582385, incubator/cxf/trunk/testutils/src/main/resources/wsdl/hello_world_schema.xsd
    incubator/cxf/branches/2.0.x-fixes/testutils/src/main/resources/wsdl/hello_world_schema2.xsd
      - copied unchanged from r582385, incubator/cxf/trunk/testutils/src/main/resources/wsdl/hello_world_schema2.xsd
    incubator/cxf/branches/2.0.x-fixes/testutils/src/main/resources/wsdl/hello_world_services_catalog.wsdl
      - copied unchanged from r582385, incubator/cxf/trunk/testutils/src/main/resources/wsdl/hello_world_services_catalog.wsdl
    incubator/cxf/branches/2.0.x-fixes/testutils/src/main/resources/wsdl/hello_world_wsdl_import_catalog.wsdl
      - copied unchanged from r582385, incubator/cxf/trunk/testutils/src/main/resources/wsdl/hello_world_wsdl_import_catalog.wsdl
Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
    incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
    incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
    incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java

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

Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java?rev=582944&r1=582943&r2=582944&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java Mon Oct  8 12:07:51 2007
@@ -88,6 +88,7 @@
             buf.append(new String(buffer, 0, n));
             n = input.read(buffer);
         }
+        input.close();
         return buf.toString();
     }
     public static String toString(final Reader input) 

Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java?rev=582944&r1=582943&r2=582944&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java Mon Oct  8 12:07:51 2007
@@ -24,8 +24,10 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.StringTokenizer;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -50,6 +52,7 @@
 
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.catalog.OASISCatalogManager;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.helpers.CastUtils;
@@ -80,13 +83,20 @@
     public boolean isRecognizedQuery(String baseUri, String ctx, 
                                      EndpointInfo endpointInfo, boolean contextMatchExact) {
         if (baseUri != null 
-            && (baseUri.toLowerCase().contains("?wsdl")
-                || baseUri.toLowerCase().contains("?xsd="))) {
-            if (contextMatchExact) {
-                return endpointInfo.getAddress().contains(ctx);
-            } else {
-                // contextMatchStrategy will be "stem"
-                return endpointInfo.getAddress().contains(getStem(baseUri));
+            && (baseUri.contains("?") 
+                && (baseUri.toLowerCase().contains("wsdl")
+                || baseUri.toLowerCase().contains("xsd=")))) {
+            
+            int idx = baseUri.indexOf("?");
+            Map<String, String> map = parseQueryString(baseUri.substring(idx + 1));
+            if (map.containsKey("wsdl")
+                || map.containsKey("xsd")) {
+                if (contextMatchExact) {
+                    return endpointInfo.getAddress().contains(ctx);
+                } else {
+                    // contextMatchStrategy will be "stem"
+                    return endpointInfo.getAddress().contains(getStem(baseUri.substring(0, idx)));
+                }
             }
         }
         return false;
@@ -95,20 +105,11 @@
     public void writeResponse(String baseUri, String ctxUri,
                               EndpointInfo endpointInfo, OutputStream os) {
         try {
-            int idx = baseUri.toLowerCase().indexOf("?wsdl");
-            String base = null;
-            String wsdl = "";
-            String xsd =  null;
-            if (idx != -1) {
-                base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?wsdl"));
-                wsdl = baseUri.substring(baseUri.toLowerCase().indexOf("?wsdl") + 5);
-                if (wsdl.length() > 0) {
-                    wsdl = wsdl.substring(1);
-                }
-            } else {
-                base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?xsd="));
-                xsd = baseUri.substring(baseUri.toLowerCase().indexOf("?xsd=") + 5);
-            }
+            int idx = baseUri.toLowerCase().indexOf("?");
+            Map<String, String> params = parseQueryString(baseUri.substring(idx + 1));
+            String base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?"));
+            String wsdl = params.get("wsdl");
+            String xsd =  params.get("xsd");
             
             Map<String, Definition> mp = CastUtils.cast((Map)endpointInfo.getService()
                                                         .getProperty(WSDLQueryHandler.class.getName()));
@@ -131,7 +132,7 @@
                                                  + ".Schemas"));
             }
             
-            if (!mp.containsKey(wsdl)) {
+            if (!mp.containsKey("")) {
                 Definition def = new ServiceWSDLBuilder(bus, endpointInfo.getService()).build();
                 mp.put("", def);
                 updateDefinition(def, mp, smp, base, endpointInfo);
@@ -141,6 +142,12 @@
             Document doc;
             if (xsd == null) {
                 Definition def = mp.get(wsdl);
+                if (def == null) {
+                    String wsdl2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
+                                                       wsdl,
+                                                       base);
+                    def = mp.get(wsdl2);
+                }
     
                 WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class)
                     .getWSDLFactory().newWSDLWriter();
@@ -148,8 +155,21 @@
                 doc = wsdlWriter.getDocument(def);
             } else {
                 SchemaReference si = smp.get(xsd);
-                ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(si.getReferencedSchema()
-                                                                                .getDocumentBaseURI(),
+                if (si == null) {
+                    String xsd2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
+                                                       xsd,
+                                                       base);
+                    si = smp.get(xsd2);
+                }
+                
+                String uri = si.getReferencedSchema().getDocumentBaseURI();
+                uri = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
+                                          uri,
+                                          si.getReferencedSchema().getDocumentBaseURI());
+                if (uri == null) {
+                    uri = si.getReferencedSchema().getDocumentBaseURI();
+                }
+                ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(uri,
                                                                                 bus);
                 
                 InputSource src = rml.getBaseInputSource();
@@ -207,20 +227,46 @@
         }
     }
     
+
+    static String resolveWithCatalogs(OASISCatalogManager catalogs, String start, String base) {
+        String resolvedSchemaLocation = null;
+        try {
+            resolvedSchemaLocation = catalogs.getCatalog().resolveSystem(start);
+            if (resolvedSchemaLocation == null) {
+                resolvedSchemaLocation = catalogs.getCatalog().resolveURI(start);
+            }
+            if (resolvedSchemaLocation == null) {
+                resolvedSchemaLocation = catalogs.getCatalog().resolvePublic(start, base);
+            }
+        } catch (Exception ex) {
+            //ignore
+        }
+        return resolvedSchemaLocation;
+    }
     
     protected void updateDefinition(Definition def, Map<String, Definition> done,
                                   Map<String, SchemaReference> doneSchemas,
                                   String base, EndpointInfo ei) {
+        OASISCatalogManager catalogs = OASISCatalogManager.getCatalogManager(bus);    
+        
         Collection<List> imports = CastUtils.cast((Collection<?>)def.getImports().values());
         for (List lst : imports) {
             List<Import> impLst = CastUtils.cast(lst);
             for (Import imp : impLst) {
                 String start = imp.getLocationURI();
-                try {
-                    //check to see if it's aleady in a URL format.  If so, leave it.
-                    new URL(start);
-                } catch (MalformedURLException e) {
+                String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);
+                
+                if (resolvedSchemaLocation == null) {
+                    try {
+                        //check to see if it's aleady in a URL format.  If so, leave it.
+                        new URL(start);
+                    } catch (MalformedURLException e) {
+                        done.put(start, imp.getDefinition());
+                        updateDefinition(imp.getDefinition(), done, doneSchemas, base, ei);
+                    }
+                } else {
                     done.put(start, imp.getDefinition());
+                    done.put(resolvedSchemaLocation, imp.getDefinition());
                     updateDefinition(imp.getDefinition(), done, doneSchemas, base, ei);
                 }
             }
@@ -245,17 +291,25 @@
     protected void updateSchemaImports(Schema schema,
                                            Map<String, SchemaReference> doneSchemas,
                                            String base) {
+        OASISCatalogManager catalogs = OASISCatalogManager.getCatalogManager(bus);    
         Collection<List>  imports = CastUtils.cast((Collection<?>)schema.getImports().values());
         for (List lst : imports) {
             List<SchemaImport> impLst = CastUtils.cast(lst);
             for (SchemaImport imp : impLst) {
                 String start = imp.getSchemaLocationURI();
                 if (start != null && !doneSchemas.containsKey(start)) {
-                    try {
-                        //check to see if it's aleady in a URL format.  If so, leave it.
-                        new URL(start);
-                    } catch (MalformedURLException e) {
+                    String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);
+                    if (resolvedSchemaLocation == null) {
+                        try {
+                            //check to see if it's aleady in a URL format.  If so, leave it.
+                            new URL(start);
+                        } catch (MalformedURLException e) {
+                            doneSchemas.put(start, imp);
+                            updateSchemaImports(imp.getReferencedSchema(), doneSchemas, base);
+                        }
+                    } else {
                         doneSchemas.put(start, imp);
+                        doneSchemas.put(resolvedSchemaLocation, imp);
                         updateSchemaImports(imp.getReferencedSchema(), doneSchemas, base);
                     }
                 }
@@ -264,12 +318,23 @@
         List<SchemaReference> includes = CastUtils.cast(schema.getIncludes());
         for (SchemaReference included : includes) {
             String start = included.getSchemaLocationURI();
-            if (start != null && !doneSchemas.containsKey(start)) {
-                try {
-                    //check to see if it's aleady in a URL format.  If so, leave it.
-                    new URL(start);
-                } catch (MalformedURLException e) {
+
+            if (start != null) {
+                String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);
+                if (resolvedSchemaLocation == null) {
+                    if (!doneSchemas.containsKey(start)) {
+                        try {
+                            //check to see if it's aleady in a URL format.  If so, leave it.
+                            new URL(start);
+                        } catch (MalformedURLException e) {
+                            doneSchemas.put(start, included);
+                            updateSchemaImports(included.getReferencedSchema(), doneSchemas, base);
+                        }
+                    }
+                } else if (!doneSchemas.containsKey(start) 
+                    || !doneSchemas.containsKey(resolvedSchemaLocation)) {
                     doneSchemas.put(start, included);
+                    doneSchemas.put(resolvedSchemaLocation, included);
                     updateSchemaImports(included.getReferencedSchema(), doneSchemas, base);
                 }
             }
@@ -289,10 +354,30 @@
         } catch (MalformedURLException e) {
             LOG.log(Level.WARNING, "URL creation failed: ", e);
         }
-        String port = String.valueOf(url.getPort());
-        baseURI = baseURI.substring(baseURI.indexOf(port) + port.length(), baseURI.lastIndexOf("/"));
-        
+        if (url != null) {
+            baseURI = url.getPath();
+            int idx = baseURI.lastIndexOf('/');
+            if (idx != -1) {
+                baseURI = baseURI.substring(0, idx + 1);
+            }
+        }        
         return baseURI;
+    }
+    
+    static Map<String, String> parseQueryString(String s) {
+        Map<String, String> ht = new HashMap<String, String>();
+        StringTokenizer st = new StringTokenizer(s, "&");
+        while (st.hasMoreTokens()) {
+            String pair = (String)st.nextToken();
+            int pos = pair.indexOf('=');
+            if (pos == -1) {
+                ht.put(pair.toLowerCase(), "");
+            } else {
+                ht.put(pair.substring(0, pos).toLowerCase(),
+                       pair.substring(pos + 1));
+            }
+        }
+        return ht;
     }
      
 }

Modified: incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java?rev=582944&r1=582943&r2=582944&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java Mon Oct  8 12:07:51 2007
@@ -22,7 +22,6 @@
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.IOException;
 import java.io.InputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
@@ -118,8 +117,9 @@
         
     }
     
-    public String getStaticResourceURL() throws IOException {
-        File staticFile = new File("target/test-classes/org/apache/cxf/systest/http_jetty/");
+    public String getStaticResourceURL() throws Exception {
+        File staticFile = new File(this.getClass().getResource("test.html").toURI());
+        staticFile = staticFile.getParentFile();
         staticFile = staticFile.getAbsoluteFile();
         URL furl = staticFile.toURL();
         return furl.toString();
@@ -135,13 +135,11 @@
         setUpBus();
         launchService();
         shutdownService();
-        try {
-            launchService();
-            invokeService();            
-            getTestHtml();
-        } catch (java.net.BindException be) {
-            fail("bind exception");
-        }
+
+        launchService();
+        invokeService();            
+        getTestHtml();
+        
         shutdownService();
     }
 

Modified: incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java?rev=582944&r1=582943&r2=582944&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java Mon Oct  8 12:07:51 2007
@@ -19,20 +19,24 @@
 
 package org.apache.cxf.systest.jaxws;
 
+import java.io.InputStream;
 import java.net.URL;
 
 import javax.wsdl.WSDLException;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
 import javax.xml.namespace.QName;
+import javax.xml.ws.Endpoint;
 import javax.xml.ws.WebServiceException;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.catalog.CatalogWSDLLocator;
 import org.apache.cxf.catalog.OASISCatalogManager;
+import org.apache.cxf.helpers.IOUtils;
 
 import org.apache.hello_world.Greeter;
+import org.apache.hello_world.GreeterImpl;
 import org.apache.hello_world.services.SOAPService;
 
 import org.junit.Assert;
@@ -48,6 +52,30 @@
         new QName("http://apache.org/hello_world/services",
                   "SoapPort");
 
+    @Test
+    public void testWSDLPublishWithCatalogs() throws Exception {
+        Endpoint ep = Endpoint.publish(null, new GreeterImpl());
+        try {
+            URL url = new URL("http://localhost:9000/SoapContext/SoapPort?"
+                              + "xsd=testutils/hello_world_schema2.xsd");
+            assertNotNull(url.getContent());
+            
+            
+            url = new URL("http://localhost:9000/SoapContext/SoapPort"
+                          + "?xsd=testutils/hello_world_schema.xsd");
+            String result = IOUtils.toString((InputStream)url.getContent());
+            assertTrue(result.contains("xsd=testutils/hello_world_schema2.xsd"));
+
+            url = new URL("http://localhost:9000/SoapContext/SoapPort"
+                          + "?wsdl=testutils/hello_world_messages_catalog.wsdl");
+            result = IOUtils.toString((InputStream)url.getContent());
+            assertTrue(result.contains("xsd=testutils/hello_world_schema.xsd"));
+
+        } finally {
+            ep.stop();
+        }
+    }
+    
     @Test
     public void testClientWithDefaultCatalog() throws Exception {
         URL wsdl = getClass().getResource("/wsdl/catalog/hello_world_services.wsdl");