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 sc...@apache.org on 2006/11/18 23:32:26 UTC

svn commit: r476635 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/marshaller/impl/alt/ src/org/apache/axis2/jaxws/message/databinding/ src/org/apache/axis2/jaxws/message/databinding/impl/ test/org/apache/axis2/jaxws/proxy...

Author: scheu
Date: Sat Nov 18 14:32:25 2006
New Revision: 476635

URL: http://svn.apache.org/viewvc?view=rev&rev=476635
Log:
AXIS2-1730
Contributor:Rich Scheuerle
Enabled another RPC test.  Updated unmarshalling code to unmarshal rpc objects using their declared type.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitBareMethodMarshaller.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/RPCLitMethodMarshaller.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/RPCProxyTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/rpclit/RPCLitImpl.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitBareMethodMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitBareMethodMarshaller.java?view=diff&rev=476635&r1=476634&r2=476635
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitBareMethodMarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitBareMethodMarshaller.java Sat Nov 18 14:32:25 2006
@@ -81,7 +81,7 @@
             Class returnType = MethodMarshallerUtils.getActualReturnType(operationDesc);
             Object returnValue = null;
             if (returnType != void.class) {
-                returnValue = MethodMarshallerUtils.getReturnValue(packages, message);
+                returnValue = MethodMarshallerUtils.getReturnValue(packages, message, null);
             }
             
             // Unmarshall the ParamValues from the Message

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java?view=diff&rev=476635&r1=476634&r2=476635
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java Sat Nov 18 14:32:25 2006
@@ -169,21 +169,23 @@
                 //    continue;
                 //}
                 
-                // Unmarshal the object into a JAXB object or JAXBElement
                 Block block = null;
+                JAXBBlockContext context = new JAXBBlockContext(packages);
+                
+                // RPC is type based, so unfortuately the type of 
+                // object must be provided
+                if (message.getStyle() == Style.RPC) {
+                    context.setRPCType(pd.getParameterActualType());
+                }
+                
+                // Unmarshal the object into a JAXB object or JAXBElement
                 if (pd.isHeader()) {
 
                     // Get the Block from the header
-                    if (message.getStyle() == Style.RPC) {
-                        // TODO add xsi type
-                    }
                     String localName = (usePartName) ? pd.getPartName() : pd.getParameterName();
-                    block = message.getHeaderBlock(pd.getTargetNamespace(), localName, new JAXBBlockContext(packages), factory);
+                    block = message.getHeaderBlock(pd.getTargetNamespace(), localName, context, factory);
                 } else {
-                    if (message.getStyle() == Style.RPC) {
-                        // TODO add xsi type
-                    }
-                    block = message.getBodyBlock(index, new JAXBBlockContext(packages), factory);
+                    block = message.getBodyBlock(index, context, factory);
                 }
                 
                 // The object is now ready for marshalling
@@ -353,19 +355,21 @@
      * Unmarshal the return object from the message
      * @param packages
      * @param message
+     * @param rpcType RPC Declared Type class (only used for RPC processing
      * @return type enabled object
      * @throws MessageException
      * @throws XMLStreamException
      */
-    static Object getReturnValue(Set<Package> packages, Message message) 
+    static Object getReturnValue(Set<Package> packages, Message message, Class rpcType) 
         throws MessageException, XMLStreamException {
         
         
         // The return object is the first block in the body
-        if (message.getStyle() == Style.RPC) {
-            // TODO add xsi type
+        JAXBBlockContext context = new JAXBBlockContext(packages);
+        if (rpcType != null) {
+            context.setRPCType(rpcType);  // RPC is type-based, so the unmarshalled type must be provided
         }
-        Block block = message.getBodyBlock(0, new JAXBBlockContext(packages), factory);
+        Block block = message.getBodyBlock(0, context, factory);
         
         // Get the business object.  We want to return the object that represents the type.
         Object returnValue = block.getBusinessObject(true);
@@ -510,7 +514,27 @@
             JAXBBlockContext blockContext = new JAXBBlockContext(packages);        
             
             if (isRPC) {
-                //TODO add xsi:type
+                // RPC is problem ! We have a chicken and egg problem.
+                // Since RPC is type based, JAXB needs the declared type
+                // to unmarshal the object.  But we don't know the declared
+                // type without knowing the name of the type (sigh)
+                
+                // First get the QName...this might cause a parse
+                QName elementName = detailBlocks[0].getQName();
+                
+                // Now search the FaultDescriptors to find the right 
+                // declared type
+                Class rpcType = null;
+                for(int i=0; i<operationDesc.getFaultDescriptions().length && rpcType == null; i++) {
+                    FaultDescription fd = operationDesc.getFaultDescriptions()[i];
+                    String tryName = fd.getName();
+                    if (elementName.getLocalPart().equals(tryName)) {
+                        rpcType = fd.getClass();
+                    }
+                }
+                // Now set it on the context
+                blockContext.setRPCType(rpcType);
+                
             }
             Block jaxbBlock = factory.createFrom(detailBlocks[0], blockContext);
             Object faultBeanObject = jaxbBlock.getBusinessObject(true); 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/RPCLitMethodMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/RPCLitMethodMarshaller.java?view=diff&rev=476635&r1=476634&r2=476635
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/RPCLitMethodMarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/RPCLitMethodMarshaller.java Sat Nov 18 14:32:25 2006
@@ -262,7 +262,7 @@
             Class returnType = MethodMarshallerUtils.getActualReturnType(operationDesc);
             Object returnValue = null;
             if (returnType != void.class) {
-                returnValue = MethodMarshallerUtils.getReturnValue(packages, message);
+                returnValue = MethodMarshallerUtils.getReturnValue(packages, message, returnType);
             }
             
             // Unmarshall the ParamValues from the Message

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java?view=diff&rev=476635&r1=476634&r2=476635
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java Sat Nov 18 14:32:25 2006
@@ -39,6 +39,15 @@
     
 	private Set<Package> contextPackages;  // List of packages needed by the context
 	private JAXBContext jaxbContext = null;
+    
+    // For RPC processing only
+    // In RPC processing, JAXB needs to unmarshal using the
+    // "declared type unmarshalling" approach because the
+    // element is not known by schema.  If this block will be 
+    // unmarshalled in this fashion, use RPCType to set the 
+    // declared type.  Please do not use this property for 
+    // document style processing.
+    private Class RPCType = null;
 	
 	/**
 	 * Normal Constructor JAXBBlockContext
@@ -51,6 +60,7 @@
     /**
      * Normal Constructor JAXBBlockContext
      * @param contextPackage
+     * @deprecated
      */
     public JAXBBlockContext(Package contextPackage) {
         this.contextPackages = new HashSet();
@@ -92,4 +102,20 @@
         }
 		return jaxbContext;
 	}
+
+    /**
+     * @return RPC Declared Type
+     */
+    public Class getRPCType() {
+        return RPCType;
+    }
+
+    /**
+     * Set RPC Declared Type.  Please do not 
+     * use this property if the message is style=document
+     * @param type
+     */
+    public void setRPCType(Class type) {
+        RPCType = type;
+    }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java?view=diff&rev=476635&r1=476634&r2=476635
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java Sat Nov 18 14:32:25 2006
@@ -107,7 +107,13 @@
             Object jaxb = null;
             
             // Unmarshal into the business object.
-            jaxb = u.unmarshal(reader);
+            if (ctx.getRPCType() == null) {
+                jaxb = u.unmarshal(reader); // preferred and always used for style=document
+            } else {
+                // Unfortunately RPC is type based.  Thus a
+                // declared type must be used to unmarshal the xml.
+                jaxb = u.unmarshal(reader, ctx.getRPCType());
+            }
             
             // Set the qname 
             QName qName = XMLRootElementUtil.getXmlRootElementQName(jaxb);

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/RPCProxyTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/RPCProxyTests.java?view=diff&rev=476635&r1=476634&r2=476635
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/RPCProxyTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/RPCProxyTests.java Sat Nov 18 14:32:25 2006
@@ -111,12 +111,12 @@
         assertTrue(response.contains("PAYLOAD WITH XSI:TYPE"));
     }
     
-    public void _testSimple_DispatchWithoutXSIType() throws Exception {
+    public void testSimple_DispatchWithoutXSIType() throws Exception {
         // Send a payload that simulates
         // the rpc message
         String request = "<tns:testSimple xmlns:tns='http://org/apache/axis2/jaxws/proxy/rpclit'>" +
         "<tns:simpleIn>" +
-        "PAYLOAD WITH XSI:TYPE" +
+        "PAYLOAD WITHOUT XSI:TYPE" +
         "</tns:simpleIn></tns:testSimple>";
         Dispatch<String> dispatch = getDispatch();
         String response = dispatch.invoke(request);
@@ -132,11 +132,11 @@
         assertTrue(!response.contains("Fault"));
         assertTrue(response.contains("simpleOut"));
         assertTrue(response.contains("testSimpleResponse"));
-        assertTrue(response.contains("PAYLOAD WITH XSI:TYPE"));
+        assertTrue(response.contains("PAYLOAD WITHOUT XSI:TYPE"));
     }
     
     /**
-     * Simple test that ensures that we can echo a string to an rpc/lit web service
+     * Simple test that ensures that we can echo a string to an rpc/lit web service.
      */
     public void testStringList() throws Exception {
         try{ 
@@ -154,4 +154,35 @@
             fail("Exception received" + e);
         }
     }
+    
+    // TODO 
+    // Commented out while fixing this test.  The above test succeeds, but sends the message in an incorrect format.
+    // This test sends the message in the correct format, but currently fails.  
+    // We need to investigate the @XmlList processing.
+    //
+    public void _testStringList_Dispatch() throws Exception {
+        // Send a payload that simulates
+        // the rpc message
+        String request = "<tns:testStringList2 xmlns:tns='http://org/apache/axis2/jaxws/proxy/rpclit'>" +
+        //"<tns:arg_2_0 xmlns:tns='http://org/apache/axis2/jaxws/proxy/rpclit' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='tns:StringList' >" +
+        "<tns:arg_2_0>" +
+        "Hello World" +
+        "</tns:arg_2_0></tns:testStringList2>";
+        Dispatch<String> dispatch = getDispatch();
+        String response = dispatch.invoke(request);
+
+        assertNotNull("dispatch invoke returned null", response);
+        System.out.println(response);
+        
+        // Check to make sure the content is correct
+        assertTrue(!response.contains("soap"));
+        assertTrue(!response.contains("Envelope"));
+        assertTrue(!response.contains("Body"));
+        assertTrue(!response.contains("Fault"));
+        assertTrue(response.contains("testStringList2Return"));
+        assertTrue(response.contains("testStringList2Response"));
+        assertTrue(response.contains("Hello World"));
+    }
+    
+    
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/rpclit/RPCLitImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/rpclit/RPCLitImpl.java?view=diff&rev=476635&r1=476634&r2=476635
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/rpclit/RPCLitImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/rpclit/RPCLitImpl.java Sat Nov 18 14:32:25 2006
@@ -66,9 +66,9 @@
 
     public String[] testStringList2(String[] arg20) {
 
-        assert(arg20.length==2);
-        assert(arg20[0].equals("Hello"));
-        assert(arg20[1].equals("World"));
+        assertTrue(arg20.length==2);
+        assertTrue(arg20[0].equals("Hello"));
+        assertTrue(arg20[1].equals("World"));
         return arg20;
     }
 
@@ -78,18 +78,18 @@
     }
 
     public Long[] testLongList4(Long[] longs) {
-        assert(longs.length==3);
-        assert(longs[0] == 0);
-        assert(longs[1] == 1);
-        assert(longs[2] == 2);
+        assertTrue(longs.length==3);
+        assertTrue(longs[0] == 0);
+        assertTrue(longs[1] == 1);
+        assertTrue(longs[2] == 2);
         return longs;
     }
 
     public Enum[] testEnumList5(Enum[] enums) {
-        assert(enums.length==3);
-        assert(enums[0] == Enum.ONE);
-        assert(enums[1] == Enum.TWO);
-        assert(enums[2] == Enum.THREE);
+        assertTrue(enums.length==3);
+        assertTrue(enums[0] == Enum.ONE);
+        assertTrue(enums[1] == Enum.TWO);
+        assertTrue(enums[2] == Enum.THREE);
         return enums;
     }
 
@@ -103,4 +103,9 @@
         return null;
     }
 
+    private void assertTrue(boolean value) throws RuntimeException {
+        if (!value) {
+            throw new RuntimeException();
+        }
+    }
 }



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