axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r510618 - in /webservices/axis2/trunk/java/modules/kernel: src/org/apache/axis2/addressing/EndpointReference.java test/org/apache/axis2/addressing/EndpointReferenceTypeTest.java
Date Thu, 22 Feb 2007 18:44:27 GMT
Author: nagy
Date: Thu Feb 22 10:44:27 2007
New Revision: 510618

URL: http://svn.apache.org/viewvc?view=rev&rev=510618
Log:
Fixed EndpointReference's so that they serialize/deserialize properly.

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/addressing/EndpointReferenceTypeTest.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java?view=diff&rev=510618&r1=510617&r2=510618
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java
Thu Feb 22 10:44:27 2007
@@ -23,11 +23,18 @@
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axis2.AxisFault;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -552,5 +559,57 @@
         // TODO: check the Map referenceParameters for equivalency
 
         return true;
+    }
+    
+
+    //REVIEW: The following code is rather heavyweight, because we have to build the OM tree
-- it would probably be better to have two serialization/deserialization paths and therefore,
for trivial EPRs, store a smaller amount of info
+    
+    /**
+     * Write the EPR to the specified OutputStream.  Because of potential
+     * OMElements/Attributes, we need to actually serialize the OM structures
+     * (at least in some cases.)
+     */
+    private void writeObject(java.io.ObjectOutputStream out)
+    throws IOException
+    {
+      OMElement om = EndpointReferenceHelper.toOM(OMAbstractFactory.getOMFactory(), this,
new QName("urn:axis2","omepr","ser"), AddressingConstants.Final.WSA_NAMESPACE);
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      
+      try
+      {
+        om.serialize(baos);
+      }
+      catch (javax.xml.stream.XMLStreamException e)
+      {
+        throw (IOException)(new IOException("Unable to serialize the EPR")).initCause(e);
+      }
+      out.writeInt(baos.size());
+      out.write(baos.toByteArray());
+    }
+      
+    /**
+     * Read the EPR to the specified InputStream.
+     */
+    private void readObject(java.io.ObjectInputStream in)
+    throws IOException, ClassNotFoundException
+    {
+      int numBytes = in.readInt();
+      
+      byte[] serBytes = new byte[numBytes];
+      
+      in.read(serBytes, 0, numBytes);
+      ByteArrayInputStream bais = new ByteArrayInputStream(serBytes);
+      try
+      {
+        XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(bais);
+        StAXOMBuilder builder = new StAXOMBuilder(xmlReader);
+        OMElement om = builder.getDocumentElement();
+        
+        EndpointReferenceHelper.fromOM(this, om, AddressingConstants.Final.WSA_NAMESPACE);
+      }
+      catch (javax.xml.stream.XMLStreamException e)
+      {
+        throw (IOException)(new IOException("Unable to deserialize the EPR")).initCause(e);
+      }
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/addressing/EndpointReferenceTypeTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/addressing/EndpointReferenceTypeTest.java?view=diff&rev=510618&r1=510617&r2=510618
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/addressing/EndpointReferenceTypeTest.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/addressing/EndpointReferenceTypeTest.java
Thu Feb 22 10:44:27 2007
@@ -27,6 +27,10 @@
 
 import javax.xml.namespace.QName;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.util.ArrayList;
 import java.util.Map;
 
@@ -98,5 +102,86 @@
         // EndpointReference with 2005/08 None address
         EndpointReference epr200508none = new EndpointReference(AddressingConstants.Final.WSA_NONE_URI);
         assertTrue(epr200508none.hasNoneAddress());
+    }
+    
+    
+    public void testSerializationDeserialization()
+    throws Exception
+    {
+      String address = "http://ws.apache.org/axis2";
+      EndpointReference epr = new EndpointReference(address);
+      
+      OMFactory omf = OMAbstractFactory.getOMFactory();
+      OMNamespace ns1 = omf.createOMNamespace("http://uri1","prefix1");
+      OMAttribute attr1 = omf.createOMAttribute("attr1",ns1,"attr1value");
+      OMNamespace ns2 = omf.createOMNamespace("http://uri2","prefix2");
+      OMAttribute attr2 = omf.createOMAttribute("attr2",ns2,"attr2value");
+      epr.addAttribute(attr1);
+      epr.addAttribute(attr2);
+      OMElement md1 = omf.createOMElement("md1", "http://mduri1", "md1prefix");
+      OMElement md2 = omf.createOMElement("md2", "http://mduri2", "md2prefix");
+      epr.addMetaData(md1);
+      epr.addMetaData(md2);
+      OMElement ext1 = omf.createOMElement("ext1", "http://exturi1", "ext1prefix");
+      OMElement ext2 = omf.createOMElement("ext2", "http://exturi2", "ext2prefix");
+      epr.addExtensibleElement(ext1);
+      epr.addExtensibleElement(ext2);
+      QName rp1Qname = new QName("http://rp1uri","refParm1","rp1prefix");
+      QName rp2Qname = new QName("http://rp2uri","refParm2","rp2prefix");
+      epr.addReferenceParameter(rp1Qname,"rp1");
+      epr.addReferenceParameter(rp2Qname,"rp2");
+      
+      ArrayList addressAttributes = new ArrayList();
+      addressAttributes.add(attr1);
+      addressAttributes.add(attr2);
+      epr.setAddressAttributes(addressAttributes);
+      
+      ArrayList metadataAttributes = new ArrayList();
+      metadataAttributes.add(attr1);
+      metadataAttributes.add(attr2);
+      epr.setMetadataAttributes(metadataAttributes);
+      
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      ObjectOutputStream oos = new ObjectOutputStream(baos);
+      oos.writeObject(epr);
+      
+      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+      ObjectInputStream ois = new ObjectInputStream(bais);
+      EndpointReference deserializedEPR = (EndpointReference)ois.readObject();
+      
+      assertEquals(epr.getAddress(),deserializedEPR.getAddress());
+      ArrayList addrAttrs = deserializedEPR.getAddressAttributes();
+      assertAttributesEqual(attr1,(OMAttribute)addrAttrs.get(0));
+      assertAttributesEqual(attr2,(OMAttribute)addrAttrs.get(1));
+      
+      ArrayList attrs = deserializedEPR.getAttributes();
+      assertAttributesEqual(attr1,(OMAttribute)attrs.get(0));
+      assertAttributesEqual(attr2,(OMAttribute)attrs.get(1));
+      
+      ArrayList metadata = deserializedEPR.getMetaData();
+      assertEquals(md1.toString(), metadata.get(0).toString());
+      assertEquals(md2.toString(), metadata.get(1).toString());
+      ArrayList mdAttrs = deserializedEPR.getMetadataAttributes();
+      assertAttributesEqual(attr1,(OMAttribute)mdAttrs.get(0));
+      assertAttributesEqual(attr2,(OMAttribute)mdAttrs.get(1));
+      
+      ArrayList extelts = deserializedEPR.getExtensibleElements();
+      assertEquals(ext1.toString(),extelts.get(0).toString());
+      assertEquals(ext2.toString(),extelts.get(1).toString());
+      
+      Map m = deserializedEPR.getAllReferenceParameters();
+      assertEquals("rp1", ((OMElement)m.get(rp1Qname)).getText());
+      assertEquals("rp2", ((OMElement)m.get(rp2Qname)).getText());
+    }
+    
+    private void assertAttributesEqual(OMAttribute attribute1, OMAttribute attribute2)
+    {
+      if (!attribute1.getAttributeValue().equals(attribute2.getAttributeValue())
+          || (!attribute1.getQName().equals(attribute2.getQName())))
+      {
+        fail("expected:"+attribute1.getQName()+"="
+             +attribute1.getAttributeValue()+" but got "+attribute2.getQName()
+             +"="+attribute2.getAttributeValue());
+      }
     }
 }



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


Mime
View raw message