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 ch...@apache.org on 2004/12/23 11:20:02 UTC

svn commit: r123183 - in webservices/axis/trunk/java/dev/scratch/prototype2/src: java/org/apache/axis/impl/llom java/org/apache/axis/impl/llom/builder java/org/apache/axis/impl/llom/traverse test/org/apache/axis/om test/org/apache/axis/om/impl/traverse

Author: chinthaka
Date: Thu Dec 23 02:20:00 2004
New Revision: 123183

URL: http://svn.apache.org/viewcvs?view=rev&rev=123183
Log:
Implemented some TODOs in SOAPHeader and OMElement with tests
Added:
   webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java
   webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/traverse/
   webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/traverse/OMChildrenWithSpecificAttributeIteratorTest.java
Modified:
   webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMAttributeImpl.java
   webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/SOAPHeaderImpl.java
   webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/builder/StAXSOAPModelBuilder.java
   webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/IteratorTester.java
   webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMChildrenQNameIteratorTest.java
   webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMTestCase.java

Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMAttributeImpl.java
Url: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMAttributeImpl.java?view=diff&rev=123183&p1=webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMAttributeImpl.java&r1=123182&p2=webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMAttributeImpl.java&r2=123183
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMAttributeImpl.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/OMAttributeImpl.java	Thu Dec 23 02:20:00 2004
@@ -48,6 +48,7 @@
         return new QName(namespaceName, localName);
     }
 
+    // -------- Getters and Setters
     public String getLocalName() {
         return localName;
     }

Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/SOAPHeaderImpl.java
Url: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/SOAPHeaderImpl.java?view=diff&rev=123183&p1=webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/SOAPHeaderImpl.java&r1=123182&p2=webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/SOAPHeaderImpl.java&r2=123183
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/SOAPHeaderImpl.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/SOAPHeaderImpl.java	Thu Dec 23 02:20:00 2004
@@ -1,7 +1,9 @@
 package org.apache.axis.impl.llom;
 
 import org.apache.axis.om.*;
+import org.apache.axis.impl.llom.traverse.OMChildrenWithSpecificAttributeIterator;
 
+import javax.xml.namespace.QName;
 import java.util.Iterator;
 
 /**
@@ -73,8 +75,20 @@
      *         specified actor
      * @see #extractHeaderBlocks(String) extractHeaderBlocks(java.lang.String)
      */
-    public Iterator examineHeaderBlocks(String actor) {
-        throw new UnsupportedOperationException(); //TODO implement this
+    public Iterator examineHeaderBlocks(String paramActor) {
+        Iterator headerBlocksIter = this.getChildren();
+
+        while (headerBlocksIter.hasNext()) {
+            Object o = headerBlocksIter.next();
+            if (o instanceof SOAPHeaderBlock) {
+                SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) o;
+                String actor = soapHeaderBlock.getActor();
+                if(actor != null && actor.equalsIgnoreCase(paramActor)){
+//                    headerBlocksIter.
+                }
+            }
+        }
+        return headerBlocksIter;
     }
 
     /**
@@ -96,7 +110,7 @@
      * @see #examineHeaderBlocks(String) examineHeaderBlocks(java.lang.String)
      */
     public Iterator extractHeaderBlocks(String actor) {
-        throw new UnsupportedOperationException(); //TODO implement this
+        return new OMChildrenWithSpecificAttributeIterator(getFirstChild(), new QName(OMConstants.SOAP_ENVELOPE_NAMESPACE_URI, OMConstants.ATTR_ACTOR), actor, true);
     }
 
     /**
@@ -112,7 +126,8 @@
      *         specified actor and are marked as MustUnderstand
      */
     public Iterator examineMustUnderstandHeaderBlocks(String actor) {
-        throw new UnsupportedOperationException(); //TODO implement this
+        return new OMChildrenWithSpecificAttributeIterator(getFirstChild(), new QName(OMConstants.SOAP_ENVELOPE_NAMESPACE_URI, OMConstants.ATTR_ACTOR), actor, false);
+
     }
 
     /**

Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/builder/StAXSOAPModelBuilder.java
Url: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/builder/StAXSOAPModelBuilder.java?view=diff&rev=123183&p1=webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/builder/StAXSOAPModelBuilder.java&r1=123182&p2=webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/builder/StAXSOAPModelBuilder.java&r2=123183
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/builder/StAXSOAPModelBuilder.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/builder/StAXSOAPModelBuilder.java	Thu Dec 23 02:20:00 2004
@@ -45,7 +45,7 @@
         super(parser);
     }
 
-    public SOAPEnvelope getOMEnvelope() throws OMException {
+    public SOAPEnvelope getSOAPEnvelope() throws OMException {
         while (envelope == null && !done) {
             next();
         }
@@ -181,7 +181,7 @@
     }
 
     public OMElement getDocumentElement() {
-        return getOMEnvelope();
+        return getSOAPEnvelope();
     }
 
     protected void processNamespaceData(OMElement node, boolean isSOAPElement) {

Added: webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java
Url: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java?view=auto&rev=123183
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/java/org/apache/axis/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java	Thu Dec 23 02:20:00 2004
@@ -0,0 +1,73 @@
+package org.apache.axis.impl.llom.traverse;
+
+import org.apache.axis.om.OMAttribute;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMNode;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class OMChildrenWithSpecificAttributeIterator extends OMChildrenIterator {
+    private QName attributeName;
+    private String attributeValue;
+    private boolean detach;
+
+    public OMChildrenWithSpecificAttributeIterator(OMNode currentChild, QName attributeName, String attributeValue, boolean detach) {
+        super(currentChild);
+        this.attributeName = attributeName;
+        this.attributeValue = attributeValue;
+        this.detach = detach;
+    }
+
+    public boolean hasNext() {
+        // First check whether we have a child, using the super class
+        if (currentChild == null)
+            return false;
+        boolean isMatchingNodeFound = false;
+        boolean needToMoveForward = true;
+
+        // now we have a child to check. If its an OMElement and matches the criteria, then we are done
+        while (needToMoveForward) {
+            // check the current node for the criteria
+            if (currentChild instanceof OMElement) {
+                OMAttribute attr = ((OMElement) currentChild).getAttributeWithQName(attributeName);
+                if (attr != null && attr.getValue().equalsIgnoreCase(attributeValue)) {
+                    isMatchingNodeFound = true;
+                    needToMoveForward = false;
+                }else{
+                    currentChild = currentChild.getNextSibling();
+                needToMoveForward = !(currentChild == null);
+                }
+            } else {
+                // get the next named node
+                currentChild = currentChild.getNextSibling();
+                needToMoveForward = !(currentChild == null);
+            }
+
+        }
+        return isMatchingNodeFound;
+    }
+
+    public Object next() {
+        Object o = super.next();
+        if (o != null && detach) {
+            ((OMElement) o).detach();
+        }
+        return o;
+    }
+
+}

Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/IteratorTester.java
Url: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/IteratorTester.java?view=diff&rev=123183&p1=webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/IteratorTester.java&r1=123182&p2=webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/IteratorTester.java&r2=123183
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/IteratorTester.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/IteratorTester.java	Thu Dec 23 02:20:00 2004
@@ -32,7 +32,7 @@
 
     protected void setUp() throws Exception {
         envelope = new StAXSOAPModelBuilder(XMLInputFactory.newInstance().createXMLStreamReader(
-                new FileReader(getTestResourceFile("soap/soapmessage1.xml")))).getOMEnvelope();
+                new FileReader(getTestResourceFile("soap/soapmessage1.xml")))).getSOAPEnvelope();
     }
 
     protected void tearDown() throws Exception {

Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMChildrenQNameIteratorTest.java
Url: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMChildrenQNameIteratorTest.java?view=diff&rev=123183&p1=webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMChildrenQNameIteratorTest.java&r1=123182&p2=webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMChildrenQNameIteratorTest.java&r2=123183
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMChildrenQNameIteratorTest.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMChildrenQNameIteratorTest.java	Thu Dec 23 02:20:00 2004
@@ -36,7 +36,7 @@
     OMChildrenQNameIterator omChildrenQNameIterator;
 
     protected void setUp() throws Exception {
-        envelope = new StAXSOAPModelBuilder(XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(getTestResourceFile("soap/soapmessage1.xml")))).getOMEnvelope();
+        envelope = new StAXSOAPModelBuilder(XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(getTestResourceFile("soap/soapmessage1.xml")))).getSOAPEnvelope();
     }
 
     protected void tearDown() throws Exception {

Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMTestCase.java
Url: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMTestCase.java?view=diff&rev=123183&p1=webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMTestCase.java&r1=123182&p2=webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMTestCase.java&r2=123183
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMTestCase.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/OMTestCase.java	Thu Dec 23 02:20:00 2004
@@ -3,9 +3,11 @@
 import org.apache.axis.AbstractTestCase;
 import org.apache.axis.impl.llom.builder.StAXSOAPModelBuilder;
 
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.*;
 import java.io.FileReader;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
 
 
 /**
@@ -30,7 +32,7 @@
 public abstract class OMTestCase extends AbstractTestCase {
 
     protected static final String IN_FILE_NAME = "soap/soapmessage.xml";
-    protected  OMXMLParserWrapper builder;
+    protected  StAXSOAPModelBuilder builder;
     protected OMFactory ombuilderFactory;
 
     protected SOAPEnvelope soapEnvelope;
@@ -43,13 +45,27 @@
 
     protected void setUp() throws Exception {
         super.setUp();
-        soapEnvelope = (SOAPEnvelope)getOMBuilder().getDocumentElement();
+        soapEnvelope = (SOAPEnvelope)getOMBuilder("").getDocumentElement();
     }
 
-    protected OMXMLParserWrapper getOMBuilder() throws Exception {
-        XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(getTestResourceFile(IN_FILE_NAME)));
+    protected StAXSOAPModelBuilder getOMBuilder(String fileName) throws Exception {
+        if(fileName == "" || fileName == null){
+            fileName = IN_FILE_NAME;
+        }
+        XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(getTestResourceFile(fileName)));
         builder = new StAXSOAPModelBuilder(OMFactory.newInstance(),parser);
         return builder;
+    }
+
+    protected StAXSOAPModelBuilder getOMBuilder(InputStream in) throws Exception {
+
+        XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(in);
+        builder = new StAXSOAPModelBuilder(OMFactory.newInstance(),parser);
+        return builder;
+    }
+
+    protected XMLStreamWriter getStAXStreamWriter(OutputStream out) throws XMLStreamException {
+        return XMLOutputFactory.newInstance().createXMLStreamWriter(out);
     }
 
 

Added: webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/traverse/OMChildrenWithSpecificAttributeIteratorTest.java
Url: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/traverse/OMChildrenWithSpecificAttributeIteratorTest.java?view=auto&rev=123183
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/om/impl/traverse/OMChildrenWithSpecificAttributeIteratorTest.java	Thu Dec 23 02:20:00 2004
@@ -0,0 +1,114 @@
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * <p/>
+ * Author: Eran Chinthaka - Lanka Software Foundation
+ * Date: Dec 23, 2004
+ * Time: 12:22:56 PM
+ */
+package org.apache.axis.om.impl.traverse;
+
+import org.apache.axis.addressing.AddressingConstants;
+import org.apache.axis.impl.llom.traverse.OMChildrenWithSpecificAttributeIterator;
+import org.apache.axis.om.OMConstants;
+import org.apache.axis.om.OMTestCase;
+import org.apache.axis.om.SOAPHeader;
+import org.apache.axis.om.SOAPHeaderBlock;
+
+import javax.xml.namespace.QName;
+import java.io.ByteArrayInputStream;
+import java.util.Iterator;
+
+import sun.text.CompactShortArray;
+
+
+public class OMChildrenWithSpecificAttributeIteratorTest extends OMTestCase implements OMConstants {
+
+    private String sampleSOAPMessage = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\">\n" +
+            "    <soapenv:Header>\n" +
+            "        <wsa:MessageID soapenv:mustUnderstand=\"1\">uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5</wsa:MessageID>\n" +
+            "        <wsa:To soapenv:mustUnderstand=\"0\">http://localhost:8081/axis/services/BankPort</wsa:To>\n" +
+            "        <wsa:From soapenv:mustUnderstand=\"1\">\n" +
+            "            <Address xmlns=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\">http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</Address>\n" +
+            "        </wsa:From>\n" +
+            "    </soapenv:Header>\n" +
+            "    <soapenv:Body>\n" +
+            "        <axis2:echoVoid xmlns:axis2=\"http://ws.apache.org/axis2\" ></axis2:echoVoid>\n" +
+            "    </soapenv:Body>\n" +
+            "</soapenv:Envelope>";
+
+    public OMChildrenWithSpecificAttributeIteratorTest(String testName) {
+        super(testName);
+    }
+
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner
+                .run(OMChildrenWithSpecificAttributeIteratorTest.class);
+    }
+
+    /*
+     * @see TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    public void testChildrenRetrievalWithNoDetach() {
+        try {
+            soapEnvelope = getOMBuilder(new ByteArrayInputStream(sampleSOAPMessage.getBytes())).getSOAPEnvelope();
+            SOAPHeader soapHeader = soapEnvelope.getHeader();
+
+            // getting header blocks with mustUnderstand="0"
+            OMChildrenWithSpecificAttributeIterator iter = new OMChildrenWithSpecificAttributeIterator(soapHeader.getFirstChild(), new QName(SOAP_ENVELOPE_NAMESPACE_URI, ATTR_MUSTUNDERSTAND), "0", false);
+
+            if (iter.hasNext()) {
+                SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) iter.next();
+                assertEquals("Header Block with mustUnderstand=\")0\" has not been retrieved properly", soapHeaderBlock.getLocalName(), AddressingConstants.WSA_TO);
+            }
+
+            if (iter.hasNext()) {
+                fail("Given sample SOAP doesn't have more than one mustunderstand false header blocks");
+            }
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Something has gone wrong in accessing the test xml file");
+        }
+    }
+
+    public void testChildrenRetrievalWithDetach() throws Exception {
+        soapEnvelope = getOMBuilder(new ByteArrayInputStream(sampleSOAPMessage.getBytes())).getSOAPEnvelope();
+        SOAPHeader soapHeader = soapEnvelope.getHeader();
+
+        OMChildrenWithSpecificAttributeIterator iter = new OMChildrenWithSpecificAttributeIterator(soapHeader.getFirstChild(), new QName(SOAP_ENVELOPE_NAMESPACE_URI, ATTR_MUSTUNDERSTAND), "0", true);
+        if (iter.hasNext()) {
+            SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) iter.next();
+            assertEquals("Header Block with mustUnderstand=\")0\" has not been retrieved properly", soapHeaderBlock.getLocalName(), AddressingConstants.WSA_TO);
+        }
+
+        Iterator soapHeaderChildrenIter = soapHeader.getChildren();
+        int childrenCount = 0;
+        while (soapHeaderChildrenIter.hasNext()) {
+            Object o = soapHeaderChildrenIter.next();
+             childrenCount++;
+        }
+
+        assertEquals("OMChildrenWithSpecificAttributeIterator with detach true, not working properly", childrenCount, 6); // here this 6 includes white spaces as OMText
+
+    }
+
+
+}