You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2005/08/15 21:50:19 UTC

svn commit: r232864 - in /geronimo/trunk/modules/axis-builder/src: java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java test/org/apache/geronimo/axis/builder/WSDLMapTest.java

Author: djencks
Date: Mon Aug 15 12:50:16 2005
New Revision: 232864

URL: http://svn.apache.org/viewcvs?rev=232864&view=rev
Log:
GERONIMO-711 Make sure documents returned by ?WSDL queries include xml declaration

Added:
    geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/WSDLMapTest.java
Modified:
    geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java

Modified: geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java?rev=232864&r1=232863&r2=232864&view=diff
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java (original)
+++ geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java Mon Aug 15 12:50:16 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.geronimo.axis.builder;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.lang.reflect.Method;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -42,8 +44,6 @@
 import org.apache.axis.description.OperationDesc;
 import org.apache.axis.encoding.TypeMapping;
 import org.apache.axis.encoding.TypeMappingRegistryImpl;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.axis.client.TypeInfo;
 import org.apache.geronimo.axis.server.ReadOnlyServiceDesc;
 import org.apache.geronimo.axis.server.ServiceInfo;
@@ -55,6 +55,7 @@
 import org.apache.geronimo.xbeans.wsdl.TImport;
 import org.apache.geronimo.xbeans.wsdl.TTypes;
 import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.impl.xb.xsdschema.ImportDocument;
 import org.apache.xmlbeans.impl.xb.xsdschema.IncludeDocument;
 import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
@@ -63,7 +64,6 @@
  * @version $Rev$ $Date$
  */
 public class AxisServiceBuilder {
-    private static final Log log = LogFactory.getLog(AxisServiceBuilder.class);
 
     public static final String XSD_NS = "http://www.w3.org/2001/XMLSchema";
     public static final QName SCHEMA_QNAME = new QName(XSD_NS, "schema");
@@ -208,7 +208,7 @@
                 SchemaDocument schemaDocument = (SchemaDocument) ((SchemaDocument) value).copy();
                 SchemaDocument.Schema schema = schemaDocument.getSchema();
                 rewriteSchema(schema, contextURI, key);
-                String schemaString = schemaDocument.toString();
+                String schemaString = xmlObjectToString(schemaDocument);
                 wsdlMap.put(key.toString(), schemaString);
             } else if (value instanceof DefinitionsDocument) {
                 DefinitionsDocument doc = (DefinitionsDocument) ((DefinitionsDocument) value).copy();
@@ -231,13 +231,14 @@
                             do {
                                 SchemaDocument.Schema schema = (SchemaDocument.Schema) typeCursor.getObject();
                                 rewriteSchema(schema, contextURI, key);
-                             } while (typeCursor.toNextSibling(SCHEMA_QNAME));
+                            } while (typeCursor.toNextSibling(SCHEMA_QNAME));
                         }
                     } finally {
                         typeCursor.dispose();
                     }
                 }
-                wsdlMap.put(key.toString(), doc.toString());
+                String docString = xmlObjectToString(doc);
+                wsdlMap.put(key.toString(), docString);
             } else {
                 throw new DeploymentException("Unexpected element in wsdlMap at location: " + key + ", value: " + value);
             }
@@ -245,6 +246,18 @@
         return wsdlMap;
     }
 
+    static String xmlObjectToString(XmlObject xmlObject) throws DeploymentException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try {
+            xmlObject.save(baos);
+            baos.flush();
+            String result = new String(baos.toByteArray());
+            return result;
+        } catch (IOException e) {
+            throw new DeploymentException("Could not write xml object to string", e);
+        }
+    }
+
     private static void rewriteSchema(SchemaDocument.Schema schema, URI contextURI, URI key) throws DeploymentException {
         ImportDocument.Import[] imports = schema.getImportArray();
         for (int i = 0; i < imports.length; i++) {
@@ -270,7 +283,7 @@
             if (importLocationURI.isAbsolute() || importLocationURI.getPath().startsWith("/")) {
                 return importLocationURI;
             }
-            URI queryURI =  new URI(null,
+            URI queryURI = new URI(null,
                     null,
                     contextURI.getPath(),
                     "wsdl=" + key.resolve(importLocationURI),

Added: geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/WSDLMapTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/WSDLMapTest.java?rev=232864&view=auto
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/WSDLMapTest.java (added)
+++ geronimo/trunk/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/WSDLMapTest.java Mon Aug 15 12:50:16 2005
@@ -0,0 +1,34 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.axis.builder;
+
+import junit.framework.TestCase;
+import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public class WSDLMapTest extends TestCase {
+
+    public void testOutputStringHasXMLDeclaration() throws Exception {
+        SchemaDocument schemaDocument = SchemaDocument.Factory.newInstance();
+        schemaDocument.addNewSchema();
+        String output = AxisServiceBuilder.xmlObjectToString(schemaDocument);
+        assertTrue(output.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
+    }
+
+}
\ No newline at end of file