geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r524530 - /geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java
Date Sun, 01 Apr 2007 04:58:18 GMT
Author: gawor
Date: Sat Mar 31 21:58:17 2007
New Revision: 524530

URL: http://svn.apache.org/viewvc?view=rev&rev=524530
Log:
if wsdl file is supplied and it has multiple services or ports make sure ?wsdl returns only
one service and one port

Modified:
    geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java

Modified: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java?view=diff&rev=524530&r1=524529&r2=524530
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java
(original)
+++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java
Sat Mar 31 21:58:17 2007
@@ -18,9 +18,12 @@
 
 import java.io.PrintWriter;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
@@ -28,6 +31,7 @@
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLWriter;
+import javax.xml.namespace.QName;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -110,30 +114,77 @@
 
         Definition def = new ServiceWSDLBuilder(ei.getService()).build();
         
-        Service service = def.getService(ei.getService().getName());
-        Port port = service.getPort(ei.getName().getLocalPart());
-        if (port == null) {
-            LOG.warn("No WSDL port found for: " + ei.getName());
-        } else {
-            List<?> exts = port.getExtensibilityElements();
-            if (exts != null && exts.size() > 0) {
-                URI requestURI = request.getURI();
-                URI serviceURI = new URI(requestURI.getScheme(), null, 
-                                         requestURI.getHost(), requestURI.getPort(), 
-                                         requestURI.getPath(), null, null);
-                ExtensibilityElement el = (ExtensibilityElement) exts.get(0);
-                if (SOAPBindingUtil.isSOAPAddress(el)) {
-                    SoapAddress add = SOAPBindingUtil.getSoapAddress(el);
-                    add.setLocationURI(serviceURI.toString());
+        QName serviceName = ei.getService().getName();
+        String portName = ei.getName().getLocalPart();
+        
+        updateServices(serviceName, portName, def, request);
+        
+        wsdlWriter.writeWSDL(def, response.getOutputStream());
+    }
+    
+    private void updateServices(QName serviceName, String portName, Definition def, Request
request)
+        throws Exception {
+        boolean updated = false;
+        Map services = def.getServices();
+        if (services != null) {
+            Iterator serviceIterator = services.entrySet().iterator();
+            while (serviceIterator.hasNext()) {
+                Map.Entry serviceEntry = (Map.Entry) serviceIterator.next();
+                QName currServiceName = (QName) serviceEntry.getKey();
+                if (currServiceName.equals(serviceName)) {
+                    Service service = (Service) serviceEntry.getValue();
+                    updatePorts(portName, service, request);
+                    updated = true;
+                } else {
+                    def.removeService(currServiceName);
                 }
-                if (el instanceof AddressType) {
-                    AddressType add = (AddressType) el;
-                    add.setLocation(serviceURI.toString());
+            }
+        }
+        if (!updated) {
+            LOG.warn("WSDL '" + serviceName.getLocalPart() + "' service not found.");
+        }
+    }
+    
+    private void updatePorts(String portName, Service service, Request request) 
+        throws Exception {
+        boolean updated = false;
+        Map ports = service.getPorts();
+        if (ports != null) {
+            Iterator portIterator = ports.entrySet().iterator();
+            while (portIterator.hasNext()) {
+                Map.Entry portEntry = (Map.Entry) portIterator.next();
+                String currPortName = (String) portEntry.getKey();
+                if (currPortName.equals(portName)) {
+                    Port port = (Port) portEntry.getValue();
+                    updatePortLocation(request, port);
+                    updated = true;
+                } else {
+                    service.removePort(currPortName);
                 }
             }
         }
-
-        wsdlWriter.writeWSDL(def, response.getOutputStream());
+        if (!updated) {
+            LOG.warn("WSDL '" + portName + "' port not found.");
+        }        
+    }
+    
+    private void updatePortLocation(Request request, Port port) throws URISyntaxException
{
+        List<?> exts = port.getExtensibilityElements();
+        if (exts != null && exts.size() > 0) {
+            URI requestURI = request.getURI();
+            URI serviceURI = new URI(requestURI.getScheme(), null, 
+                                     requestURI.getHost(), requestURI.getPort(), 
+                                     requestURI.getPath(), null, null);
+            ExtensibilityElement el = (ExtensibilityElement) exts.get(0);
+            if (SOAPBindingUtil.isSOAPAddress(el)) {
+                SoapAddress add = SOAPBindingUtil.getSoapAddress(el);
+                add.setLocationURI(serviceURI.toString());
+            }
+            if (el instanceof AddressType) {
+                AddressType add = (AddressType) el;
+                add.setLocation(serviceURI.toString());
+            }
+        }
     }
 
     public void destroy() {



Mime
View raw message