axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dee...@apache.org
Subject svn commit: r327145 - in /webservices/axis2/trunk/java/modules: codegen/src/org/apache/axis2/util/ integration/test/org/apache/axis2/rpc/
Date Fri, 21 Oct 2005 10:27:47 GMT
Author: deepal
Date: Fri Oct 21 03:27:24 2005
New Revision: 327145

URL: http://svn.apache.org/viewcvs?rev=327145&view=rev
Log:
RPCMessageReceiver completed and that can handle
  1. Nine simple type including date
  2. Any JavaBean
  3. OMElement
  4. Multirfs
  5. If the method return is an Obect array that can also handle

Note that Axis2 does not suppoer multiref serializtion only the deserilization support

Still to be done
 1. Array supprt
 3. Typemapping support (not a big task)


see the test cases for how to use that (RPCCallTest,MultirefTest) , I will drop a mail soon

Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/MultirefHelper.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCServiceClass.java

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java?rev=327145&r1=327144&r2=327145&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/BeanSerializerUtil.java
Fri Oct 21 03:27:24 2005
@@ -238,8 +238,14 @@
 
             if(OMElement.class.isAssignableFrom(classType)){
                 if(hasRef){
-                    throw new AxisFault("The method take OMElenent as argument , and the
body contains" +
-                            "refs , encounter processing error ");
+                    OMElement elemnt = helper.getOMElement(ref);
+                    if(elemnt == null){
+                       retObjs[count] = helper.processOMElementRef(ref);
+                    } else {
+                        retObjs[count] =omElement;
+                    }
+//                    throw new AxisFault("The method take OMElenent as argument , and the
body contains" +
+//                            "refs , encounter processing error ");
                 } else
                     retObjs[count] =omElement;
             } else {

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/MultirefHelper.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/MultirefHelper.java?rev=327145&r1=327144&r2=327145&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/MultirefHelper.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/util/MultirefHelper.java
Fri Oct 21 03:27:24 2005
@@ -2,6 +2,8 @@
 
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMAttribute;
+import org.apache.axis2.om.OMNode;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.rpc.receivers.SimpleTypeMapper;
 
@@ -42,6 +44,7 @@
 
     private HashMap objectmap = new HashMap();
     private HashMap elementMap = new HashMap();
+    private  HashMap omElementMap = new HashMap();
 
     public MultirefHelper(OMElement parent) {
         this.parent = parent;
@@ -49,6 +52,53 @@
 
     public Object getObject(String id){
         return objectmap.get(id);
+    }
+
+    public OMElement getOMElement(String id){
+        return (OMElement)omElementMap.get(id);
+    }
+
+    public OMElement processOMElementRef(String id) throws AxisFault {
+        if(!filledTable){
+            readallChildElements();
+        }
+        OMElement val = (OMElement)elementMap.get(id);
+        if(val == null){
+            throw new AxisFault("Invalid reference :" + id);
+        } else {
+            OMElement ele = processElementforRefs(val);
+            OMElement cloneele = elementClone(ele);
+            omElementMap.put(id,cloneele);
+            return cloneele;
+        }
+    }
+
+    public OMElement processElementforRefs(OMElement elemnts) throws AxisFault {
+        Iterator itr = elemnts.getChildElements();
+        while (itr.hasNext()) {
+            OMElement omElement = (OMElement) itr.next();
+            OMAttribute attri = processRefAtt(omElement);
+            if(attri != null){
+                String ref = getAttvalue(attri);
+                OMElement tempele = getOMElement(ref);
+                if(tempele == null){
+                    tempele = processOMElementRef(ref);
+                }
+                OMElement ele2 = elementClone(tempele);
+                Iterator itrChild = ele2.getChildren();
+                while (itrChild.hasNext()) {
+                    Object obj = itrChild.next();
+                    if(obj instanceof OMNode){
+                      omElement.addChild((OMNode)obj);
+                    }
+                }
+            }
+        }
+        return elemnts;
+    }
+
+    private OMElement elementClone(OMElement ele){
+        return  new StAXOMBuilder(ele.getXMLStreamReader()).getDocumentElement();
     }
 
     public Object processRef(Class javatype, String id) throws AxisFault {

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java?rev=327145&r1=327144&r2=327145&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java
(original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java
Fri Oct 21 03:27:24 2005
@@ -33,6 +33,7 @@
 import javax.xml.stream.FactoryConfigurationError;
 import java.text.SimpleDateFormat;
 import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
 
 import junit.framework.TestCase;
 /*
@@ -177,7 +178,7 @@
         assertEquals(env.getBody().getFirstElement().getFirstElement().getText(), "20");
     }
 
-     public void testaddSameRef() throws AxisFault {
+    public void testaddSameRef() throws AxisFault {
         configureSystem("add");
         OMFactory fac = OMAbstractFactory.getOMFactory();
 
@@ -303,6 +304,108 @@
         MyBean resBean = (MyBean) BeanSerializerUtil.deserialize(MyBean.class, response.getFirstElement());
         assertNotNull(resBean);
         assertEquals(resBean.getAge(), 159);
+        call.close();
+    }
+
+
+    public void testbeanOM() throws AxisFault {
+        configureSystem("beanOM");
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+
+        OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+        OMElement method = fac.createOMElement("beanOM", omNs);
+        OMElement value = fac.createOMElement("arg0", null);
+        value.addAttribute(fac.createOMAttribute("href",null,"#1"));
+        method.addChild(value);
+        OMElement value2 = fac.createOMElement("arg1", null);
+        value2.setText("159");
+        method.addChild(value2);
+
+
+        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
+        SOAPEnvelope envelope = factory.getDefaultEnvelope();
+        envelope.getBody().addChild(method);
+
+
+        String ref1 ="<reference id=\"1\"><name>Deepal</name><value
href=\"#2\"/><address href=\"#3\"/></reference>";
+        OMElement om1 = getOMelemnt(ref1,fac);
+        envelope.getBody().addChild(om1);
+        String ref2 = "<reference id=\"2\">false</reference>";
+        OMElement om2 = getOMelemnt(ref2,fac);
+        envelope.getBody().addChild(om2);
+        String ref3 = "<reference id=\"3\"><town href=\"#4\"/><number>1010</number></reference>";
+        OMElement om3 = getOMelemnt(ref3,fac);
+        envelope.getBody().addChild(om3);
+        String ref4 = "<reference id=\"4\">Colombo3</reference>";
+        OMElement om4 = getOMelemnt(ref4,fac);
+        envelope.getBody().addChild(om4);
+
+        RPCCall call =
+                new RPCCall("target/test-resources/intregrationRepo");
+
+        call.setTo(targetEPR);
+        call.setTransportInfo(Constants.TRANSPORT_HTTP,
+                Constants.TRANSPORT_HTTP,
+                false);
+        SOAPEnvelope env = call.invokeBlocking("beanOM",envelope);
+        OMElement response = env.getBody().getFirstElement();
+        MyBean resBean = (MyBean) BeanSerializerUtil.deserialize(MyBean.class, response.getFirstElement());
+        assertNotNull(resBean);
+        assertEquals(resBean.getAge(), 159);
+        call.close();
+    }
+
+
+    public void testomrefs() throws AxisFault {
+        configureSystem("omrefs");
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+
+        OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+        OMElement method = fac.createOMElement("omrefs", omNs);
+
+        OMElement value = fac.createOMElement("arg0", null);
+        value.addAttribute(fac.createOMAttribute("href",null,"#1"));
+        method.addChild(value);
+
+        OMElement value2 = fac.createOMElement("arg1", null);
+        value2.addAttribute(fac.createOMAttribute("href",null,"#1"));
+        method.addChild(value2);
+
+
+        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
+        SOAPEnvelope envelope = factory.getDefaultEnvelope();
+        envelope.getBody().addChild(method);
+
+
+        String ref1 ="<reference id=\"1\"><name>Deepal</name><value
href=\"#2\"/><address href=\"#3\"/></reference>";
+        OMElement om1 = getOMelemnt(ref1,fac);
+        envelope.getBody().addChild(om1);
+        String ref2 = "<reference id=\"2\">false</reference>";
+        OMElement om2 = getOMelemnt(ref2,fac);
+        envelope.getBody().addChild(om2);
+        String ref3 = "<reference id=\"3\"><town href=\"#4\"/><number>1010</number></reference>";
+        OMElement om3 = getOMelemnt(ref3,fac);
+        envelope.getBody().addChild(om3);
+        String ref4 = "<reference id=\"4\">Colombo3</reference>";
+        OMElement om4 = getOMelemnt(ref4,fac);
+        envelope.getBody().addChild(om4);
+
+        RPCCall call =
+                new RPCCall("target/test-resources/intregrationRepo");
+
+        call.setTo(targetEPR);
+        call.setTransportInfo(Constants.TRANSPORT_HTTP,
+                Constants.TRANSPORT_HTTP,
+                false);
+        SOAPEnvelope env = call.invokeBlocking("omrefs",envelope);
+        OMElement response = env.getBody().getFirstElement();
+
+        ArrayList args = new ArrayList();
+        args.add(boolean.class);
+
+        Object [] resBean = BeanSerializerUtil.deserialize(response,args.toArray());
+        assertNotNull(resBean);
+        assertEquals(((Boolean)resBean[0]).booleanValue(),true);
         call.close();
     }
 

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCServiceClass.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCServiceClass.java?rev=327145&r1=327144&r2=327145&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCServiceClass.java
(original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/RPCServiceClass.java
Fri Oct 21 03:27:24 2005
@@ -6,6 +6,8 @@
 import org.apache.axis2.om.OMFactory;
 import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
 import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.util.BeanSerializerUtil;
+import org.apache.axis2.AxisFault;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
@@ -123,5 +125,21 @@
         bean.setAddress(ab);
         objs.add(bean);
         return objs.toArray();
+    }
+
+    public MyBean beanOM(OMElement element, int val) throws AxisFault {
+        MyBean bean =(MyBean)BeanSerializerUtil.deserialize(MyBean.class,element);
+        bean.setAge(val);
+        return bean;
+    }
+
+    public boolean omrefs(OMElement element, OMElement element2) throws AxisFault {
+        MyBean bean =(MyBean)BeanSerializerUtil.deserialize(MyBean.class,element);
+        MyBean bean2 =(MyBean)BeanSerializerUtil.deserialize(MyBean.class,element2);
+        if(bean2 !=null && bean !=null){
+            return true;
+        } else{
+            return false;
+        }
     }
 }



Mime
View raw message