Author: ajith
Date: Thu Sep  1 00:30:50 2005
New Revision: 265667

URL: http://svn.apache.org/viewcvs?rev=265667&view=rev
Log:
1.Updated the test case to include a new test.
2.Added SOAP 1.2 support for the generated stubs. Earlier there was a bug that 
used a SOAP 1.1 factory even when it should be using the SOAP 1.2 factory.
3.Updated the templates to handle the SOAP faults.

Modified:
    
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
    
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/Stub.java
    
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
    
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
    
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/MessageReceiverTemplate.xsl
    
webservices/axis2/trunk/java/modules/wsdl/test/org/apache/axis2/wsdl/codegen/WSDL2JavaTest.java

Modified: 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java?rev=265667&r1=265666&r2=265667&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
 Thu Sep  1 00:30:50 2005
@@ -33,6 +33,7 @@
 import org.apache.axis2.om.OMException;
 import org.apache.axis2.soap.SOAPEnvelope;
 import org.apache.axis2.soap.SOAPFault;
+import org.apache.axis2.soap.SOAPBody;
 import org.apache.axis2.transport.TransportListener;
 import org.apache.axis2.util.threadpool.AxisWorker;
 import org.apache.wsdl.WSDLConstants;
@@ -282,8 +283,8 @@
                     senderTransport.equals(listenerTransport);
             boolean isATwoWaytransport =
                     Constants.TRANSPORT_HTTP.equals(senderTransport)
-                    || Constants.TRANSPORT_TCP.equals(senderTransport)
-                    || Constants.TRANSPORT_HTTP.equals(senderTransport);
+                            || Constants.TRANSPORT_TCP.equals(senderTransport)
+                            || 
Constants.TRANSPORT_HTTP.equals(senderTransport);
             if ((!isTransportsEqual || !isATwoWaytransport)) {
                 throw new 
AxisFault(Messages.getMessage("useSeparateListenerLimited"));
             }
@@ -291,7 +292,7 @@
             this.useSeparateListener = useSeparateListener;
 
         }
-        
+
         //find and set the transport details
         AxisConfiguration axisConfig =
                 serviceContext.getEngineContext().getAxisConfiguration();
@@ -305,7 +306,7 @@
         if (this.listenerTransport == null) {
             throw new AxisFault(Messages.getMessage("unknownTransport", 
listenerTransport));
         }
-        
+
         //if seperate transport is used, start the required listeners
         if (useSeparateListener) {
             if (!serviceContext
@@ -332,9 +333,9 @@
         if (listenerTransport == null) {
             listenerTransport =
                     serviceContext
-                    .getEngineContext()
-                    .getAxisConfiguration()
-                    .getTransportIn(senderTransport.getName());
+                            .getEngineContext()
+                            .getAxisConfiguration()
+                            .getTransportIn(senderTransport.getName());
         }
 
         if (msgctx.getTransportIn() == null) {
@@ -399,8 +400,20 @@
                         TwoWayTransportBasedSender.send(msgctx, 
listenerTransport);
                 //call the callback                        
                 SOAPEnvelope resenvelope = response.getEnvelope();
-                AsyncResult asyncResult = new AsyncResult(response);
-                callback.onComplete(asyncResult);
+                SOAPBody body = resenvelope.getBody();
+                if (body.hasFault()){
+                    Exception ex = body.getFault().getException();
+                    if (ex !=null){
+                        callback.reportError(ex);
+                    }else{
+                        //todo this needs to be fixed
+                        callback.reportError(new 
Exception(body.getFault().getReason().getText()));
+                    }
+                }else{
+                    AsyncResult asyncResult = new AsyncResult(response);
+                    callback.onComplete(asyncResult);
+                }
+
                 callback.setComplete(true);
             } catch (Exception e) {
                 callback.reportError(e);

Modified: 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/Stub.java
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/Stub.java?rev=265667&r1=265666&r2=265667&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/Stub.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/Stub.java
 Thu Sep  1 00:30:50 2005
@@ -30,10 +30,7 @@
 import org.apache.axis2.om.OMNamespace;

 import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;

 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;

-import org.apache.axis2.soap.SOAPBody;

-import org.apache.axis2.soap.SOAPEnvelope;

-import org.apache.axis2.soap.SOAPFactory;

-import org.apache.axis2.soap.SOAPHeader;

+import org.apache.axis2.soap.*;

 import org.apache.axis2.soap.impl.llom.SOAPProcessingException;

 import org.apache.wsdl.WSDLService;

 

@@ -45,6 +42,10 @@
  */

 public abstract class Stub{

 

+    public static final int SOAP_11 =0;

+    public static final int SOAP_12 =1;

+

+

     protected ConfigurationContext _configurationContext;

     protected static ServiceDescription _service;

     protected ServiceContext _serviceContext;

@@ -55,6 +56,8 @@
     protected String senderTransport = Constants.TRANSPORT_HTTP;

     protected String listenerTransport =Constants.TRANSPORT_HTTP ;

     protected boolean useSeparateListener;

+    //Default SOAP version

+    protected int soapVesrion = SOAP_11;

 

     public void setTransportInfo(String senderTransport,String 
listenerTransport,boolean useSeparateListener)throws AxisFault{

         this.senderTransport = senderTransport;

@@ -80,6 +83,14 @@
 

     }

 

+    /**

+     * Set the soap version

+     * @param soapVersion

+     */

+    public void setSOAPVersion(int soapVersion){

+        this.soapVesrion = soapVersion;

+    }

+

 //     public abstract void _setSessionInfo(Object key, Object value) throws 
Exception;

 //

 //     public abstract Object _getSessionInfo(Object key) throws Exception ;

@@ -126,9 +137,9 @@
         return Long.toString(System.currentTimeMillis());

     }

 

-    //todo make this compliant with the SOAP12

+

     protected SOAPEnvelope createEnvelope() throws SOAPProcessingException {

-        return getFactory().getDefaultEnvelope();

+        return getFactory(this.soapVesrion).getDefaultEnvelope();

     }

 

     protected void setValueRPC(SOAPEnvelope env,

@@ -137,7 +148,7 @@
                                String[] paramNames,

                                Object[] values) {

         SOAPBody body = env.getBody();

-        OMFactory fac = this.getFactory();

+        OMFactory fac = this.getFactory(this.soapVesrion);

 

         OMNamespace methodNamespace = fac.createOMNamespace(methodNamespaceURI,

                 "ns1");

@@ -181,6 +192,34 @@
         }

     }

 

+//    /**

+//     * use this method to handle the faults

+//     * @param env

+//     */

+//    protected void checkFault(SOAPEnvelope env) throws AxisFault{

+//        SOAPBody body = env.getBody();

+//        if (body.hasFault()){

+//           SOAPFault fault = body.getFault();

+//           if (null!=fault.getException()){

+//               throw new AxisFault(fault.getException());

+//           }else{

+//               String message = "";

+//               message = message + "Code =" + fault.getCode()==null?"":

+//                       
fault.getCode().getValue()==null?"":fault.getCode().getValue().getText();

+//               message = message + "Actor = "+fault.getRole()==null?"":

+//                                   fault.getRole().getRoleValue();

+//               //add the details here

+//               throw new AxisFault(message);

+//           }

+//        }

+//    }

+

+    /**

+     * Extract the correct element - A util method

+     * @param env

+     * @param type

+     * @return the relevant element to be databound

+     */

     protected OMElement getElement(SOAPEnvelope env, String type) {

         SOAPBody body = env.getBody();

         OMElement element = body.getFirstElement();

@@ -216,8 +255,14 @@
     }

 

 

-    private SOAPFactory getFactory() {

-        return OMAbstractFactory.getSOAP11Factory();

+    private SOAPFactory getFactory(int soapVersion) {

+        if (soapVersion==SOAP_11){

+            return OMAbstractFactory.getSOAP11Factory();

+        }else if (soapVersion==SOAP_12){

+            return OMAbstractFactory.getSOAP12Factory();

+        }else{

+            throw new RuntimeException("Unknown SOAP version");

+        }

     }

 }

 


Modified: 
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java?rev=265667&r1=265666&r2=265667&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
 Thu Sep  1 00:30:50 2005
@@ -1013,7 +1013,7 @@
             
addHeaderOperations(headerParameterQNameList,bindingOperation,false);

             parameterElementList = 
getParameterElementList(doc,headerParameterQNameList, "header");

             for (int i = 0; i < parameterElementList.size(); i++) {

-                 newChild = (Element) parameterElementList.get(i);

+                newChild = (Element) parameterElementList.get(i);

                 parameterMap.put(newChild.getAttribute("type"),newChild);

             }

         }

@@ -1021,7 +1021,7 @@
         //Now run through the parameters and ad them to the root element

         Collection parameters = parameterMap.values();

         for (Iterator iterator = parameters.iterator(); iterator.hasNext();) {

-           rootElement.appendChild((Element)iterator.next());

+            rootElement.appendChild((Element)iterator.next());

         }

 

         doc.appendChild(rootElement);

@@ -1062,15 +1062,47 @@
                 configuration.getPackageName() +

                         DATABINDING_PACKAGE_NAME_SUFFIX,

                 rootElement);

+        addAttribute(doc,

+                "dbsupportpackage",

+                configuration.getPackageName() +

+                        DATABINDING_PACKAGE_NAME_SUFFIX,

+                rootElement);

+        //add SOAP version

+        addSoapVersion(binding,doc,rootElement);

+        //add the end point

         addEndpoints(doc, rootElement, endpoints);

+        //set the sync/async attributes

         fillSyncAttributes(doc, rootElement);

+        //load the operations

         loadOperations(boundInterface, doc, rootElement, binding);

         doc.appendChild(rootElement);

+       

+        return doc;

 

 

-        return doc;

+    }

 

+    protected void addSoapVersion(WSDLBinding binding,Document doc,Element 
rootElement){

+        //loop through the extensibility elements to get to the bindings 
element

+        List extensibilityElementsList = binding.getExtensibilityElements();

+        int count = extensibilityElementsList.size();

+        for (int i = 0; i < count; i++) {

+            WSDLExtensibilityElement extElement =  
(WSDLExtensibilityElement)extensibilityElementsList.get(i);

+            if 
(ExtensionConstants.SOAP_11_BINDING.equals(extElement.getType())){

+                addAttribute(doc,"soap-version", "1.1",rootElement);

+                break;

+            }else if 
(ExtensionConstants.SOAP_12_BINDING.equals(extElement.getType())){

+                addAttribute(doc,"soap-version", "1.2",rootElement);

+                break;

+            }

+        }

     }

+    /**

+     * Add the endpoint to the document

+     * @param doc

+     * @param rootElement

+     * @param endpointMap

+     */

 

     protected void addEndpoints(Document doc,

                                 Element rootElement,

@@ -1098,6 +1130,13 @@
 

     }

 

+    /**

+     * Utility method to add an attribute to a given element

+     * @param document

+     * @param AttribName

+     * @param attribValue

+     * @param element

+     */

     protected void addAttribute(Document document,

                                 String AttribName,

                                 String attribValue,

@@ -1107,6 +1146,11 @@
         element.setAttributeNode(attribute);

     }

 

+    /**

+     *

+     * @param word

+     * @return character removed string

+     */

     protected String removeUnsuitableCharacters(String word) {

         return word.replaceAll("\\W", "_");

     }


Modified: 
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl?rev=265667&r1=265666&r2=265667&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
 (original)
+++ 
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
 Thu Sep  1 00:30:50 2005
@@ -7,6 +7,7 @@
     <xsl:variable name="isSync"><xsl:value-of select="@isSync"/></xsl:variable>

     <xsl:variable name="isAsync"><xsl:value-of 
select="@isAsync"/></xsl:variable>

     <xsl:variable name="dbpackage"><xsl:value-of 
select="@dbsupportpackage"/></xsl:variable>

+    <xsl:variable name="soapVersion"><xsl:value-of 
select="@soap-version"/></xsl:variable>

     package <xsl:value-of select="$package"/>;

 

     /*

@@ -42,8 +43,15 @@
            _configurationContext = new 
org.apache.axis2.context.ConfigurationContextFactory().buildClientConfigurationContext(axis2Home);

            _configurationContext.getAxisConfiguration().addService(_service);

            _serviceContext = 
_configurationContext.createServiceContext(_service.getName());

+        <!--  Set the soap version depending on the binding. Default is 1.1 so 
don't set anything for that case-->

+        <xsl:if test="$soapVersion='1.2'">

+            //Set the soap version

+            setSOAPVersion(SOAP_12);

+        </xsl:if>

 

-           }

+

+

+        }

 

         /**

         * Default Constructor

@@ -141,8 +149,12 @@
                return;

               </xsl:when>

               <xsl:otherwise>

+             //set the exception throwing status     

+             _call.setExceptionToBeThrownOnSOAPFault(true);

              org.apache.axis2.context.MessageContext  _returnMessageContext = 
_call.invokeBlocking(_operations[<xsl:value-of select="position()-1"/>], 
_messageContext);

              org.apache.axis2.soap.SOAPEnvelope _returnEnv = 
_returnMessageContext.getEnvelope();

+             //check for faults. This might throw an Axis fault

+             //checkFault(_returnEnv);

              java.lang.Object object = <xsl:value-of 
select="$fullsupporterclassname"/>.fromOM(getElement(_returnEnv,"<xsl:value-of 
select="$style"/>"),<xsl:value-of select="$outputtype"/>.class);

              return (<xsl:value-of select="$outputtype"/>)object;

                  </xsl:otherwise>


Modified: 
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/MessageReceiverTemplate.xsl
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/MessageReceiverTemplate.xsl?rev=265667&r1=265666&r2=265667&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/MessageReceiverTemplate.xsl
 (original)
+++ 
webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/MessageReceiverTemplate.xsl
 Thu Sep  1 00:30:50 2005
@@ -96,12 +96,18 @@
                 </xsl:when>

                 <xsl:when test="$style='doc'">

                     //doc style

-                    <xsl:if test="$returntype!=''">

-                        <xsl:value-of select="$returnvariable"/> =</xsl:if> 
skel.<xsl:value-of select="@name"/>(

-                    <xsl:for-each select="input/[EMAIL PROTECTED]'body']">

-                    (<xsl:value-of select="@type"/>)<xsl:value-of 
select="$dbsupportpackage"/>.<xsl:value-of 
select="$dbsupportname"/>.fromOM((org.apache.axis2.om.OMElement)msgContext.getEnvelope().getBody().getFirstElement().detach(),
 <xsl:value-of select="@type"/>.class)

-                     <xsl:if test="position() &gt; 1">,</xsl:if>               
      

-                     </xsl:for-each>);

+                    <xsl:if test="$returntype!=''"><xsl:value-of 
select="$returnvariable"/> =</xsl:if>

+                    <xsl:variable name="paramCount"> <xsl:value-of 
select="count(input/[EMAIL PROTECTED]'body'])"/></xsl:variable>

+                    <xsl:choose>

+                        <xsl:when test="$paramCount &gt; 0"> 
skel.<xsl:value-of select="@name"/>(

+                            <xsl:for-each select="input/[EMAIL 
PROTECTED]'body']">

+                                <xsl:if test="@type!=''">(<xsl:value-of 
select="@type"/>)<xsl:value-of select="$dbsupportpackage"/>.<xsl:value-of 
select="$dbsupportname"/>.fromOM((org.apache.axis2.om.OMElement)msgContext.getEnvelope().getBody().getFirstElement().detach(),
 <xsl:value-of select="@type"/>.class)<xsl:if test="position() &gt; 
1">,</xsl:if></xsl:if>

+                            </xsl:for-each>);

+                        </xsl:when>

+                        <xsl:otherwise>skel.<xsl:value-of 
select="@name"/>();</xsl:otherwise>

+                    </xsl:choose>

+

+

                     //Create a default envelop

                     envelope = getSOAPFactory().getDefaultEnvelope();

                     //Create a Omelement of the result if a result exist


Modified: 
webservices/axis2/trunk/java/modules/wsdl/test/org/apache/axis2/wsdl/codegen/WSDL2JavaTest.java
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/test/org/apache/axis2/wsdl/codegen/WSDL2JavaTest.java?rev=265667&r1=265666&r2=265667&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/wsdl/test/org/apache/axis2/wsdl/codegen/WSDL2JavaTest.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/wsdl/test/org/apache/axis2/wsdl/codegen/WSDL2JavaTest.java
 Thu Sep  1 00:30:50 2005
@@ -47,12 +47,12 @@
      */

     protected void setUp() throws Exception {

         File outputFile = new File(OUTPUT_LOCATION_BASE);

-        if (outputFile.exists() && outputFile.isDirectory()){

-            deleteDir(outputFile);

-            outputFile.mkdir();

-        }else{

-            outputFile.mkdir();

-        }

+//        if (outputFile.exists() && outputFile.isDirectory()){

+//            deleteDir(outputFile);

+//            outputFile.mkdir();

+//        }else{

+//            outputFile.mkdir();

+//        }

     }

 

     /**

@@ -60,10 +60,10 @@
      * @throws Exception

      */

     protected void tearDown() throws Exception {

-        File outputFile = new File(OUTPUT_LOCATION_BASE);

-        if (outputFile.exists() && outputFile.isDirectory()){

-            deleteDir(outputFile);

-        }

+//        File outputFile = new File(OUTPUT_LOCATION_BASE);

+//        if (outputFile.exists() && outputFile.isDirectory()){

+//            deleteDir(outputFile);

+//        }

     }

 

     /**

@@ -150,7 +150,8 @@
     }

 

     /**

-     * Test for the mtom echo wsdl. This wsdl contains a restriction based on 
xmime

+     * Test for the mtom echo wsdl. This wsdl contains a restriction based on 
xmime and a

+     * SOAP 1.2 binding

      *

      */

     public void testCodeGenerationMTOMEcho(){

@@ -173,7 +174,7 @@
         //todo - Still the compilation fails (the original problem of the 
java.home was settled by setting fork

         //todo - to true). Now the compiler fails for some unknown reason 
(inside maven! works fine in the IDE though)

 

-//        compile(outputLocation);

+        //compile(outputLocation);

     }

 

     /**

@@ -198,7 +199,7 @@
         //using the ant javac task for compilation

         Javac javaCompiler = new Javac();

         Project codeGenProject = new Project();

-        Target compileTarget = new Target();

+         Target compileTarget = new Target();

 

         compileTarget.setName(COMPILE_TARGET_NAME);

         compileTarget.addTask(javaCompiler);

@@ -207,6 +208,7 @@
         javaCompiler.setProject(codeGenProject);

         javaCompiler.setIncludejavaruntime(true);

         javaCompiler.setIncludeantruntime(true);

+

         /*

           This harmless looking setFork is actually very important. unless the 
compiler is

           forked it wont work!



Reply via email to