Skip to content

Commit

Permalink
fix: support messages having a part attribute without namespace prefix
Browse files Browse the repository at this point in the history
* Function to resolve the targetNamespace from the WSDL-document. If such a target namespace is declared and e.g. the element attribute of the message part has no namespace prefix, use that target namespace to construct a qualified name.
* Adapt random test WSDLs to have no namespace prefix

fixes outofcoffee#569
  • Loading branch information
driesva committed May 14, 2024
1 parent df6a332 commit 34f4502
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ abstract class AbstractWsdlParser(

protected abstract fun findEmbeddedTypesSchemaNodes(): List<Element>

protected abstract fun resolveTargetNamespace(): String?

protected fun selectSingleNodeWithName(context: Any, expressionTemplate: String, name: String): Element? {
return selectSingleNode(context, String.format(expressionTemplate, name))
?: name.takeIf { it.contains(":") }?.let {
Expand Down Expand Up @@ -191,6 +193,10 @@ abstract class AbstractWsdlParser(

val valueParts = attrValue.split(':')
if (valueParts.size == 1) {
val tns = resolveTargetNamespace()
if (tns != null) {
return QName(tns, valueParts[0]);
}
// unqualified name
return QName(valueParts[0])
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ class Wsdl1Parser(

override val services: List<WsdlService>
get() {
val tns = selectSingleNode(document, "/wsdl:definitions")
?.getAttribute("targetNamespace")?.value
val tns = resolveTargetNamespace()

val services = selectNodes(document, "/wsdl:definitions/wsdl:service")

Expand Down Expand Up @@ -297,6 +296,11 @@ class Wsdl1Parser(
return BodyQueryUtil.selectNodes(document, "/wsdl:definitions/wsdl:types/xs:schema", xsNamespaces)
}

override fun resolveTargetNamespace(): String? {
return selectSingleNode(document, "/wsdl:definitions")
?.getAttribute("targetNamespace")?.value
}

/**
* @return a human-readable description of the node
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ class Wsdl2Parser(
return BodyQueryUtil.selectNodes(document, "/wsdl:description/wsdl:types/xs:schema", xsNamespaces)
}

override fun resolveTargetNamespace(): String? {
return selectSingleNode(document, "/wsdl:description")
?.getAttribute("targetNamespace")?.value
}

companion object {
const val wsdl2Namespace = "http://www.w3.org/ns/wsdl"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

<message name="getPetByIdRequest">
<part type="xs:string" name="header"/>
<part element="tns:getPetByIdRequest" name="body"/>
<part element="getPetByIdRequest" name="body"/>
</message>
<message name="getPetByIdResponse">
<part element="tns:getPetByIdResponse" name="body"/>
Expand Down
2 changes: 1 addition & 1 deletion mock/soap/src/test/resources/wsdl2-soap12/service.wsdl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ http://www.w3.org/ns/wsdl/soap http://www.w3.org/2002/ws/desc/ns/soap.xsd">

<operation name="getPetById" pattern="http://www.w3.org/ns/wsdl/in-out">
<wsoap:operation soapAction="getPetById" style="document"/>
<input messageLabel="In" element="tns:getPetByIdRequest"/>
<input messageLabel="In" element="getPetByIdRequest"/>
<output messageLabel="Out" element="tns:getPetByIdResponse"/>
</operation>

Expand Down

0 comments on commit 34f4502

Please sign in to comment.