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 am...@apache.org on 2006/12/06 11:56:37 UTC

svn commit: r483023 - in /webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl: codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java template/java/InterfaceImplementationTemplate.xsl

Author: amilas
Date: Wed Dec  6 02:56:36 2006
New Revision: 483023

URL: http://svn.apache.org/viewvc?view=rev&rev=483023
Log:
Added Http headers to generated code

Modified:
    webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java
    webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl

Modified: webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java?view=diff&rev=483023&r1=483022&r2=483023
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java (original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java Wed Dec  6 02:56:36 2006
@@ -592,7 +592,7 @@
         doc.appendChild(rootElement);
 
         //////////////////////////////////////////////////////////
-//        System.out.println(DOM2Writer.nodeToString(rootElement));
+        System.out.println(DOM2Writer.nodeToString(rootElement));
         ////////////////////////////////////////////////////////////
         return doc;
     }
@@ -1273,8 +1273,7 @@
         // First Iterate through the operations and find the relevant fromOM and toOM methods to be generated
         ArrayList parameters = new ArrayList();
 
-        for (Iterator operationsIterator = axisService.getOperations(); operationsIterator.hasNext();)
-        {
+        for (Iterator operationsIterator = axisService.getOperations(); operationsIterator.hasNext();) {
             AxisOperation axisOperation = (AxisOperation) operationsIterator.next();
 
             // Add the parameters to a map with their type as the key
@@ -1390,8 +1389,7 @@
                 }
             }
         }
-        for (Iterator operationsIterator = axisService.getOperations(); operationsIterator.hasNext();)
-        {
+        for (Iterator operationsIterator = axisService.getOperations(); operationsIterator.hasNext();) {
             AxisOperation axisOperation = (AxisOperation) operationsIterator.next();
             details = axisOperation.getParameter(Constants.DATABINDING_OPERATION_DETAILS);
             if (details != null) {
@@ -1438,8 +1436,7 @@
         Element root = doc.createElement("opnames");
         Element elt;
 
-        for (Iterator operationsIterator = axisService.getOperations(); operationsIterator.hasNext();)
-        {
+        for (Iterator operationsIterator = axisService.getOperations(); operationsIterator.hasNext();) {
             AxisOperation axisOperation = (AxisOperation) operationsIterator.next();
             elt = doc.createElement("name");
             elt.appendChild(doc.createTextNode(axisOperation.getName().getLocalPart()));
@@ -2008,7 +2005,7 @@
         String MEP = axisOperation.getMessageExchangePattern();
         if (input) {
             if (WSDLUtil.isInputPresentForMEP(MEP)) {
-               headerparamList = (ArrayList) getBindingPropertyFromMessage(WSDL2Constants.ATTR_WSOAP_HEADER, axisOperation.getName(), WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
+                headerparamList = (ArrayList) getBindingPropertyFromMessage(WSDL2Constants.ATTR_WSOAP_HEADER, axisOperation.getName(), WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
 
             }
         } else {
@@ -2016,6 +2013,29 @@
                 headerparamList = (ArrayList) getBindingPropertyFromMessage(WSDL2Constants.ATTR_WSOAP_HEADER, axisOperation.getName(), WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT);
             }
         }
+        if (headerparamList != null) {
+            for (Iterator iterator = headerparamList.iterator(); iterator.hasNext();) {
+                SOAPHeaderMessage header = (SOAPHeaderMessage) iterator.next();
+                soapHeaderParameterQNameList.add(header.getElement());
+            }
+        }
+
+    }
+
+    /**
+     * populate the header parameters to faults
+     *
+     * @param soapHeaderParameterQNameList
+     * @param axisOperation
+     */
+    protected void addHeaderOperationsToFault(List soapHeaderParameterQNameList, AxisOperation axisOperation) {
+        ArrayList headerparamList = new ArrayList();
+        ArrayList faultMessages = axisOperation.getFaultMessages();
+        Iterator iter = faultMessages.iterator();
+        while (iter.hasNext()) {
+            AxisMessage axisFaultMessage = (AxisMessage) iter.next();
+            headerparamList.addAll((ArrayList) getBindingPropertyFromMessageFault(WSDL2Constants.ATTR_WSOAP_HEADER, axisOperation.getName(), axisFaultMessage.getName()));
+        }
 
         if (headerparamList != null) {
             for (Iterator iterator = headerparamList.iterator(); iterator.hasNext();) {
@@ -2067,7 +2087,7 @@
             }
 
             List parameterElementList = getParameterElementList(doc, headerParameterQNameList, WSDLConstants.SOAP_HEADER);
-            parameterElementList.addAll(getParameterElementListForHttpHeader(doc,(ArrayList)getBindingPropertyFromMessage(WSDL2Constants.ATTR_WHTTP_HEADER,operation.getName(), WSDLConstants.WSDL_MESSAGE_DIRECTION_IN),WSDLConstants.HTTP_HEADER));
+            parameterElementList.addAll(getParameterElementListForHttpHeader(doc, (ArrayList) getBindingPropertyFromMessage(WSDL2Constants.ATTR_WHTTP_HEADER, operation.getName(), WSDLConstants.WSDL_MESSAGE_DIRECTION_IN), WSDLConstants.HTTP_HEADER));
 
             for (int i = 0; i < parameterElementList.size(); i++) {
                 inputElt.appendChild((Element) parameterElementList.get(i));
@@ -2090,7 +2110,7 @@
             faultElt.appendChild(param[i]);
         }
 
-       return faultElt;
+        return faultElt;
     }
 
     /**
@@ -2132,7 +2152,7 @@
             }
 
             List outputElementList = getParameterElementList(doc, headerParameterQNameList, WSDLConstants.SOAP_HEADER);
-            outputElementList.addAll(getParameterElementListForHttpHeader(doc,(ArrayList)getBindingPropertyFromMessage(WSDL2Constants.ATTR_WHTTP_HEADER,operation.getName(), WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT),WSDLConstants.HTTP_HEADER));
+            outputElementList.addAll(getParameterElementListForHttpHeader(doc, (ArrayList) getBindingPropertyFromMessage(WSDL2Constants.ATTR_WHTTP_HEADER, operation.getName(), WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT), WSDLConstants.HTTP_HEADER));
 
             for (int i = 0; i < outputElementList.size(); i++) {
                 outputElt.appendChild((Element) outputElementList.get(i));
@@ -2477,7 +2497,10 @@
         return parameterElementList;
     }
 
+
     protected List getParameterElementListForHttpHeader(Document doc, List parameters, String location) {
+
+
         List parameterElementList = new ArrayList();
 
         if ((parameters != null) && !parameters.isEmpty()) {
@@ -2485,11 +2508,14 @@
 
             for (int i = 0; i < count; i++) {
                 Element param = doc.createElement("param");
-                HTTPHeaderMessage httpHeaderMessage = (HTTPHeaderMessage)parameters.get(i);
+                HTTPHeaderMessage httpHeaderMessage = (HTTPHeaderMessage) parameters.get(i);
                 QName qName = httpHeaderMessage.getqName();
                 String name = httpHeaderMessage.getName();
 
-                addAttribute(doc, "name", name, param);
+                // use name as the name attribute of the parameter
+                addAttribute(doc, "name", JavaUtils.xmlNameToJavaIdentifier(name), param);
+                // header name is to set the header value
+                addAttribute(doc, "headername", name, param);
 
                 String typeMapping = this.mapper.getTypeMappingName(qName);
                 String typeMappingStr = (typeMapping == null)

Modified: webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl?view=diff&rev=483023&r1=483022&r2=483023
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl (original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl Wed Dec  6 02:56:36 2006
@@ -267,6 +267,9 @@
               _operationClient.getOptions().setAction("<xsl:value-of select="$soapAction"/>");
               _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
 
+              // create a message context
+              org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext();
+
               <!--todo if the stub was generated with unwrapping, wrap all parameters into a single element-->
 
               // create SOAP envelope with that payload
@@ -323,13 +326,20 @@
                                         </xsl:otherwise>
                                     </xsl:choose>
 
-                                   <xsl:if test="count(input/param[@location='header']) &gt; 0">
+                                   <xsl:if test="count(input/param[@location='soap_header']) &gt; 0">
                                                env.build();
                                     </xsl:if>
-                                    <xsl:for-each select="input/param[@location='header']">
+                                    <xsl:for-each select="input/param[@location='soap_header']">
+                                        // add the children only if the parameter is not null
+                                        if (<xsl:value-of select="@name"/>!=null){
+                                            env.getHeader().addChild(toOM(<xsl:value-of select="@name"/>, optimizeContent(new javax.xml.namespace.QName("<xsl:value-of select="$method-ns"/>", "<xsl:value-of select="$method-name"/>"))));
+                                        }
+                                    </xsl:for-each>
+
+                                    <xsl:for-each select="input/param[@location='http_header']">
                                         // add the children only if the parameter is not null
                                         if (<xsl:value-of select="@name"/>!=null){
-                                        env.getHeader().addChild(toOM(<xsl:value-of select="@name"/>, optimizeContent(new javax.xml.namespace.QName("<xsl:value-of select="$method-ns"/>", "<xsl:value-of select="$method-name"/>"))));
+                                            addHttpHeader(_messageContext,"<xsl:value-of select="@headername"/>",<xsl:value-of select="@name"/>);
                                         }
                                     </xsl:for-each>
                                 </xsl:when>
@@ -353,10 +363,9 @@
                             </xsl:choose>
                         </xsl:otherwise>
                     </xsl:choose>
-        //adding SOAP headers
+        //adding SOAP soap_headers
          _serviceClient.addHeadersToEnvelope(env);
-        // create message context with that soap envelope
-        org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext() ;
+        // set the message context with that soap envelope
         _messageContext.setEnvelope(env);
 
         // add the message contxt to the operation client
@@ -496,6 +505,8 @@
 
               // create SOAP envelope with that payload
               org.apache.axiom.soap.SOAPEnvelope env=null;
+              org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext();
+
                     <xsl:variable name="count" select="count(input/param[@type!=''])"/>
                     <xsl:choose>
                         <!-- test the number of input parameters
@@ -536,12 +547,18 @@
                                         </xsl:otherwise>
                                     </xsl:choose>
 
-                                    <xsl:for-each select="input/param[@location='header']">
-                                         // add the headers only if they are not null
+                                    <xsl:for-each select="input/param[@location='soap_header']">
+                                         // add the soap_headers only if they are not null
                                         if (<xsl:value-of select="@name"/>!=null){
                                            env.getHeader().addChild(toOM(<xsl:value-of select="@name"/>, optimizeContent(new javax.xml.namespace.QName("<xsl:value-of select="$method-ns"/>", "<xsl:value-of select="$method-name"/>"))));
                                         }
                                     </xsl:for-each>
+                                     <xsl:for-each select="input/param[@location='http_header']">
+                                        // add the children only if the parameter is not null
+                                        if (<xsl:value-of select="@name"/>!=null){
+                                            addHttpHeader(_messageContext,"<xsl:value-of select="@headername"/>",<xsl:value-of select="@name"/>);
+                                        }
+                                    </xsl:for-each>
                                 </xsl:when>
                                 <xsl:otherwise>
                                     //Unknown style detected !! No code is generated
@@ -563,10 +580,9 @@
                             </xsl:choose>
                         </xsl:otherwise>
                     </xsl:choose>
-        //adding SOAP headers
+        //adding SOAP soap_headers
          _serviceClient.addHeadersToEnvelope(env);
         // create message context with that soap envelope
-        org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext() ;
         _messageContext.setEnvelope(env);
 
         // add the message contxt to the operation client
@@ -658,6 +674,7 @@
 
                 <xsl:for-each select="input/param[@Action!='']">_operationClient.getOptions().setAction("<xsl:value-of select="@Action"/>");</xsl:for-each>
                 org.apache.axiom.soap.SOAPEnvelope env = null;
+                org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext();
 
                 <xsl:variable name="count" select="count(input/param[@type!=''])"/>
                                     <xsl:choose>
@@ -700,12 +717,18 @@
                                                         </xsl:otherwise>
                                                   </xsl:choose>
 
-                                                    <xsl:for-each select="input/param[@location='header']">
+                                                    <xsl:for-each select="input/param[@location='soap_header']">
                                                         // add the children only if the parameter is not null
                                                         if (<xsl:value-of select="@name"/>!=null){
                                                         env.getHeader().addChild(toOM(<xsl:value-of select="@name"/>, optimizeContent(new javax.xml.namespace.QName("<xsl:value-of select="$method-ns"/>", "<xsl:value-of select="$method-name"/>"))));
                                                         }
                                                     </xsl:for-each>
+                                                     <xsl:for-each select="input/param[@location='http_header']">
+                                                        // add the children only if the parameter is not null
+                                                        if (<xsl:value-of select="@name"/>!=null){
+                                                            addHttpHeader(_messageContext,"<xsl:value-of select="@headername"/>",<xsl:value-of select="@name"/>);
+                                                        }
+                                                    </xsl:for-each>
                                                 </xsl:when>
                                                 <xsl:otherwise>
                                                     //Unknown style detected !! No code is generated
@@ -728,10 +751,10 @@
                                         </xsl:otherwise>
                                     </xsl:choose>
 
-              //adding SOAP headers
+              //adding SOAP soap_headers
          _serviceClient.addHeadersToEnvelope(env);
                 // create message context with that soap envelope
-            org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext() ;
+
             _messageContext.setEnvelope(env);
 
             // add the message contxt to the operation client
@@ -795,6 +818,27 @@
             </xsl:if>
           </xsl:if>
         </xsl:for-each>
+
+        /**
+         * private method to add the http soap_headers
+         *
+         * @param messageContext
+         * @param name
+         * @param value
+         */
+        private void addHttpHeader(org.apache.axis2.context.MessageContext messageContext,
+                                   String name,
+                                   String value) {
+            java.lang.Object headersObj = messageContext.getProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS);
+            if (headersObj == null) {
+                headersObj = new java.util.ArrayList();
+            }
+            java.util.List headers = (java.util.List) headersObj;
+            org.apache.commons.httpclient.Header header = new org.apache.commons.httpclient.Header();
+            headers.add(header);
+            messageContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS, headers);
+        }
+
 
        /**
         *  A utility method that copies the namepaces from the SOAPEnvelope



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org