[jbossws-commits] JBossWS SVN: r2550 - in trunk/jbossws-core/src/java: org/jboss/ws/core/soap and 1 other directory.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Thu Mar 8 10:11:31 EST 2007


Author: heiko.braun at jboss.com
Date: 2007-03-08 10:11:31 -0500 (Thu, 08 Mar 2007)
New Revision: 2550

Modified:
   trunk/jbossws-core/src/java/javax/xml/soap/SOAPEnvelope.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPPartImpl.java
Log:
Fix JBCTS-472

Modified: trunk/jbossws-core/src/java/javax/xml/soap/SOAPEnvelope.java
===================================================================
--- trunk/jbossws-core/src/java/javax/xml/soap/SOAPEnvelope.java	2007-03-08 11:22:03 UTC (rev 2549)
+++ trunk/jbossws-core/src/java/javax/xml/soap/SOAPEnvelope.java	2007-03-08 15:11:31 UTC (rev 2550)
@@ -21,29 +21,55 @@
  */
 package javax.xml.soap;
 
-/** The container for the SOAPHeader and SOAPBody portions of a SOAPPart object. By default, a SOAPMessage object is created with a SOAPPart object that has a SOAPEnvelope object. The SOAPEnvelope object by default has an empty SOAPBody object and an empty SOAPHeader object. The SOAPBody object is required, and the SOAPHeader object, though optional, is used in the majority of cases. If the SOAPHeader object is not needed, it can be deleted, which is shown later. 
- A client can access the SOAPHeader and SOAPBody objects by calling the methods SOAPEnvelope.getHeader and SOAPEnvelope.getBody. The following lines of code use these two methods after starting with the SOAPMessage object message to get the SOAPPart object sp, which is then used to get the SOAPEnvelope object se. 
- SOAPPart sp = message.getSOAPPart();
- SOAPEnvelope se = sp.getEnvelope();
- SOAPHeader sh = se.getHeader();
- SOAPBody sb = se.getBody();
- 
- It is possible to change the body or header of a SOAPEnvelope object by retrieving the current one, deleting it, and then adding a new body or header. The javax.xml.soap.Node method deleteNode deletes the XML element (node) on which it is called. For example, the following line of code deletes the SOAPBody object that is retrieved by the method getBody. 
- se.getBody().detachNode();
- 
- To create a SOAPHeader object to replace the one that was removed, a client uses the method SOAPEnvelope.addHeader, which creates a new header and adds it to the SOAPEnvelope object. Similarly, the method addBody creates a new SOAPBody object and adds it to the SOAPEnvelope object. The following code fragment retrieves the current header, removes it, and adds a new one. Then it retrieves the current body, removes it, and adds a new one. 
- SOAPPart sp = message.getSOAPPart();
- SOAPEnvelope se = sp.getEnvelope();
- se.getHeader().detachNode();
- SOAPHeader sh = se.addHeader();
- se.getBody().detachNode();
- SOAPBody sb = se.addBody();
- 
- It is an error to add a SOAPBody or SOAPHeader object if one already exists. 
- The SOAPEnvelope interface provides three methods for creating Name objects. One method creates Name objects with a local name, a namespace prefix, and a namesapce URI. The second method creates Name objects with a local name and a namespace prefix, and the third creates Name objects with just a local name. The following line of code, in which se is a SOAPEnvelope object, creates a new Name object with all three. 
- Name name = se.createName("GetLastTradePrice", "WOMBAT",
- "http://www.wombat.org/trader");
-
+/** The container for the SOAPHeader and SOAPBody portions of a SOAPPart object.
+ * By default, a SOAPMessage object is created with a SOAPPart object that has a SOAPEnvelope object.
+ * The SOAPEnvelope object by default has an empty SOAPBody object and an empty SOAPHeader object.<p>
+ * The SOAPBody object is required, and the SOAPHeader object, though optional,
+ * is used in the majority of cases. If the SOAPHeader object is not needed, it can be deleted, which is shown later.<p>
+ * A client can access the SOAPHeader and SOAPBody objects by calling the methods SOAPEnvelope.getHeader and SOAPEnvelope.getBody.
+ * The following lines of code use these two methods after starting with the SOAPMessage object message to get the SOAPPart object
+ * sp, which is then used to get the SOAPEnvelope object se.<p>
+ *
+ * <code>
+ * SOAPPart sp = message.getSOAPPart();<br>
+ * SOAPEnvelope se = sp.getEnvelope();<br>
+ * SOAPHeader sh = se.getHeader();<br>
+ * SOAPBody sb = se.getBody(); <br>
+ * </code>
+ * <p>
+ * It is possible to change the body or header of a SOAPEnvelope object by retrieving the current one,
+ * deleting it, and then adding a new body or header.
+ * The javax.xml.soap.Node method deleteNode deletes the XML element (node) on which it is called.
+ * For example, the following line of code deletes the SOAPBody object that is retrieved by the method getBody.
+ * <p>
+ * <code>se.getBody().detachNode();</code>
+ * <p>
+ * To create a SOAPHeader object to replace the one that was removed,
+ * a client uses the method SOAPEnvelope.addHeader, which creates a new header and adds it to the SOAPEnvelope object.
+ * Similarly, the method addBody creates a new SOAPBody object and adds it to the SOAPEnvelope object.
+ * The following code fragment retrieves the current header, removes it, and adds a new one.
+ * Then it retrieves the current body, removes it, and adds a new one.
+ * <p>
+ * <code>
+ * SOAPPart sp = message.getSOAPPart();<br>
+ * SOAPEnvelope se = sp.getEnvelope();<br>
+ * se.getHeader().detachNode(); <br>
+ * SOAPHeader sh = se.addHeader();<br>
+ * se.getBody().detachNode(); <br>
+ * SOAPBody sb = se.addBody();<br>
+ * </code>
+ * <p>
+ * <b>It is an error to add a SOAPBody or SOAPHeader object if one already exists.</b>
+ * The SOAPEnvelope interface provides three methods for creating Name objects.
+ * One method creates Name objects with a local name, a namespace prefix, and a namesapce URI.
+ * The second method creates Name objects with a local name and a namespace prefix,
+ * and the third creates Name objects with just a local name.
+ * <p>
+ * The following line of code, in which se is a SOAPEnvelope object, creates a new Name object with all three.
+ * <code>
+ * Name name = se.createName("GetLastTradePrice", "WOMBAT", "http://www.wombat.org/trader");
+ * </code>
+ *
  * @author Scott.Stark at jboss.org
  * @version $Revision$
  */

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java	2007-03-08 11:22:03 UTC (rev 2549)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java	2007-03-08 15:11:31 UTC (rev 2550)
@@ -71,8 +71,9 @@
       assertEnvelopeNamespace(namespaceURI);
       addNamespaceDeclaration(prefix, namespaceURI);
 
-      addHeader();
-      addBody();
+      // the Element source might already contain a Header and Body declaration
+      if(null == soapPart.getEnvelope().getHeader()) addHeader();
+      if(null == soapPart.getEnvelope().getBody()) addBody();
    }
 
    /** Construct a SOAP envelope for the given SOAP version URI.

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPPartImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPPartImpl.java	2007-03-08 11:22:03 UTC (rev 2549)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPPartImpl.java	2007-03-08 15:11:31 UTC (rev 2550)
@@ -28,12 +28,7 @@
 import java.util.Iterator;
 import java.util.List;
 
-import javax.xml.soap.MimeHeaders;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPMessage;
-import javax.xml.soap.SOAPPart;
+import javax.xml.soap.*;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamSource;
@@ -153,6 +148,11 @@
          return;
       }
 
+      // Start with a fresh soapMessage
+      /*MessageFactory mf = MessageFactory.newInstance();
+      soapMessage = mf.createMessage();
+      soapMessage.getSOAPHeader().detachNode();*/
+
       if (source instanceof DOMSource)
       {
          Element domElement;
@@ -164,7 +164,7 @@
             domElement = (Element)node;
          else
             throw new SOAPException("Unsupported DOMSource node: " + node);
-         
+
          EnvelopeBuilderDOM envBuilder = new EnvelopeBuilderDOM(Style.DOCUMENT);
          envBuilder.build(soapMessage, domElement);
       }




More information about the jbossws-commits mailing list