You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2007/03/27 00:12:44 UTC

svn commit: r522644 - in /incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src: main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/ test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/

Author: dkulp
Date: Mon Mar 26 15:12:43 2007
New Revision: 522644

URL: http://svn.apache.org/viewvc?view=rev&rev=522644
Log:
Fix problems if jaxws customization file doesn't use the same namespace prefixes as the target wsdl

Added:
    incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding3.xml   (with props)
Modified:
    incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/CustomizationParser.java
    incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilderTest.java

Modified: incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/CustomizationParser.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/CustomizationParser.java?view=diff&rev=522644&r1=522643&r2=522644
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/CustomizationParser.java (original)
+++ incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/CustomizationParser.java Mon Mar 26 15:12:43 2007
@@ -25,8 +25,10 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Logger;
 
 import javax.xml.namespace.NamespaceContext;
@@ -161,8 +163,17 @@
         }
 
         if (isGlobaleBindings(bindings)) {
-            Node node = queryXPathNode(wsdlNode, "//wsdl:definitions");
-            copyBindingsToWsdl(node, bindings);
+            String pfx = wsdlNode.getPrefix();
+            if (pfx == null) {
+                pfx = "";
+            } else {
+                pfx += ":";
+            }
+            ContextImpl ctx = new ContextImpl(wsdlNode);
+            Node node = queryXPathNode(wsdlNode, 
+                                       ctx,
+                                       "//" + pfx + "definitions");
+            copyBindingsToWsdl(node, bindings, ctx);
         }
 
         if (isJAXWSBindings(bindings) && bindings.getAttributeNode("node") != null) {
@@ -171,9 +182,10 @@
             Node node = null;
             NodeList nestedJaxbNodes = getNestedJaxbBinding(bindings);
 
-            node = queryXPathNode(wsdlNode, expression);
+            ContextImpl ctx = new ContextImpl(bindings);
+            node = queryXPathNode(wsdlNode, ctx, expression);
             if (node != null && nestedJaxbNodes.getLength() == 0) {
-                copyBindingsToWsdl(node, bindings);
+                copyBindingsToWsdl(node, bindings, ctx);
             }
 
             if (node != null && nestedJaxbNodes.getLength() != 0) {
@@ -184,7 +196,10 @@
                     String xpathExpress = DOMUtils.getAttribute(jaxbNode, "node");
 
                     Node schemaNode = getSchemaNode(node);
-                    Node targetNode = queryXPathNode(schemaNode, xpathExpress);
+
+                    ctx = new ContextImpl(bindings);
+                    Node targetNode = queryXPathNode(schemaNode, ctx, xpathExpress);
+                    //@@TODO - copy namespaces
                     Element schemaElement = (Element)schemaNode;
                     // Element targetElement = (Element)targetNode;
 
@@ -227,10 +242,18 @@
         }
     }
 
-    private void copyBindingsToWsdl(Node node, Node bindings) {
+    private void copyBindingsToWsdl(Node node, Node bindings, ContextImpl ctx) {
         if (bindings.getNamespaceURI().equals(ToolConstants.JAXWS_BINDINGS.getNamespaceURI())) {
             bindings.setPrefix("jaxws");
         }
+        
+        for (Map.Entry<String, String> ent : ctx.getUsedNamespaces().entrySet()) {
+            if (node.lookupNamespaceURI(ent.getKey()) == null) {
+                node.getOwnerDocument().getDocumentElement()
+                    .setAttribute("xmlns:" + ent.getKey(), ent.getValue());
+            }
+            
+        }
 
         for (int i = 0; i < bindings.getChildNodes().getLength(); i++) {
             Node childNode = bindings.getChildNodes().item(i);
@@ -393,13 +416,18 @@
 
     class ContextImpl implements NamespaceContext {
         private Node targetNode;
-
+        private Map<String, String> pfxMap = new HashMap<String, String>();
+        
         public ContextImpl(Node node) {
             targetNode = node;
         }
 
         public String getNamespaceURI(String prefix) {
-            return targetNode.getOwnerDocument().lookupNamespaceURI(prefix);
+            String s = targetNode.lookupNamespaceURI(prefix);
+            if (prefix != null) { 
+                pfxMap.put(prefix, s);
+            }
+            return s;
         }
 
         public String getPrefix(String nsURI) {
@@ -409,12 +437,16 @@
         public Iterator getPrefixes(String namespaceURI) {
             throw new UnsupportedOperationException();
         }
+        
+        public Map<String, String> getUsedNamespaces() {
+            return pfxMap;
+        }
     }
 
-    private Node queryXPathNode(Node target, String expression) {
+    private Node queryXPathNode(Node target, ContextImpl nsCtx, String expression) {
         NodeList nlst;
         try {
-            xpath.setNamespaceContext(new ContextImpl(target));
+            xpath.setNamespaceContext(nsCtx);
             nlst = (NodeList)xpath.evaluate(expression, target, XPathConstants.NODESET);
         } catch (XPathExpressionException e) {
             Message msg = new Message("XPATH_ERROR", LOG, new Object[] {expression});

Modified: incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilderTest.java?view=diff&rev=522644&r1=522643&r2=522644
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilderTest.java (original)
+++ incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilderTest.java Mon Mar 26 15:12:43 2007
@@ -50,6 +50,7 @@
         env = new ToolContext();
     }
 
+    
     public void testBuildDefinitionWithXMLBinding() {
         String qname = "http://apache.org/hello_world_xml_http/bare";
         String wsdlUrl = getClass().getResource("hello_world_xml_bare.wsdl").toString();
@@ -154,4 +155,51 @@
             .getJaxwsPara().getMessageName());
         assertEquals("customized parameter name does not parsered", "num1", binding.getJaxwsPara().getName());
     }
+    
+    
+    
+    
+    public void testCustomizationWithDifferentNS() {
+        env.put(ToolConstants.CFG_WSDLURL, getClass().getResource("./hello_world.wsdl").toString());
+        env.put(ToolConstants.CFG_BINDING, getClass().getResource("./binding3.xml").toString());
+        JAXWSDefinitionBuilder builder = new JAXWSDefinitionBuilder();
+        builder.setContext(env);
+        builder.build();
+        builder.customize();
+
+        Definition customizedDef = builder.getWSDLModel();
+        List defExtensionList = customizedDef.getExtensibilityElements();
+        Iterator ite = defExtensionList.iterator();
+
+        while (ite.hasNext()) {
+            ExtensibilityElement extElement = (ExtensibilityElement)ite.next();
+            JAXWSBinding binding = (JAXWSBinding)extElement;
+            assertEquals("Customized package name does not been parsered", "com.foo", binding.getPackage());
+            assertEquals("Customized enableAsync does not parsered", true, binding.isEnableAsyncMapping());
+        }
+
+        PortType portType = customizedDef.getPortType(new QName("http://apache.org/hello_world_soap_http",
+                                                                "Greeter"));
+
+        List portTypeList = portType.getExtensibilityElements();
+        JAXWSBinding binding = (JAXWSBinding)portTypeList.get(0);
+
+        assertEquals("Customized enable EnableWrapperStyle name does not been parsered", true, binding
+            .isEnableWrapperStyle());
+       
+        List opList = portType.getOperations();
+        Operation operation = (Operation)opList.get(0);
+        List extList = operation.getExtensibilityElements();
+        binding = (JAXWSBinding)extList.get(0);
+
+        assertEquals("Customized method name does not parsered", "echoMeOneWay", binding.getMethodName());
+        
+        
+        assertEquals("Customized parameter element name does not parsered", "tns:number1", binding
+            .getJaxwsPara().getElementName());
+        assertEquals("Customized parameter message name does not parsered", "greetMeOneWayRequest", binding
+            .getJaxwsPara().getMessageName());
+        assertEquals("customized parameter name does not parsered", "num1", binding.getJaxwsPara().getName());
+    }
+    
 }

Added: incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding3.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding3.xml?view=auto&rev=522644
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding3.xml (added)
+++ incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding3.xml Mon Mar 26 15:12:43 2007
@@ -0,0 +1,47 @@
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements. See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership. The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License. You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied. See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+<jaxws:bindings
+	wsdlLocation="hello_world.wsdl"
+	xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+	xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
+	xmlns:wsdlFoo="http://schemas.xmlsoap.org/wsdl/"
+	xmlns:tns="http://apache.org/hello_world_soap_http"
+	xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+	<jaxws:package name="com.foo" />
+	<jaxws:enableAsyncMapping>true</jaxws:enableAsyncMapping>
+
+	<jaxws:bindings node="wsdlFoo:portType[@name='Greeter']">
+		<jaxws:enableAsyncMapping>true</jaxws:enableAsyncMapping>		
+		<jaxws:bindings
+			node="wsdlFoo:operation[@name='greetMeOneWay']">
+			<jaxws:method name="echoMeOneWay" />
+			<jaxws:parameter part="wsdlFoo:message[@name='greetMeOneWayRequest']/wsdlFoo:part[@name='in']" childElementName="tns:number1" name="num1"/>
+		</jaxws:bindings>
+	</jaxws:bindings>
+
+	<jaxws:bindings node="wsdlFoo:definitions/wsdlFoo:types/xsd:schema">
+		<jaxb:bindings version="2.0" node="xsd:element[@name='CreateProcess']/xsd:complexType/xsd:sequence/xsd:element[@name='MyProcess']/xsd:simpleType">
+				<jaxb:typesafeEnumClass name="MyProcess">
+					<jaxb:typesafeEnumMember name="BLUE" value="BLUE" />
+					<jaxb:typesafeEnumMember name="RED" value="RED" />
+					<jaxb:typesafeEnumMember name="GREEN" value="GREEN" />
+				</jaxb:typesafeEnumClass>
+	        </jaxb:bindings>
+	</jaxws:bindings>
+</jaxws:bindings>
\ No newline at end of file

Propchange: incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding3.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding3.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding3.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml