From 6c920dd8ea42d7363800ced5a4ad4ba959408ef5 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Fri, 7 Dec 2007 14:46:43 +0000 Subject: [PATCH] SWS-247 --- ...XsdBasedSoap11Wsdl4jDefinitionBuilder.java | 9 +-- ...XsdBasedSoap12Wsdl4jDefinitionBuilder.java | 57 ++++++------------- ...asedSoap11Wsdl4jDefinitionBuilderTest.java | 18 +++++- ...asedSoap12Wsdl4jDefinitionBuilderTest.java | 18 +++++- 4 files changed, 56 insertions(+), 46 deletions(-) diff --git a/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilder.java b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilder.java index 5929dcf5..2a4617dd 100644 --- a/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilder.java +++ b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilder.java @@ -37,15 +37,16 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.Resource; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition; import org.springframework.xml.namespace.QNameUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; /** * Builds a WsdlDefinition with a SOAP 1.1 binding based on an XSD schema. This builder iterates over all @@ -278,7 +279,7 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jD QName elementName = (QName) iterator.next(); if (elementName != null && (isRequestMessage(elementName) || isResponseMessage(elementName) || isFaultMessage(elementName))) { - if (!StringUtils.hasLength(definition.getPrefix(elementName.getNamespaceURI()))) { + if (definition.getPrefix(elementName.getNamespaceURI()) == null) { int i = 0; while (true) { String prefix = schemaPrefix + Integer.toString(i); diff --git a/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap12Wsdl4jDefinitionBuilder.java b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap12Wsdl4jDefinitionBuilder.java index 9f986a1d..c0cdbc7c 100755 --- a/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap12Wsdl4jDefinitionBuilder.java +++ b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap12Wsdl4jDefinitionBuilder.java @@ -37,15 +37,16 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.Resource; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition; import org.springframework.xml.namespace.QNameUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; /** * Builds a WsdlDefinition with a SOAP 1.2 binding based on an XSD schema. This builder iterates over all @@ -86,34 +87,22 @@ import org.xml.sax.SAXException; public class XsdBasedSoap12Wsdl4jDefinitionBuilder extends AbstractSoap12Wsdl4jDefinitionBuilder implements InitializingBean { - /** - * The default suffix used to detect request elements in the schema. - */ + /** The default suffix used to detect request elements in the schema. */ public static final String DEFAULT_REQUEST_SUFFIX = "Request"; - /** - * The default suffix used to detect response elements in the schema. - */ + /** The default suffix used to detect response elements in the schema. */ public static final String DEFAULT_RESPONSE_SUFFIX = "Response"; - /** - * The default suffix used to detect fault elements in the schema. - */ + /** The default suffix used to detect fault elements in the schema. */ public static final String DEFAULT_FAULT_SUFFIX = "Fault"; - /** - * The default prefix used to register the schema namespace in the WSDL. - */ + /** The default prefix used to register the schema namespace in the WSDL. */ public static final String DEFAULT_SCHEMA_PREFIX = "schema"; - /** - * The default prefix used to register the target namespace in the WSDL. - */ + /** The default prefix used to register the target namespace in the WSDL. */ public static final String DEFAULT_PREFIX = "tns"; - /** - * The suffix used to create a service name from a port type name. - */ + /** The suffix used to create a service name from a port type name. */ public static final String SERVICE_SUFFIX = "Service"; private Resource schemaResource; @@ -165,16 +154,12 @@ public class XsdBasedSoap12Wsdl4jDefinitionBuilder extends AbstractSoap12Wsdl4jD this.faultSuffix = faultSuffix; } - /** - * Sets the port type name used for this definition. Required. - */ + /** Sets the port type name used for this definition. Required. */ public void setPortTypeName(String portTypeName) { this.portTypeName = portTypeName; } - /** - * Sets the target namespace used for this definition. - */ + /** Sets the target namespace used for this definition. */ public void setTargetNamespace(String targetNamespace) { this.targetNamespace = targetNamespace; } @@ -197,9 +182,7 @@ public class XsdBasedSoap12Wsdl4jDefinitionBuilder extends AbstractSoap12Wsdl4jD this.prefix = prefix; } - /** - * Sets the XSD schema to use for generating the WSDL. - */ + /** Sets the XSD schema to use for generating the WSDL. */ public void setSchema(Resource schemaResource) { Assert.notNull(schemaResource, "'schema' must not be null"); Assert.isTrue(schemaResource.exists(), "schema \"" + schemaResource + "\" does not exit"); @@ -232,9 +215,7 @@ public class XsdBasedSoap12Wsdl4jDefinitionBuilder extends AbstractSoap12Wsdl4jD } } - /** - * Adds the target namespace and schema namespace to the definition. - */ + /** Adds the target namespace and schema namespace to the definition. */ protected void populateDefinition(Definition definition) throws WSDLException { super.populateDefinition(definition); definition.setTargetNamespace(targetNamespace); @@ -244,9 +225,7 @@ public class XsdBasedSoap12Wsdl4jDefinitionBuilder extends AbstractSoap12Wsdl4jD } } - /** - * Does nothing. - */ + /** Does nothing. */ protected void buildImports(Definition definition) throws WSDLException { } @@ -301,7 +280,7 @@ public class XsdBasedSoap12Wsdl4jDefinitionBuilder extends AbstractSoap12Wsdl4jD QName elementName = (QName) iterator.next(); if (elementName != null && (isRequestMessage(elementName) || isResponseMessage(elementName) || isFaultMessage(elementName))) { - if (!StringUtils.hasLength(definition.getPrefix(elementName.getNamespaceURI()))) { + if (definition.getPrefix(elementName.getNamespaceURI()) == null) { int i = 0; while (true) { String prefix = schemaPrefix + Integer.toString(i); @@ -517,9 +496,7 @@ public class XsdBasedSoap12Wsdl4jDefinitionBuilder extends AbstractSoap12Wsdl4jD operation.setName(operationName); } - /** - * Sets the name of the service to the name of the port type, with "Service" appended to it. - */ + /** Sets the name of the service to the name of the port type, with "Service" appended to it. */ protected void populateService(Service service) throws WSDLException { service.setQName(new QName(targetNamespace, portTypeName + SERVICE_SUFFIX)); } diff --git a/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilderTest.java b/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilderTest.java index 2d32cddc..86733a53 100644 --- a/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilderTest.java +++ b/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilderTest.java @@ -24,9 +24,11 @@ import javax.xml.transform.dom.DOMResult; import org.custommonkey.xmlunit.XMLTestCase; import org.custommonkey.xmlunit.XMLUnit; +import org.w3c.dom.Document; + import org.springframework.core.io.ClassPathResource; import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; -import org.w3c.dom.Document; +import org.springframework.xml.transform.StringResult; public class XsdBasedSoap11Wsdl4jDefinitionBuilderTest extends XMLTestCase { @@ -144,6 +146,20 @@ public class XsdBasedSoap11Wsdl4jDefinitionBuilderTest extends XMLTestCase { assertXMLEqual("Invalid WSDL built", expected, result); } + public void testNoSchemaPrefix() throws Exception { + builder.setSchema(new ClassPathResource("single.xsd", getClass())); + builder.setPortTypeName("Order"); + builder.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions"); + builder.setSchemaPrefix(""); + builder.afterPropertiesSet(); + + buildAll(); + + Wsdl11Definition definition = builder.getDefinition(); + + transformer.transform(definition.getSource(), new StringResult()); + } + private void buildAll() { builder.buildDefinition(); builder.buildImports(); diff --git a/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap12Wsdl4jDefinitionBuilderTest.java b/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap12Wsdl4jDefinitionBuilderTest.java index 0253b05a..37c27834 100644 --- a/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap12Wsdl4jDefinitionBuilderTest.java +++ b/core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap12Wsdl4jDefinitionBuilderTest.java @@ -24,9 +24,11 @@ import javax.xml.transform.dom.DOMResult; import org.custommonkey.xmlunit.XMLTestCase; import org.custommonkey.xmlunit.XMLUnit; +import org.w3c.dom.Document; + import org.springframework.core.io.ClassPathResource; import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition; -import org.w3c.dom.Document; +import org.springframework.xml.transform.StringResult; public class XsdBasedSoap12Wsdl4jDefinitionBuilderTest extends XMLTestCase { @@ -73,6 +75,20 @@ public class XsdBasedSoap12Wsdl4jDefinitionBuilderTest extends XMLTestCase { assertXMLEqual("Invalid WSDL built", expected, result); } + public void testNoSchemaPrefix() throws Exception { + builder.setSchema(new ClassPathResource("single.xsd", getClass())); + builder.setPortTypeName("Order"); + builder.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions"); + builder.setSchemaPrefix(""); + builder.afterPropertiesSet(); + + buildAll(); + + Wsdl11Definition definition = builder.getDefinition(); + + transformer.transform(definition.getSource(), new StringResult()); + } + private void buildAll() { builder.buildDefinition(); builder.buildImports();