This is an automated email from the ASF dual-hosted git repository.

billblough pushed a commit to branch AXIS2-4091
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git

commit 415e34a9591adfb3b2efe0111d4d28fbc9aa7ae6
Author: Andreas Veithen <veit...@apache.org>
AuthorDate: Sun Dec 17 21:14:43 2017 +0000

    Apply patch for AXIS2-4091 provided by Antonio Andrade and Matt Fluet.
---
 .../description/WSDL11ToAxisServiceBuilder.java    | 17 +++++++-
 .../WSDL11ToAxisServiceBuilderTest.java            | 50 ++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)

diff --git 
a/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
 
b/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
index 4c86c88..2b22013 100644
--- 
a/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
+++ 
b/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
@@ -1760,6 +1760,11 @@ public class WSDL11ToAxisServiceBuilder extends 
WSDLToAxisServiceBuilder {
                                                          namespacePrefixMap, 
                                                          boEntry);
 
+                // No wrapped element needs to be created
+                if (!boEntry.isWrappedInput()) {
+                  continue;
+                }
+
                 elementDeclaration.appendChild(newComplexType);
                 String namespaceToUse = namespaceURI;
 
@@ -1849,6 +1854,12 @@ public class WSDL11ToAxisServiceBuilder extends 
WSDLToAxisServiceBuilder {
                                                          namespaceImportsMap,
                                                          namespacePrefixMap,
                                                          boEntry);
+
+                // No wrapped element needs to be created
+                if (!boEntry.isWrappedInput()) {
+                  continue;
+                }
+
                 elementDeclaration.appendChild(newComplexType);
 
                 String namespaceToUse = namespaceURI;
@@ -2253,7 +2264,11 @@ public class WSDL11ToAxisServiceBuilder extends 
WSDLToAxisServiceBuilder {
                    "and use the type attribute.");
             } else {
                 // The presense of an element means that a wrapper xsd element 
is not needed.
-                boe.setWrappedOutput(false);
+                if (isOutMessage){
+                    boe.setWrappedOutput(false);
+                } else {
+                    boe.setWrappedInput(false);
+                }
                 if (log.isDebugEnabled()) {
                     log.debug("The binding operation " + bindingOperationName 
+ 
                               " references message part " +
diff --git 
a/modules/kernel/test/org/apache/axis2/description/WSDL11ToAxisServiceBuilderTest.java
 
b/modules/kernel/test/org/apache/axis2/description/WSDL11ToAxisServiceBuilderTest.java
index 4854c97..7f64d71 100644
--- 
a/modules/kernel/test/org/apache/axis2/description/WSDL11ToAxisServiceBuilderTest.java
+++ 
b/modules/kernel/test/org/apache/axis2/description/WSDL11ToAxisServiceBuilderTest.java
@@ -21,9 +21,18 @@ package org.apache.axis2.description;
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
 
 import javax.xml.namespace.QName;
 
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+
 import junit.framework.TestCase;
 
 public class WSDL11ToAxisServiceBuilderTest extends TestCase {
@@ -54,4 +63,45 @@ public class WSDL11ToAxisServiceBuilderTest extends TestCase 
{
             in.close();
         }
     }
+    
+    public void testNonDuplicatedElementsHttpBinding() throws Exception {
+        final String wsdlPath = 
"test-resources/wsdl/nonduplicatedElements.wsdl";
+        InputStream in = new FileInputStream(wsdlPath);
+        final String targetNamespace = "http://www.example.org";;
+        final QName serviceName = new QName(targetNamespace, "FooService");
+        final String portName = "FooHttpGetPort";
+          
+        AxisService service = new WSDL11ToAxisServiceBuilder(in, serviceName, 
portName).populateService();
+        List schemaDocuments = service.getSchema();
+        List duplicatedGlobalElements = 
findDuplicatedGlobalElements(schemaDocuments);
+        // NO duplicated element should exists
+        assertTrue("Duplicated global element declarations found in '" +  
wsdlPath, 
+            duplicatedGlobalElements.isEmpty());
+    }
+
+    protected List findDuplicatedGlobalElements(List schemaDocuments) {
+        List duplicatedGlobalElementDeclarations = new ArrayList();
+        Set globalElementDeclarations = new HashSet();
+        // Iterate over all schema documents
+        for (int i = 0; i < schemaDocuments.size(); i++) {
+            XmlSchema schemaDocument = (XmlSchema)schemaDocuments.get(i);
+            XmlSchemaObjectCollection items = schemaDocument.getItems();
+            for (Iterator itemsIt = items.getIterator(); itemsIt.hasNext();) {
+                XmlSchemaObject xmlSchemaObject = 
(XmlSchemaObject)itemsIt.next();
+                // Check only XML schema elements
+                if (xmlSchemaObject instanceof XmlSchemaElement) {
+                    QName elementName = 
((XmlSchemaElement)xmlSchemaObject).getQName();
+                    /* Was another element with the same name found in this or
+                      other XML schema document? */
+                    if (globalElementDeclarations.contains(elementName)) {
+                        duplicatedGlobalElementDeclarations.add(elementName);
+                    } else {
+                        globalElementDeclarations.add(elementName);
+                    }
+                }
+            }
+        }
+        return duplicatedGlobalElementDeclarations;
+    }
+
 }

Reply via email to