diff --git a/src/main/java/org/wso2/soaptorest/SOAPRequestBodyGenerator.java b/src/main/java/org/wso2/soaptorest/SOAPRequestBodyGenerator.java index d45ef59..8356e32 100644 --- a/src/main/java/org/wso2/soaptorest/SOAPRequestBodyGenerator.java +++ b/src/main/java/org/wso2/soaptorest/SOAPRequestBodyGenerator.java @@ -352,7 +352,11 @@ private static Document createSOAPRequestXMLForOperation(ArrayList param path = path.concat(escapeFreeMarkerTemplate(parameterTreeNodes[j])).concat("."); } element.setAttribute(IS_EMPTY_ATTRIBUTE, "true"); - element.setAttribute(VALUE_ATTRIBUTE, path.substring(0, path.length() - 1)); + if (path.length() == 0) { + element.setAttribute(VALUE_ATTRIBUTE, ""); + } else { + element.setAttribute(VALUE_ATTRIBUTE, path.substring(0, path.length() - 1)); + } } if (prevElement != null) { prevElement.appendChild(element); diff --git a/src/test/java/org/wso2/soaptorest/SOAPToRESTConverterTest.java b/src/test/java/org/wso2/soaptorest/SOAPToRESTConverterTest.java index 5d01cf8..8aab3c9 100644 --- a/src/test/java/org/wso2/soaptorest/SOAPToRESTConverterTest.java +++ b/src/test/java/org/wso2/soaptorest/SOAPToRESTConverterTest.java @@ -54,4 +54,18 @@ void testURLGetSOAPtoRESTConversionData() throws MalformedURLException, SOAPToRE } -} \ No newline at end of file + @Test + void testIssue28() throws MalformedURLException, SOAPToRESTException { + + URL url = new URL( + "https://raw.githubusercontent.com/indika-dev/soap-to-rest/main/src/test/resources/issue-28/failing.wsdl"); + SOAPtoRESTConversionData soaPtoRESTConversionData = + SOAPToRESTConverter.getSOAPtoRESTConversionData(url, "Test API", "1.0.0"); + assertTrue(StringUtils.isNotBlank(soaPtoRESTConversionData.getOASString())); + assertEquals(1, soaPtoRESTConversionData.getAllSOAPRequestBodies().size()); + assertEquals(soaPtoRESTConversionData.getSoapService(), "myServer"); + assertEquals(soaPtoRESTConversionData.getSoapPort(), "myServerSOAP"); + + } + +} diff --git a/src/test/resources/issue-28/failing.wsdl b/src/test/resources/issue-28/failing.wsdl new file mode 100644 index 0000000..76fd15c --- /dev/null +++ b/src/test/resources/issue-28/failing.wsdl @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +