Skip to content

Commit 6c920dd

Browse files
committed
SWS-247
1 parent 9ed471f commit 6c920dd

File tree

4 files changed

+56
-46
lines changed

4 files changed

+56
-46
lines changed

core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@
3737
import javax.xml.parsers.DocumentBuilderFactory;
3838
import javax.xml.parsers.ParserConfigurationException;
3939

40+
import org.w3c.dom.Document;
41+
import org.w3c.dom.Element;
42+
import org.xml.sax.SAXException;
43+
4044
import org.springframework.beans.factory.InitializingBean;
4145
import org.springframework.core.io.Resource;
4246
import org.springframework.util.Assert;
4347
import org.springframework.util.StringUtils;
4448
import org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition;
4549
import org.springframework.xml.namespace.QNameUtils;
46-
import org.w3c.dom.Document;
47-
import org.w3c.dom.Element;
48-
import org.xml.sax.SAXException;
4950

5051
/**
5152
* Builds a <code>WsdlDefinition</code> with a SOAP 1.1 binding based on an XSD schema. This builder iterates over all
@@ -278,7 +279,7 @@ protected void buildMessages(Definition definition) throws WSDLException {
278279
QName elementName = (QName) iterator.next();
279280
if (elementName != null &&
280281
(isRequestMessage(elementName) || isResponseMessage(elementName) || isFaultMessage(elementName))) {
281-
if (!StringUtils.hasLength(definition.getPrefix(elementName.getNamespaceURI()))) {
282+
if (definition.getPrefix(elementName.getNamespaceURI()) == null) {
282283
int i = 0;
283284
while (true) {
284285
String prefix = schemaPrefix + Integer.toString(i);

core/src/main/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap12Wsdl4jDefinitionBuilder.java

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@
3737
import javax.xml.parsers.DocumentBuilderFactory;
3838
import javax.xml.parsers.ParserConfigurationException;
3939

40+
import org.w3c.dom.Document;
41+
import org.w3c.dom.Element;
42+
import org.xml.sax.SAXException;
43+
4044
import org.springframework.beans.factory.InitializingBean;
4145
import org.springframework.core.io.Resource;
4246
import org.springframework.util.Assert;
4347
import org.springframework.util.StringUtils;
4448
import org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition;
4549
import org.springframework.xml.namespace.QNameUtils;
46-
import org.w3c.dom.Document;
47-
import org.w3c.dom.Element;
48-
import org.xml.sax.SAXException;
4950

5051
/**
5152
* Builds a <code>WsdlDefinition</code> with a SOAP 1.2 binding based on an XSD schema. This builder iterates over all
@@ -86,34 +87,22 @@
8687
public class XsdBasedSoap12Wsdl4jDefinitionBuilder extends AbstractSoap12Wsdl4jDefinitionBuilder
8788
implements InitializingBean {
8889

89-
/**
90-
* The default suffix used to detect request elements in the schema.
91-
*/
90+
/** The default suffix used to detect request elements in the schema. */
9291
public static final String DEFAULT_REQUEST_SUFFIX = "Request";
9392

94-
/**
95-
* The default suffix used to detect response elements in the schema.
96-
*/
93+
/** The default suffix used to detect response elements in the schema. */
9794
public static final String DEFAULT_RESPONSE_SUFFIX = "Response";
9895

99-
/**
100-
* The default suffix used to detect fault elements in the schema.
101-
*/
96+
/** The default suffix used to detect fault elements in the schema. */
10297
public static final String DEFAULT_FAULT_SUFFIX = "Fault";
10398

104-
/**
105-
* The default prefix used to register the schema namespace in the WSDL.
106-
*/
99+
/** The default prefix used to register the schema namespace in the WSDL. */
107100
public static final String DEFAULT_SCHEMA_PREFIX = "schema";
108101

109-
/**
110-
* The default prefix used to register the target namespace in the WSDL.
111-
*/
102+
/** The default prefix used to register the target namespace in the WSDL. */
112103
public static final String DEFAULT_PREFIX = "tns";
113104

114-
/**
115-
* The suffix used to create a service name from a port type name.
116-
*/
105+
/** The suffix used to create a service name from a port type name. */
117106
public static final String SERVICE_SUFFIX = "Service";
118107

119108
private Resource schemaResource;
@@ -165,16 +154,12 @@ public void setFaultSuffix(String faultSuffix) {
165154
this.faultSuffix = faultSuffix;
166155
}
167156

168-
/**
169-
* Sets the port type name used for this definition. Required.
170-
*/
157+
/** Sets the port type name used for this definition. Required. */
171158
public void setPortTypeName(String portTypeName) {
172159
this.portTypeName = portTypeName;
173160
}
174161

175-
/**
176-
* Sets the target namespace used for this definition.
177-
*/
162+
/** Sets the target namespace used for this definition. */
178163
public void setTargetNamespace(String targetNamespace) {
179164
this.targetNamespace = targetNamespace;
180165
}
@@ -197,9 +182,7 @@ public void setPrefix(String prefix) {
197182
this.prefix = prefix;
198183
}
199184

200-
/**
201-
* Sets the XSD schema to use for generating the WSDL.
202-
*/
185+
/** Sets the XSD schema to use for generating the WSDL. */
203186
public void setSchema(Resource schemaResource) {
204187
Assert.notNull(schemaResource, "'schema' must not be null");
205188
Assert.isTrue(schemaResource.exists(), "schema \"" + schemaResource + "\" does not exit");
@@ -232,9 +215,7 @@ public final void afterPropertiesSet() throws IOException, ParserConfigurationEx
232215
}
233216
}
234217

235-
/**
236-
* Adds the target namespace and schema namespace to the definition.
237-
*/
218+
/** Adds the target namespace and schema namespace to the definition. */
238219
protected void populateDefinition(Definition definition) throws WSDLException {
239220
super.populateDefinition(definition);
240221
definition.setTargetNamespace(targetNamespace);
@@ -244,9 +225,7 @@ protected void populateDefinition(Definition definition) throws WSDLException {
244225
}
245226
}
246227

247-
/**
248-
* Does nothing.
249-
*/
228+
/** Does nothing. */
250229
protected void buildImports(Definition definition) throws WSDLException {
251230
}
252231

@@ -301,7 +280,7 @@ protected void buildMessages(Definition definition) throws WSDLException {
301280
QName elementName = (QName) iterator.next();
302281
if (elementName != null &&
303282
(isRequestMessage(elementName) || isResponseMessage(elementName) || isFaultMessage(elementName))) {
304-
if (!StringUtils.hasLength(definition.getPrefix(elementName.getNamespaceURI()))) {
283+
if (definition.getPrefix(elementName.getNamespaceURI()) == null) {
305284
int i = 0;
306285
while (true) {
307286
String prefix = schemaPrefix + Integer.toString(i);
@@ -517,9 +496,7 @@ protected void populateOperation(Operation operation, Message requestMessage, Me
517496
operation.setName(operationName);
518497
}
519498

520-
/**
521-
* Sets the name of the service to the name of the port type, with "Service" appended to it.
522-
*/
499+
/** Sets the name of the service to the name of the port type, with "Service" appended to it. */
523500
protected void populateService(Service service) throws WSDLException {
524501
service.setQName(new QName(targetNamespace, portTypeName + SERVICE_SUFFIX));
525502
}

core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap11Wsdl4jDefinitionBuilderTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424

2525
import org.custommonkey.xmlunit.XMLTestCase;
2626
import org.custommonkey.xmlunit.XMLUnit;
27+
import org.w3c.dom.Document;
28+
2729
import org.springframework.core.io.ClassPathResource;
2830
import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
29-
import org.w3c.dom.Document;
31+
import org.springframework.xml.transform.StringResult;
3032

3133
public class XsdBasedSoap11Wsdl4jDefinitionBuilderTest extends XMLTestCase {
3234

@@ -144,6 +146,20 @@ public void testAirline() throws Exception {
144146
assertXMLEqual("Invalid WSDL built", expected, result);
145147
}
146148

149+
public void testNoSchemaPrefix() throws Exception {
150+
builder.setSchema(new ClassPathResource("single.xsd", getClass()));
151+
builder.setPortTypeName("Order");
152+
builder.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions");
153+
builder.setSchemaPrefix("");
154+
builder.afterPropertiesSet();
155+
156+
buildAll();
157+
158+
Wsdl11Definition definition = builder.getDefinition();
159+
160+
transformer.transform(definition.getSource(), new StringResult());
161+
}
162+
147163
private void buildAll() {
148164
builder.buildDefinition();
149165
builder.buildImports();

core/src/test/java/org/springframework/ws/wsdl/wsdl11/builder/XsdBasedSoap12Wsdl4jDefinitionBuilderTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424

2525
import org.custommonkey.xmlunit.XMLTestCase;
2626
import org.custommonkey.xmlunit.XMLUnit;
27+
import org.w3c.dom.Document;
28+
2729
import org.springframework.core.io.ClassPathResource;
2830
import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
29-
import org.w3c.dom.Document;
31+
import org.springframework.xml.transform.StringResult;
3032

3133
public class XsdBasedSoap12Wsdl4jDefinitionBuilderTest extends XMLTestCase {
3234

@@ -73,6 +75,20 @@ public void testAirline() throws Exception {
7375
assertXMLEqual("Invalid WSDL built", expected, result);
7476
}
7577

78+
public void testNoSchemaPrefix() throws Exception {
79+
builder.setSchema(new ClassPathResource("single.xsd", getClass()));
80+
builder.setPortTypeName("Order");
81+
builder.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions");
82+
builder.setSchemaPrefix("");
83+
builder.afterPropertiesSet();
84+
85+
buildAll();
86+
87+
Wsdl11Definition definition = builder.getDefinition();
88+
89+
transformer.transform(definition.getSource(), new StringResult());
90+
}
91+
7692
private void buildAll() {
7793
builder.buildDefinition();
7894
builder.buildImports();

0 commit comments

Comments
 (0)