You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by de...@apache.org on 2006/03/28 05:55:51 UTC

svn commit: r389385 - in /webservices/axis2/trunk/java/modules: core/src/org/apache/axis2/description/ integration/test/org/apache/axis2/engine/ java2wsdl/src/org/apache/ws/java2wsdl/

Author: deepal
Date: Mon Mar 27 19:55:49 2006
New Revision: 389385

URL: http://svn.apache.org/viewcvs?rev=389385&view=rev
Log:
?wsdl works using OM

Added:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java
Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/WSDLClientTest.java
    webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2OMBuilder.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java?rev=389385&r1=389384&r2=389385&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java Mon Mar 27 19:55:49 2006
@@ -34,8 +34,6 @@
 import org.apache.axis2.transport.TransportListener;
 import org.apache.axis2.util.PolicyUtil;
 import org.apache.axis2.util.XMLUtils;
-import org.apache.axis2.wsdl.writer.WOMWriter;
-import org.apache.axis2.wsdl.writer.WOMWriterFactory;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ws.commons.schema.XmlSchema;
@@ -43,7 +41,6 @@
 import org.apache.ws.java2wsdl.SchemaGenerator;
 import org.apache.ws.java2wsdl.utils.TypeTable;
 import org.apache.wsdl.WSDLConstants;
-import org.apache.wsdl.WSDLDescription;
 import org.codehaus.jam.JMethod;
 import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
@@ -483,20 +480,19 @@
     }
 
     private void printUsingWOM(OutputStream out, String [] serviceURL) throws AxisFault {
-        AxisService2WOM axisService2WOM = new AxisService2WOM(getSchema(),
-                this,
-                targetNamespace,
-                targetNamespacePrefix,
-                serviceURL);
+        AxisService2OM axisService2WOM = new AxisService2OM(getSchema(), this, serviceURL, "document", "literal");
         try {
-            WSDLDescription desc = axisService2WOM.generateWOM();
-
-            // populate it with policy information ..
-            PolicyUtil.populatePolicy(desc, this);
-
-            WOMWriter womWriter = WOMWriterFactory.createWriter(WSDLConstants.WSDL_1_1);
-            womWriter.setdefaultWSDLPrefix("wsdl");
-            womWriter.writeWOM(desc, out);
+            OMElement wsdlElement = axisService2WOM.generateOM();
+            wsdlElement.serialize(out);
+            out.flush();
+            out.close();
+//
+//            // populate it with policy information ..
+//            PolicyUtil.populatePolicy(desc, this);
+//
+//            WOMWriter womWriter = WOMWriterFactory.createWriter(WSDLConstants.WSDL_1_1);
+//            womWriter.setdefaultWSDLPrefix("wsdl");
+//            womWriter.writeWOM(desc, out);
 
         } catch (Exception e) {
             throw new AxisFault(e);

Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java?rev=389385&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java (added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java Mon Mar 27 19:55:49 2006
@@ -0,0 +1,244 @@
+package org.apache.axis2.description;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.ws.commons.schema.XmlSchema;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import java.io.ByteArrayInputStream;
+import java.io.StringWriter;
+import java.util.Iterator;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.
+*
+*
+*/
+
+public class AxisService2OM implements org.apache.ws.java2wsdl.Constants {
+
+    private XmlSchema schema;
+
+    private AxisService axisService;
+
+    private String [] url;
+
+    private String targetNamespace;
+    private OMNamespace ns1;
+    private OMNamespace soap;
+    private OMNamespace tns;
+    private OMNamespace wsdl;
+
+    private String style;
+    private String use;
+
+    public AxisService2OM(XmlSchema schema, AxisService service,
+                          String [] serviceURL, String style, String use) {
+        this.schema = schema;
+        this.axisService = service;
+        url = serviceURL;
+
+        this.schema = schema;
+        if (style == null) {
+            this.style = DOCUMNT;
+        } else {
+            this.style = style;
+        }
+        if (use == null) {
+            this.use = LITERAL;
+        } else {
+            this.use = use;
+        }
+        this.targetNamespace = service.getTargetNamespace();
+    }
+
+    public OMElement generateOM() throws Exception {
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        wsdl = fac.createOMNamespace(WSDL_NAMESPACE,
+                DEFAULT_WSDL_NAMESPACE_PREFIX);
+        OMElement ele = fac.createOMElement("definitions", wsdl);
+        ns1 = ele.declareNamespace(AXIS2_XSD, "ns1");
+        ele.declareNamespace(SCHEMA_NAME_SPACE, DEFAULT_SCHEMA_NAMESPACE_PREFIX);
+        soap = ele.declareNamespace(DEFAULT_SOAP_NAMESPACE, DEFAULT_SOAP_NAMESPACE_PREFIX);
+        tns = ele.declareNamespace(DEFAULT_TARGET_NAMESPACE, TARGETNAMESPACE_PREFIX);
+        ele.addAttribute("targetNamespace", DEFAULT_TARGET_NAMESPACE, null);
+        OMElement wsdlTypes = fac.createOMElement("types", wsdl);
+        StringWriter writer = new StringWriter();
+        schema.write(writer);
+        XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(new
+                ByteArrayInputStream(writer.toString().getBytes()));
+
+        StAXOMBuilder staxOMBuilder = new
+                StAXOMBuilder(fac, xmlReader);
+        wsdlTypes.addChild(staxOMBuilder.getDocumentElement());
+        ele.addChild(wsdlTypes);
+        generateMessages(fac, ele);
+        generatePortType(fac, ele);
+        generateBinding(fac, ele);
+        generateService(fac, ele);
+        return ele;
+    }
+
+    private void generateMessages(OMFactory fac,
+                                  OMElement defintions) {
+        Iterator operations = axisService.getOperations();
+        while (operations.hasNext()) {
+            AxisOperation axisOperation = (AxisOperation) operations.next();
+            String operationName = axisOperation.getName().getLocalPart();
+            //Request Message
+            OMElement requestMessge = fac.createOMElement(MESSAGE_LOCAL_NAME, wsdl);
+            requestMessge.addAttribute(ATTRIBUTE_NAME, operationName
+                    + REQUEST_MESSAGE, null);
+            defintions.addChild(requestMessge);
+            OMElement requestPart = fac.createOMElement(PART_ATTRIBUTE_NAME, wsdl);
+            requestMessge.addChild(requestPart);
+            requestPart.addAttribute(ATTRIBUTE_NAME, "part1", null);
+            requestPart.addAttribute(ELEMENT_ATTRIBUTE_NAME,
+                    ns1.getPrefix() + ":" + operationName
+                            + REQUEST, null);
+            //Response Message
+            OMElement responseMessge = fac.createOMElement(MESSAGE_LOCAL_NAME, wsdl);
+            responseMessge.addAttribute(ATTRIBUTE_NAME,
+                    operationName + RESPONSE_MESSAGE, null);
+            defintions.addChild(responseMessge);
+            OMElement responsePart = fac.createOMElement(PART_ATTRIBUTE_NAME, wsdl);
+            responseMessge.addChild(responsePart);
+            responsePart.addAttribute(ATTRIBUTE_NAME, "part1", null);
+            responsePart.addAttribute(ELEMENT_ATTRIBUTE_NAME,
+                    ns1.getPrefix() + ":" + operationName + RESPONSE, null);
+        }
+    }
+
+    /**
+     * Generate the porttypes
+     */
+    private void generatePortType(OMFactory fac,
+                                  OMElement defintions) {
+        OMElement portType = fac.createOMElement(PORT_TYPE_LOCAL_NAME, wsdl);
+        defintions.addChild(portType);
+        portType.addAttribute(ATTRIBUTE_NAME, axisService.getName() + PORT_TYPE_SUFFIX, null);
+
+        Iterator operations = axisService.getOperations();
+        while (operations.hasNext()) {
+            AxisOperation axisOperation = (AxisOperation) operations.next();
+            if (axisOperation.isControlOperation()) {
+                continue;
+            }
+            String operationName = axisOperation.getName().getLocalPart();
+            OMElement operation = fac.createOMElement(OPERATION_LOCAL_NAME, wsdl);
+            portType.addChild(operation);
+            operation.addAttribute(ATTRIBUTE_NAME, operationName, null);
+
+            OMElement input = fac.createOMElement(IN_PUT_LOCAL_NAME, wsdl);
+            input.addAttribute(MESSAGE_LOCAL_NAME, tns.getPrefix() + ":"
+                    + operationName + REQUEST_MESSAGE, null);
+            operation.addChild(input);
+
+            OMElement output = fac.createOMElement(OUT_PUT_LOCAL_NAME, wsdl);
+            output.addAttribute(MESSAGE_LOCAL_NAME, tns.getPrefix() + ":"
+                    + operationName + RESPONSE_MESSAGE, null);
+            operation.addChild(output);
+        }
+    }
+
+    /**
+     * Generate the service
+     */
+    public void generateService(OMFactory fac,
+                                OMElement defintions) {
+        OMElement service = fac.createOMElement(SERVICE_LOCAL_NAME, wsdl);
+        defintions.addChild(service);
+        service.addAttribute(ATTRIBUTE_NAME, axisService.getName(), null);
+        for (int i = 0; i < url.length; i++) {
+            String urlString = url[i];
+            OMElement port = fac.createOMElement(PORT, wsdl);
+            service.addChild(port);
+            port.addAttribute(ATTRIBUTE_NAME, axisService.getName() + PORT + i, null);
+            port.addAttribute(BINDING_LOCAL_NAME, tns.getPrefix() + ":" +
+                    axisService.getName() + BINDING_NAME_SUFFIX, null);
+            addExtensionElemnet(fac, port, SOAP_ADDRESS, LOCATION,
+                    urlString);
+        }
+
+
+    }
+
+    /**
+     * Generate the bindings
+     */
+    private void generateBinding(OMFactory fac,
+                                 OMElement defintions) {
+        OMElement binding = fac.createOMElement(BINDING_LOCAL_NAME, wsdl);
+        defintions.addChild(binding);
+        binding.addAttribute(ATTRIBUTE_NAME, axisService.getName() + BINDING_NAME_SUFFIX, null);
+        binding.addAttribute("type", tns.getPrefix() + ":" + axisService.getName() + PORT_TYPE_SUFFIX, null);
+
+        addExtensionElemnet(fac, binding, BINDING_LOCAL_NAME,
+                TRANSPORT, TRANSPORT_URI,
+                STYLE, style);
+        Iterator operations = axisService.getOperations();
+        while (operations.hasNext()) {
+            AxisOperation axisOperation = (AxisOperation) operations.next();
+            if (axisOperation.isControlOperation()) {
+                continue;
+            }
+            String opeartionName = axisOperation.getName().getLocalPart();
+            OMElement operation = fac.createOMElement(OPERATION_LOCAL_NAME, wsdl);
+            binding.addChild(operation);
+            addExtensionElemnet(fac, operation, OPERATION_LOCAL_NAME,
+                    SOAP_ACTION, opeartionName,
+                    STYLE, style);
+            operation.addAttribute(ATTRIBUTE_NAME, opeartionName, null);
+
+            OMElement input = fac.createOMElement(IN_PUT_LOCAL_NAME, wsdl);
+            addExtensionElemnet(fac, input, SOAP_BODY, SOAP_USE, use, "namespace",
+                    targetNamespace);
+            operation.addChild(input);
+
+            OMElement output = fac.createOMElement(OUT_PUT_LOCAL_NAME, wsdl);
+            addExtensionElemnet(fac, output, SOAP_BODY, SOAP_USE, use, "namespace",
+                    targetNamespace);
+            operation.addChild(output);
+        }
+    }
+
+    private void addExtensionElemnet(OMFactory fac,
+                                     OMElement element,
+                                     String name,
+                                     String att1Name,
+                                     String att1Value,
+                                     String att2Name,
+                                     String att2Value) {
+        OMElement soapbinding = fac.createOMElement(name, soap);
+        element.addChild(soapbinding);
+        soapbinding.addAttribute(att1Name, att1Value, null);
+        soapbinding.addAttribute(att2Name, att2Value, null);
+    }
+
+    private void addExtensionElemnet(OMFactory fac,
+                                     OMElement element,
+                                     String name,
+                                     String att1Name,
+                                     String att1Value) {
+        OMElement soapbinding = fac.createOMElement(name, soap);
+        element.addChild(soapbinding);
+        soapbinding.addAttribute(att1Name, att1Value, null);
+    }
+
+
+}
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/WSDLClientTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/WSDLClientTest.java?rev=389385&r1=389384&r2=389385&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/WSDLClientTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/WSDLClientTest.java Mon Mar 27 19:55:49 2006
@@ -54,8 +54,8 @@
             URL wsdlURL = new URL("http://localhost:" + UtilServer.TESTING_PORT +
                     "/axis2/services/EchoXMLService?wsdl");
             ServiceClient serviceClient = new ServiceClient(null, wsdlURL,
-                    new QName("http://org.apache.axis2/", "EchoXMLService"),
-                    "EchoXMLServicePortType0");
+                    new QName("http://ws.apache.org/axis2", "EchoXMLService"),
+                    "EchoXMLServiceport0");
             OMElement payload = TestingUtils.createDummyOMElement();
             OMElement response = serviceClient.sendReceive(
                     new QName("http://org.apache.axis2/xsd", "echoOMElement"), payload);

Modified: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2OMBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2OMBuilder.java?rev=389385&r1=389384&r2=389385&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2OMBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2OMBuilder.java Mon Mar 27 19:55:49 2006
@@ -90,7 +90,7 @@
         soap = ele.declareNamespace(DEFAULT_SOAP_NAMESPACE, DEFAULT_SOAP_NAMESPACE_PREFIX);
         tns = ele.declareNamespace(DEFAULT_TARGET_NAMESPACE, TARGETNAMESPACE_PREFIX);
         ele.addAttribute("targetNamespace", DEFAULT_TARGET_NAMESPACE, null);
-        OMElement wsdlTypes = fac.createOMElement("type", wsdl);
+        OMElement wsdlTypes = fac.createOMElement("types", wsdl);
         StringWriter writer = new StringWriter();
         schema.write(writer);
         XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(new