axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r489554 - in /webservices/axis2/trunk/java/modules: saaj-api/src/javax/xml/soap/ saaj/src/org/apache/axis2/saaj/
Date Fri, 22 Dec 2006 03:43:38 GMT
Author: dims
Date: Thu Dec 21 19:43:37 2006
New Revision: 489554

URL: http://svn.apache.org/viewvc?view=rev&rev=489554
Log:
- Add if/then for using the correct soap version
- Fix SOAPFactory#newInstance to work correctly given a soap version
- Fix bad code in SAAJResult#getResult() [check if it is a SOAPPart before trying to use dom]


Modified:
    webservices/axis2/trunk/java/modules/saaj-api/src/javax/xml/soap/SAAJResult.java
    webservices/axis2/trunk/java/modules/saaj-api/src/javax/xml/soap/SOAPFactory.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFactoryImpl.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderImpl.java

Modified: webservices/axis2/trunk/java/modules/saaj-api/src/javax/xml/soap/SAAJResult.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj-api/src/javax/xml/soap/SAAJResult.java?view=diff&rev=489554&r1=489553&r2=489554
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj-api/src/javax/xml/soap/SAAJResult.java (original)
+++ webservices/axis2/trunk/java/modules/saaj-api/src/javax/xml/soap/SAAJResult.java Thu Dec
21 19:43:37 2006
@@ -18,6 +18,8 @@
 
 import javax.xml.transform.dom.DOMResult;
 
+import org.w3c.dom.*;
+
 public class SAAJResult extends DOMResult {
 
     public SAAJResult()
@@ -39,6 +41,14 @@
     }
 
     public javax.xml.soap.Node getResult() {
-        return (javax.xml.soap.Node) super.getNode().getFirstChild();
+        org.w3c.dom.Node node = super.getNode();
+        if(node instanceof SOAPPart){
+            try {
+                return ((SOAPPart)node).getEnvelope();
+            } catch (SOAPException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return (javax.xml.soap.Node) node.getFirstChild();
     }
 }

Modified: webservices/axis2/trunk/java/modules/saaj-api/src/javax/xml/soap/SOAPFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj-api/src/javax/xml/soap/SOAPFactory.java?view=diff&rev=489554&r1=489553&r2=489554
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj-api/src/javax/xml/soap/SOAPFactory.java (original)
+++ webservices/axis2/trunk/java/modules/saaj-api/src/javax/xml/soap/SOAPFactory.java Thu
Dec 21 19:43:37 2006
@@ -15,6 +15,9 @@
  */
 package javax.xml.soap;
 
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
 /**
  * <code>SOAPFactory</code> is a factory for creating various objects
  * that exist in the SOAP XML tree.
@@ -145,13 +148,20 @@
     }
 
     public static SOAPFactory newInstance(String s) throws SOAPException {
-
-        try {
-            return (SOAPFactory) Class.forName(s).newInstance();
-        } catch (Exception exception) {
-            throw new SOAPException("Unable to create SOAP Factory: "
-                    + exception.getMessage());
+        SOAPFactory factory = newInstance();
+        if (factory.getClass().getName().equals(DEFAULT_SF)) {
+            try {
+                Method m = factory.getClass().getMethod("setSOAPVersion", new Class[]{String.class});
+                m.invoke(factory, new Object[]{s});
+            } catch (IllegalAccessException e) {
+                throw new SOAPException(e);
+            } catch (InvocationTargetException e) {
+                throw new SOAPException(e);
+            } catch (NoSuchMethodException e) {
+                throw new SOAPException(e);
+            }
         }
+        return factory;
     }
 
     public SOAPElement createElement(org.w3c.dom.Element element)

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java?view=diff&rev=489554&r1=489553&r2=489554
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
Thu Dec 21 19:43:37 2006
@@ -16,12 +16,15 @@
 package org.apache.axis2.saaj;
 
 import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.om.impl.dom.DocumentImpl;
 import org.apache.axiom.om.impl.dom.ElementImpl;
 import org.apache.axiom.om.impl.dom.NamespaceImpl;
 import org.apache.axiom.om.impl.dom.NodeImpl;
 import org.apache.axiom.soap.impl.dom.soap11.SOAP11FaultImpl;
+import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
+import org.apache.axiom.soap.impl.dom.soap12.SOAP12FaultImpl;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
@@ -154,7 +157,13 @@
         if (isBodyElementAdded) {
             throw new SOAPException("A SOAPBodyElement has been already added to this SOAPBody");
         }
-        SOAP11FaultImpl fault = new SOAP11FaultImpl(omSOAPBody, (SOAPFactory)this.element.getOMFactory());
+        SOAPFactory omFactory = (SOAPFactory) this.element.getOMFactory();
+        org.apache.axiom.soap.SOAPFault fault;
+        if(omFactory instanceof SOAP11Factory) {
+            fault = new SOAP11FaultImpl(omSOAPBody,  omFactory);
+        } else {
+            fault = new SOAP12FaultImpl(omSOAPBody,  omFactory);
+        }
         SOAPFaultImpl saajSOAPFault = new SOAPFaultImpl(fault);
         ((NodeImpl) omSOAPBody.getFault()).setUserData(SAAJ_NODE, saajSOAPFault, null);
         return saajSOAPFault;
@@ -413,8 +422,14 @@
                 // silently replace node, as per saaj 1.2 spec
                 if (domNode instanceof ElementImpl) {
                     if (omSOAPBody.hasFault()) {
-                        SOAP11FaultImpl fault = new SOAP11FaultImpl(omSOAPBody,
-                                (SOAPFactory) this.element.getOMFactory());
+
+                        SOAPFactory omFactory = (SOAPFactory) this.element.getOMFactory();
+                        org.apache.axiom.soap.SOAPFault fault;
+                        if(omFactory instanceof SOAP11Factory) {
+                            fault = new SOAP11FaultImpl(omSOAPBody,  omFactory);
+                        } else {
+                            fault = new SOAP12FaultImpl(omSOAPBody,  omFactory);
+                        }
                         SOAPFaultImpl saajSOAPFault = new SOAPFaultImpl(fault);
                         ((NodeImpl) omSOAPBody.getFault()).setUserData(SAAJ_NODE, saajSOAPFault,
null);
                         childElements.add(saajSOAPFault);

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java?view=diff&rev=489554&r1=489553&r2=489554
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java
Thu Dec 21 19:43:37 2006
@@ -21,6 +21,8 @@
 import org.apache.axiom.om.impl.dom.TextImpl;
 import org.apache.axiom.soap.impl.dom.soap11.SOAP11BodyImpl;
 import org.apache.axiom.soap.impl.dom.soap11.SOAP11HeaderImpl;
+import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
+import org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderImpl;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
@@ -154,10 +156,18 @@
     public SOAPHeader addHeader() throws SOAPException {
         org.apache.axiom.soap.SOAPHeader header = omSOAPEnvelope.getHeader();
         if (header == null) {
-            header = new SOAP11HeaderImpl(omSOAPEnvelope,
-                    (SOAPFactory) this.element.getOMFactory());
-            SOAPHeaderImpl saajSOAPHeader = new SOAPHeaderImpl(header);
-            saajSOAPHeader.setParentElement(this);
+            SOAPHeaderImpl saajSOAPHeader;
+            if(this.element.getOMFactory() instanceof SOAP11Factory) {
+                header = new SOAP11HeaderImpl(omSOAPEnvelope,
+                        (SOAPFactory) this.element.getOMFactory());
+                saajSOAPHeader = new SOAPHeaderImpl(header);
+                saajSOAPHeader.setParentElement(this);
+            } else {
+                header = new SOAP12HeaderImpl(omSOAPEnvelope,
+                        (SOAPFactory) this.element.getOMFactory());
+                saajSOAPHeader = new SOAPHeaderImpl(header);
+                saajSOAPHeader.setParentElement(this);
+            }
             ((NodeImpl) omSOAPEnvelope.getHeader()).setUserData(SAAJ_NODE, saajSOAPHeader,
null);
             return saajSOAPHeader;
         } else {

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFactoryImpl.java?view=diff&rev=489554&r1=489553&r2=489554
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFactoryImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFactoryImpl.java
Thu Dec 21 19:43:37 2006
@@ -27,6 +27,7 @@
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPFactory;
 import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPConstants;
 import javax.xml.namespace.QName;
 
 /**
@@ -34,6 +35,8 @@
  */
 public class SOAPFactoryImpl extends SOAPFactory {
 
+    protected String soapVersion = SOAPConstants.SOAP_1_1_PROTOCOL;
+
     /**
      * Create a <code>SOAPElement</code> object initialized with the
      * given <code>Name</code> object.
@@ -49,7 +52,13 @@
         String localName = name.getLocalName();
         String prefix = name.getPrefix();
         String uri = name.getURI();
-        OMElement omElement = DOOMAbstractFactory.getOMFactory().createOMElement(localName,
uri, prefix);
+        OMElement omElement = null;
+        if (soapVersion.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) {
+            omElement = DOOMAbstractFactory.getSOAP12Factory().createOMElement(localName,
uri, prefix);
+        } else {
+            omElement = DOOMAbstractFactory.getSOAP11Factory().createOMElement(localName,
uri, prefix);
+        }
+        DOOMAbstractFactory.getOMFactory().createOMElement(localName, uri, prefix);
         return new SOAPElementImpl((ElementImpl) omElement);
     }
 
@@ -65,8 +74,12 @@
      *                                      <code>SOAPElement</code> object
      */
     public SOAPElement createElement(String localName) throws SOAPException {
-        OMDOMFactory omdomFactory = (OMDOMFactory) DOOMAbstractFactory.getOMFactory();
-
+        OMDOMFactory omdomFactory = null;
+        if (soapVersion.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) {
+            omdomFactory = (OMDOMFactory) DOOMAbstractFactory.getSOAP12Factory();
+        } else {
+            omdomFactory = (OMDOMFactory) DOOMAbstractFactory.getSOAP11Factory();
+        }
         OMNamespace ns = omdomFactory.createOMNamespace(null, null);
         OMElement omElement = omdomFactory.createOMElement(localName, ns);
         return new SOAPElementImpl((ElementImpl) omElement);
@@ -87,7 +100,12 @@
      *                                      <code>SOAPElement</code> object
      */
     public SOAPElement createElement(String localName, String prefix, String uri) throws
SOAPException {
-        OMElement omElement = DOOMAbstractFactory.getOMFactory().createOMElement(localName,
uri, prefix);
+        OMElement omElement = null;
+        if (soapVersion.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) {
+            omElement = DOOMAbstractFactory.getSOAP12Factory().createOMElement(localName,
uri, prefix);
+        } else {
+            omElement = DOOMAbstractFactory.getSOAP11Factory().createOMElement(localName,
uri, prefix);
+        }
         return new SOAPElementImpl((ElementImpl) omElement);
     }
 
@@ -103,7 +121,11 @@
      * @throws javax.xml.soap.SOAPException if there is a SOAP error
      */
     public Detail createDetail() throws SOAPException { 
-        return new DetailImpl(DOOMAbstractFactory.getSOAP11Factory().createSOAPFaultDetail());
+        if (soapVersion.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) {
+            return new DetailImpl(DOOMAbstractFactory.getSOAP12Factory().createSOAPFaultDetail());
+        } else {
+            return new DetailImpl(DOOMAbstractFactory.getSOAP11Factory().createSOAPFaultDetail());
+        }
     }
 
     /**
@@ -148,5 +170,9 @@
 
     public SOAPFault createFault(String s, QName qname) throws SOAPException {
         return null;  //TODO - Not yet implemented
+    }
+
+    public void setSOAPVersion(String soapVersion){
+        this.soapVersion = soapVersion;
     }
 }

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java?view=diff&rev=489554&r1=489553&r2=489554
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java
Thu Dec 21 19:43:37 2006
@@ -22,6 +22,7 @@
 import org.apache.axiom.soap.SOAPFaultRole;
 import org.apache.axiom.soap.SOAPFaultText;
 import org.apache.axiom.soap.SOAPFaultValue;
+import org.apache.axiom.soap.SOAPFaultDetail;
 import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
 import org.apache.axiom.om.impl.dom.ElementImpl;
 import org.apache.axiom.om.impl.dom.NodeImpl;
@@ -29,6 +30,8 @@
 import org.apache.axiom.soap.impl.dom.soap11.SOAP11FaultReasonImpl;
 import org.apache.axiom.soap.impl.dom.soap11.SOAP11FaultRoleImpl;
 import org.apache.axiom.soap.impl.dom.soap11.SOAP11FaultTextImpl;
+import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
+import org.apache.axiom.soap.impl.dom.soap12.SOAP12FaultDetailImpl;
 
 import javax.xml.namespace.QName;
 import javax.xml.soap.Detail;
@@ -186,8 +189,15 @@
                                     "Please remove the existing Detail element before " +
                                     "calling addDetail()");
         }
-        SOAP11FaultDetailImpl omDetail = new SOAP11FaultDetailImpl(this.fault,
-                (SOAPFactory) this.element.getOMFactory());
+        SOAPFaultDetail omDetail;
+        SOAPFactory factory = (SOAPFactory) this.element.getOMFactory();
+        if (factory instanceof SOAP11Factory) {
+            omDetail = new SOAP11FaultDetailImpl(this.fault,
+                    factory);
+        } else {
+            omDetail = new SOAP12FaultDetailImpl(this.fault,
+                    factory);
+        }
         Detail saajDetail = new DetailImpl(omDetail);
         ((NodeImpl) fault.getDetail()).setUserData(SAAJ_NODE, saajDetail, null);
         isDetailAdded = true;

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderImpl.java?view=diff&rev=489554&r1=489553&r2=489554
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderImpl.java
Thu Dec 21 19:43:37 2006
@@ -15,14 +15,9 @@
  */
 package org.apache.axis2.saaj;
 
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.soap.SOAPHeaderBlock;
-import org.apache.axiom.om.impl.dom.ElementImpl;
-import org.apache.axiom.om.impl.dom.NamespaceImpl;
-import org.apache.axiom.om.impl.dom.NodeImpl;
-import org.apache.axiom.soap.impl.dom.soap11.SOAP11HeaderBlockImpl;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 
 import javax.xml.namespace.QName;
 import javax.xml.soap.Name;
@@ -31,9 +26,17 @@
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPHeaderElement;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
+
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.impl.dom.ElementImpl;
+import org.apache.axiom.om.impl.dom.NamespaceImpl;
+import org.apache.axiom.om.impl.dom.NodeImpl;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
+import org.apache.axiom.soap.impl.dom.soap11.SOAP11HeaderBlockImpl;
+import org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl;
 
 public class SOAPHeaderImpl extends SOAPElementImpl implements SOAPHeader {
 
@@ -73,8 +76,14 @@
     */
     public SOAPElement addChildElement(String localName, String prefix, String uri) throws
SOAPException {
         OMNamespace ns = new NamespaceImpl(uri, prefix);
-        SOAPHeaderBlock headerBlock =
-                new SOAP11HeaderBlockImpl(localName, ns, omSOAPHeader, (SOAPFactory)this.element.getOMFactory());
+        SOAPHeaderBlock headerBlock = null;
+        if (this.element.getOMFactory() instanceof SOAP11Factory) {
+            headerBlock = new SOAP11HeaderBlockImpl(localName, ns, omSOAPHeader,
+                    (SOAPFactory) this.element.getOMFactory());
+        } else {
+            headerBlock = new SOAP12HeaderBlockImpl(localName, ns, omSOAPHeader,
+                    (SOAPFactory) this.element.getOMFactory());
+        }
         SOAPHeaderElementImpl soapHeaderElement = new SOAPHeaderElementImpl(headerBlock);
         element.setUserData(SAAJ_NODE, this, null);
         soapHeaderElement.element.setUserData(SAAJ_NODE, soapHeaderElement, null);
@@ -95,10 +104,17 @@
     public SOAPElement addChildElement(SOAPElement soapElement) throws SOAPException {
         OMNamespace ns = new NamespaceImpl(soapElement.getNamespaceURI(), 
                 soapElement.getPrefix());
-        SOAPHeaderBlock headerBlock =
-                new SOAP11HeaderBlockImpl(soapElement.getLocalName(), ns, 
-                        omSOAPHeader,
-                        (SOAPFactory)this.element.getOMFactory());
+        SOAPHeaderBlock headerBlock = null;
+        if (this.element.getOMFactory() instanceof SOAP11Factory) {
+            headerBlock = new SOAP11HeaderBlockImpl(soapElement.getLocalName(), ns,
+                    omSOAPHeader,
+                    (SOAPFactory)this.element.getOMFactory());
+        } else {
+            headerBlock = new SOAP12HeaderBlockImpl(soapElement.getLocalName(), ns,
+                    omSOAPHeader,
+                    (SOAPFactory)this.element.getOMFactory());
+
+        }
         SOAPHeaderElementImpl soapHeaderElement = new SOAPHeaderElementImpl(headerBlock);
         element.setUserData(SAAJ_NODE, this, null);
         soapHeaderElement.element.setUserData(SAAJ_NODE, soapHeaderElement, null);
@@ -121,9 +137,14 @@
      */
     public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException {
         OMNamespace ns = new NamespaceImpl(name.getURI(), name.getPrefix());
-        SOAPHeaderBlock headerBlock =
-                new SOAP11HeaderBlockImpl(name.getLocalName(), ns, omSOAPHeader,
-                        (SOAPFactory)this.element.getOMFactory());
+        SOAPHeaderBlock headerBlock = null;
+        if (this.element.getOMFactory() instanceof SOAP11Factory) {
+            headerBlock = new SOAP11HeaderBlockImpl(name.getLocalName(), ns, omSOAPHeader,
+                    (SOAPFactory) this.element.getOMFactory());
+        } else {
+            headerBlock = new SOAP12HeaderBlockImpl(name.getLocalName(), ns, omSOAPHeader,
+                    (SOAPFactory) this.element.getOMFactory());
+        }
         SOAPHeaderElementImpl soapHeaderElement = new SOAPHeaderElementImpl(headerBlock);
         element.setUserData(SAAJ_NODE, this, null);
         soapHeaderElement.element.setUserData(SAAJ_NODE, soapHeaderElement, null);



---------------------------------------------------------------------
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