geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r158026 - in geronimo/trunk/modules/axis/src: java/org/apache/geronimo/axis/server/AxisWebServiceContainer.java test/org/apache/geronimo/axis/AxisRequest.java test/org/apache/geronimo/axis/AxisWebServiceContainerTest.java
Date Fri, 18 Mar 2005 07:34:16 GMT
Author: chirino
Date: Thu Mar 17 23:34:13 2005
New Revision: 158026

URL: http://svn.apache.org/viewcvs?view=rev&rev=158026
Log:
Implemented WSDL port address replacment.

Modified:
    geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/server/AxisWebServiceContainer.java
    geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/AxisRequest.java
    geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/AxisWebServiceContainerTest.java

Modified: geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/server/AxisWebServiceContainer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/server/AxisWebServiceContainer.java?view=diff&r1=158025&r2=158026
==============================================================================
--- geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/server/AxisWebServiceContainer.java
(original)
+++ geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/server/AxisWebServiceContainer.java
Thu Mar 17 23:34:13 2005
@@ -20,8 +20,18 @@
 import java.io.OutputStream;
 import java.net.URI;
 import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
 
 import javax.servlet.http.HttpServletResponse;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.wsdl.xml.WSDLWriter;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPMessage;
 
@@ -51,6 +61,11 @@
     protected final URL wsdlURL;
     protected final SOAPService service;  //TODO why did i make these protected?
     private final ClassLoader classLoader;
+    private final Object wsdlMutext = new Object();
+
+    private Definition definition;
+
+    private WSDLWriter wsdlWriter;
 
     public AxisWebServiceContainer(URI location, URL wsdlURL, SOAPService service, ClassLoader
classLoader) {
         this.location = location;
@@ -172,23 +187,59 @@
         }
         return responseMessage;
     }
-
-    public void getWsdl(Request req, Response res) throws Exception {
-        OutputStream out = res.getOutputStream();
-        InputStream in = null;
-        try {
-            in = wsdlURL.openStream();
-            byte[] buffer = new byte[1024];
-            for (int read = in.read(buffer); read > 0; read = in.read(buffer)) {
-//                System.out.write(buffer, 0, read);
-                out.write(buffer, 0, read);
-            }
-        } finally {
-            if (in != null) {
-                in.close();
-            }
+    
+    public void getWsdl(Request request, Response response) throws Exception {
+        
+        // Avoid concurrent modification of the WSDL dom.
+        synchronized(wsdlMutext) {
+            
+            // Read in the the WSDL in once. 
+            if( definition == null ) {
+                initWSDLDom();
+            }
+            
+            // Update all the service port soap address elements.
+            Map services = definition.getServices();
+            for (Iterator iter1 = services.values().iterator(); iter1.hasNext();) {
+                Service service = (Service) iter1.next();
+                Map ports = service.getPorts();
+                for (Iterator iter2 = ports.values().iterator(); iter2.hasNext();) {
+                    Port port = (Port) iter2.next();
+                    for (Iterator iter3 = port.getExtensibilityElements().iterator(); iter3.hasNext();)
{
+                        ExtensibilityElement element = (ExtensibilityElement) iter3.next();
+                        if (element instanceof SOAPAddress ) {
+                            SOAPAddress soapAddress = (SOAPAddress)element;
+                            URI realLocation = request.getURI();                        
   
+                            // We replace the host and port here.
+                            URI updated = new URI(
+                                    realLocation.getScheme(),
+                                    realLocation.getUserInfo(), 
+                                    realLocation.getHost(), 
+                                    realLocation.getPort(),
+                                    realLocation.getPath(), // Humm is this right?
+                                    null,
+                                    null);
+                            soapAddress.setLocationURI(updated.toString());
+                        }
+                    }
+                }
+            }
+            
+            // Dump the WSDL dom to the output stream
+            OutputStream out = response.getOutputStream();
+            wsdlWriter.writeWSDL(definition, out);
+            out.close();
         }
+    }
 
+    /**
+     * @throws Exception
+     */
+    private void initWSDLDom() throws Exception {
+        WSDLFactory wsdlFactory = WSDLFactory.newInstance();
+        wsdlWriter = wsdlFactory.newWSDLWriter();
+        WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
+        definition = wsdlReader.readWSDL(wsdlURL.toExternalForm());
     }
 
     public URI getLocation() {

Modified: geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/AxisRequest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/AxisRequest.java?view=diff&r1=158025&r2=158026
==============================================================================
--- geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/AxisRequest.java (original)
+++ geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/AxisRequest.java Thu Mar
17 23:34:13 2005
@@ -2,7 +2,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
-import java.net.URL;
 import java.util.Map;
 
 import org.apache.geronimo.webservices.WebServiceContainer;
@@ -10,13 +9,10 @@
 public class AxisRequest implements WebServiceContainer.Request {
     private int contentLength;
     private String contentType;
-    private String host;
     private InputStream in;
     private int method;
     private Map parameters;
-    private String path;
     private URI uri;
-    private int port;
     private Map headers;
 
     /**
@@ -25,22 +21,16 @@
     public AxisRequest(
         int contentLength,
         String contentType,
-        String host,
         InputStream in,
         int method,
         Map parameters,
-        String path,
         URI uri,
-        int port,
         Map headers) {
         this.contentType = contentType;
-        this.host = host;
         this.in = in;
         this.method = method;
         this.parameters = parameters;
-        this.path = path;
         this.uri = uri;
-        this.port = port;
         this.headers = headers;
     }
 
@@ -56,10 +46,6 @@
         return (String) headers.get(name);
     }
 
-    public String getHost() {
-        return host;
-    }
-
     public InputStream getInputStream() throws IOException {
         return in;
     }
@@ -74,14 +60,6 @@
 
     public Map getParameters() {
         return parameters;
-    }
-
-    public String getPath() {
-        return path;
-    }
-
-    public int getPort() {
-        return port;
     }
 
     public URI getURI() {

Modified: geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/AxisWebServiceContainerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/AxisWebServiceContainerTest.java?view=diff&r1=158025&r2=158026
==============================================================================
--- geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/AxisWebServiceContainerTest.java
(original)
+++ geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/AxisWebServiceContainerTest.java
Thu Mar 17 23:34:13 2005
@@ -110,13 +110,10 @@
             new AxisRequest(
                 504,
                 "text/xml; charset=utf-8",
-                "127.0.0.1",
                 in,
                 0,
                 new HashMap(),
-                null,
                 location,
-                8080,
                 new HashMap());
         AxisResponse res =
             new AxisResponse("text/xml; charset=utf-8", "127.0.0.1", null, null, 8080, System.out);



Mime
View raw message