[jbossws-commits] JBossWS SVN: r3980 - in branches/dlofthouse/JBWS-1763/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
Tue Jul 24 13:13:30 EDT 2007


Author: darran.lofthouse at jboss.com
Date: 2007-07-24 13:13:30 -0400 (Tue, 24 Jul 2007)
New Revision: 3980

Modified:
   branches/dlofthouse/JBWS-1763/jbossws-core/src/java/javax/xml/soap/SOAPEnvelope.java
   branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilder.java
   branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
   branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java
   branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java
   branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/MessageFactoryImpl.java
   branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java
   branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPPartImpl.java
Log:
Prototype Code

Modified: branches/dlofthouse/JBWS-1763/jbossws-core/src/java/javax/xml/soap/SOAPEnvelope.java
===================================================================
--- branches/dlofthouse/JBWS-1763/jbossws-core/src/java/javax/xml/soap/SOAPEnvelope.java	2007-07-24 17:02:53 UTC (rev 3979)
+++ branches/dlofthouse/JBWS-1763/jbossws-core/src/java/javax/xml/soap/SOAPEnvelope.java	2007-07-24 17:13:30 UTC (rev 3980)
@@ -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: branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilder.java
===================================================================
--- branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilder.java	2007-07-24 17:02:53 UTC (rev 3979)
+++ branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilder.java	2007-07-24 17:13:30 UTC (rev 3980)
@@ -24,12 +24,13 @@
 // $Id$
 
 import java.io.IOException;
-import java.io.InputStream;
 
 import javax.xml.soap.SOAPEnvelope;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPMessage;
 
+import org.xml.sax.InputSource;
+
 /**
  * @author Heiko Braun, <heiko.braun at jboss.com>
  * @author Thomas.Diesler at jboss.com
@@ -37,5 +38,5 @@
  */
 public interface EnvelopeBuilder
 {
-   SOAPEnvelope build(SOAPMessage soapMessage, InputStream in, boolean ignoreParseError) throws IOException, SOAPException;
+   SOAPEnvelope build(SOAPMessage soapMessage, InputSource is, boolean ignoreParseError) throws IOException, SOAPException;
 }

Modified: branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
===================================================================
--- branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java	2007-07-24 17:02:53 UTC (rev 3979)
+++ branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java	2007-07-24 17:13:30 UTC (rev 3980)
@@ -23,20 +23,28 @@
 
 //$Id$
 
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.dom.DOMSource;
+
 import org.jboss.logging.Logger;
 import org.jboss.ws.WSException;
 import org.jboss.ws.core.jaxrpc.Style;
 import org.jboss.ws.core.utils.DOMUtils;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
 
-import javax.xml.namespace.QName;
-import javax.xml.soap.*;
-import javax.xml.transform.dom.DOMSource;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-
 /**
  * A SOAPEnvelope builder for JAXRPC based on DOM 
  * 
@@ -56,13 +64,13 @@
       this.style = style;
    }
 
-   public SOAPEnvelope build(SOAPMessage soapMessage, InputStream ins, boolean ignoreParseError) throws IOException, SOAPException
+   public SOAPEnvelope build(SOAPMessage soapMessage, InputSource is, boolean ignoreParseError) throws IOException, SOAPException
    {
       // Parse the XML input stream
       Element domEnv = null;
       try
       {
-         domEnv = DOMUtils.parse(ins);
+         domEnv = DOMUtils.parse(is);
       }
       catch (IOException ex)
       {

Modified: branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java
===================================================================
--- branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java	2007-07-24 17:02:53 UTC (rev 3979)
+++ branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java	2007-07-24 17:13:30 UTC (rev 3980)
@@ -24,7 +24,6 @@
 //$Id$
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.Iterator;
 
 import javax.xml.namespace.QName;
@@ -36,8 +35,8 @@
 import javax.xml.transform.dom.DOMSource;
 
 import org.jboss.ws.core.utils.DOMUtils;
-import org.jboss.ws.core.utils.DOMWriter;
 import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
 
 /**
  * A SOAPEnvelope builder for JAXWS in service mode PAYLOAD 
@@ -47,13 +46,13 @@
  */
 public class EnvelopeBuilderPayload implements EnvelopeBuilder
 {
-   public SOAPEnvelope build(SOAPMessage soapMessage, InputStream ins, boolean ignoreParseError) throws IOException, SOAPException
+   public SOAPEnvelope build(SOAPMessage soapMessage, InputSource is, boolean ignoreParseError) throws IOException, SOAPException
    {
       // Parse the XML input stream
       Element domEnv = null;
       try
       {
-         domEnv = DOMUtils.parse(ins);
+         domEnv = DOMUtils.parse(is);
       }
       catch (IOException ex)
       {

Modified: branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java
===================================================================
--- branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java	2007-07-24 17:02:53 UTC (rev 3979)
+++ branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java	2007-07-24 17:13:30 UTC (rev 3980)
@@ -41,6 +41,7 @@
 import javax.xml.transform.stream.StreamSource;
 
 import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
 
 import com.ctc.wstx.stax.WstxInputFactory;
 
@@ -91,11 +92,20 @@
       this.fragmentBuffer.ensureCapacity(2048);
    }
 
-   public SOAPEnvelope build(SOAPMessage soapMessage, InputStream in, boolean ignoreParseError) throws IOException, SOAPException
+   public SOAPEnvelope build(SOAPMessage soapMessage, InputSource is, boolean ignoreParseError) throws IOException, SOAPException
    {
       try
       {
-         reader = getFactoryInstance().createXMLStreamReader(in);
+         XMLInputFactory factory = getFactoryInstance();
+         InputStream ins = is.getByteStream();
+         if (ins != null)
+         {
+            reader = factory.createXMLStreamReader(ins);
+         }
+         else
+         {
+            reader = factory.createXMLStreamReader(is.getCharacterStream());
+         }
       }
       catch (XMLStreamException e)
       {
@@ -237,7 +247,8 @@
    }
 
    // TODO: this is rubbish. Use Source internally instead...
-   private XMLFragment bufferToFragment(StringBuffer fragmentBuffer) {
+   private XMLFragment bufferToFragment(StringBuffer fragmentBuffer)
+   {
       StreamSource source = new StreamSource(new ByteArrayInputStream(fragmentBuffer.toString().getBytes()));
       return new XMLFragment(source);
    }

Modified: branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/MessageFactoryImpl.java
===================================================================
--- branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/MessageFactoryImpl.java	2007-07-24 17:02:53 UTC (rev 3979)
+++ branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/MessageFactoryImpl.java	2007-07-24 17:13:30 UTC (rev 3980)
@@ -27,6 +27,8 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -47,6 +49,7 @@
 import org.jboss.ws.core.soap.attachment.MimeConstants;
 import org.jboss.ws.core.soap.attachment.MultipartRelatedDecoder;
 import org.jboss.ws.core.utils.IOUtils;
+import org.xml.sax.InputSource;
 
 /**
  * MessageFactory implementation
@@ -74,8 +77,7 @@
    {
       if (SOAPConstants.SOAP_1_2_PROTOCOL.equals(protocol))
          envNamespace = SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;
-      else
-         envNamespace = SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE;
+      else envNamespace = SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE;
    }
 
    /**
@@ -188,7 +190,8 @@
       }
 
       ContentType contentType = getContentType(mimeHeaders);
-      if(log.isDebugEnabled()) log.debug("createMessage: [contentType=" + contentType + "]");
+      if (log.isDebugEnabled())
+         log.debug("createMessage: [contentType=" + contentType + "]");
 
       // Debug the incoming message
       if (log.isTraceEnabled())
@@ -249,8 +252,21 @@
          envBuilder = new EnvelopeBuilderDOM(getStyle());
       }
 
+      String charset = contentType.getParameter("charset");
+      Reader reader = null;
+
+      if (charset != null)
+      {
+         reader = new InputStreamReader(ins, charset);
+      }
+      else
+      {
+         reader = new InputStreamReader(ins);
+      }
+      InputSource source = new InputSource(reader);
+
       // Build the payload
-      envBuilder.build(soapMessage, ins, ignoreParseError);
+      envBuilder.build(soapMessage, source, ignoreParseError);
 
       return soapMessage;
    }

Modified: branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java
===================================================================
--- branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java	2007-07-24 17:02:53 UTC (rev 3979)
+++ branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java	2007-07-24 17:13:30 UTC (rev 3980)
@@ -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: branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPPartImpl.java
===================================================================
--- branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPPartImpl.java	2007-07-24 17:02:53 UTC (rev 3979)
+++ branches/dlofthouse/JBWS-1763/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPPartImpl.java	2007-07-24 17:13:30 UTC (rev 3980)
@@ -1,24 +1,24 @@
 /*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jboss.ws.core.soap;
 
 // $Id$
@@ -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;
@@ -58,6 +53,7 @@
 import org.w3c.dom.ProcessingInstruction;
 import org.w3c.dom.Text;
 import org.w3c.dom.UserDataHandler;
+import org.xml.sax.InputSource;
 
 /** An implementation of SOAPPart.
  * 
@@ -83,7 +79,7 @@
    {
       return soapMessage;
    }
-   
+
    public SOAPEnvelope getEnvelope() throws SOAPException
    {
       return soapEnvelope;
@@ -148,11 +144,17 @@
       // Specifically, the HTTP response entity-body must be empty.
       if (source == null)
       {
-         if(log.isDebugEnabled()) log.debug("Setting content source to null removes the SOAPEnvelope");
+         if (log.isDebugEnabled())
+            log.debug("Setting content source to null removes the SOAPEnvelope");
          soapEnvelope = null;
          return;
       }
 
+      // Start with a fresh soapMessage
+      /*MessageFactory mf = MessageFactory.newInstance();
+       soapMessage = mf.createMessage();
+       soapMessage.getSOAPHeader().detachNode();*/
+
       if (source instanceof DOMSource)
       {
          Element domElement;
@@ -162,9 +164,8 @@
             domElement = ((Document)node).getDocumentElement();
          else if (node instanceof Element)
             domElement = (Element)node;
-         else
-            throw new SOAPException("Unsupported DOMSource node: " + node);
-         
+         else throw new SOAPException("Unsupported DOMSource node: " + node);
+
          EnvelopeBuilderDOM envBuilder = new EnvelopeBuilderDOM(Style.DOCUMENT);
          envBuilder.build(soapMessage, domElement);
       }
@@ -174,7 +175,7 @@
          {
             StreamSource streamSource = (StreamSource)source;
             EnvelopeBuilderDOM envBuilder = new EnvelopeBuilderDOM(Style.DOCUMENT);
-            envBuilder.build(soapMessage, streamSource.getInputStream(), false);
+            envBuilder.build(soapMessage, new InputSource(streamSource.getInputStream()), false);
          }
          catch (IOException e)
          {
@@ -302,7 +303,7 @@
       if (soapEnvelope != null)
       {
          list.add((NodeImpl)soapEnvelope);
-      }      
+      }
       return new NodeListImpl(list);
    }
 




More information about the jbossws-commits mailing list