Author: darran.lofthouse(a)jboss.com
Date: 2007-05-11 10:38:19 -0400 (Fri, 11 May 2007)
New Revision: 3050
Modified:
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/HRefInlineHandler.java
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/MessageFactoryTestCase.java
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPHeaderElementTestCase.java
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPHeaderTestCase.java
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/jaxrpc/jbws1186/JBWS1186TestCase.java
Log:
Initial fix and test case modifications.
Modified:
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/HRefInlineHandler.java
===================================================================
---
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/HRefInlineHandler.java 2007-05-11
14:36:21 UTC (rev 3049)
+++
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/HRefInlineHandler.java 2007-05-11
14:38:19 UTC (rev 3050)
@@ -63,14 +63,28 @@
String bodyStr = DOMWriter.printNode(soapBody, true);
log.debug("Begin processHRefs:\n" + bodyStr);
- SOAPBodyElement bodyElement = (SOAPBodyElement)soapBody.getChildElements().next();
+ SOAPBodyElement bodyElement = null;
+ Iterator children = soapBody.getChildElements();
+ while (bodyElement == null && children.hasNext())
+ {
+ Object currentChild = children.next();
+ if (currentChild instanceof SOAPBodyElement)
+ {
+ bodyElement = (SOAPBodyElement)currentChild;
+ }
+ }
+
processElement(bodyElement);
-
+
Iterator it = soapBody.getChildElements();
while (it.hasNext())
{
+ Object currentChild = it.next();
+ if (currentChild instanceof TextImpl)
+ continue;
+
// Remove id elements
- SOAPElement soapElement = (SOAPElement)it.next();
+ SOAPElement soapElement = (SOAPElement)currentChild;
if ((soapElement instanceof SOAPBodyElement) == false)
soapBody.removeChild(soapElement);
}
Modified:
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java
===================================================================
---
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2007-05-11
14:36:21 UTC (rev 3049)
+++
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2007-05-11
14:38:19 UTC (rev 3050)
@@ -143,7 +143,7 @@
}
public SOAPElement setElementQNameInternal(QName qname) throws SOAPException
- {
+ {
elementName = new NameImpl(qname);
Document owner = domNode.getOwnerDocument();
@@ -153,7 +153,6 @@
return this.completeNamespaceDeclaration();
}
-
/**
* Adds an attribute with the specified name and value to this SOAPElement object.
*
@@ -465,9 +464,7 @@
}
else if (node instanceof Text)
{
- String value = node.getNodeValue();
- if (value.trim().length() > 0)
- list.add(node);
+ list.add(node);
}
}
return list.iterator();
@@ -835,7 +832,14 @@
}
else if (node instanceof TextImpl)
{
+ boolean comment = node.getNodeType() == Node.COMMENT_NODE;
+ if (comment)
+ out.write("<!--");
+
out.write(node.getValue());
+
+ if (comment)
+ out.write("-->");
}
else
{
Modified:
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java
===================================================================
---
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java 2007-05-11
14:36:21 UTC (rev 3049)
+++
branches/dlofthouse/JBWS-1648/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java 2007-05-11
14:38:19 UTC (rev 3050)
@@ -58,7 +58,7 @@
/** Add a SOAPHeaderElement as a child of this SOAPHeader instance.
*/
public SOAPElement addChildElement(SOAPElement child) throws SOAPException
- {
+ {
QName qname = child.getElementQName();
if (qname == null || qname.getNamespaceURI().length() == 0)
throw new SOAPException("Invalid SOAPHeaderElement name: " + qname);
@@ -111,8 +111,12 @@
Iterator it = getChildElements();
while (it.hasNext())
{
- SOAPHeaderElement shElement = (SOAPHeaderElement)it.next();
- list.add(shElement);
+ Object currentChild = it.next();
+ if (currentChild instanceof SOAPHeaderElement)
+ {
+ SOAPHeaderElement shElement = (SOAPHeaderElement)currentChild;
+ list.add(shElement);
+ }
}
return list.iterator();
}
@@ -129,9 +133,13 @@
Iterator it = getChildElements();
while (it.hasNext())
{
- SOAPHeaderElement shElement = (SOAPHeaderElement)it.next();
- if (actor.equals(shElement.getActor()))
- list.add(shElement);
+ Object currentChild = it.next();
+ if (currentChild instanceof SOAPHeaderElement)
+ {
+ SOAPHeaderElement shElement = (SOAPHeaderElement)currentChild;
+ if (actor.equals(shElement.getActor()))
+ list.add(shElement);
+ }
}
return list.iterator();
}
@@ -149,9 +157,13 @@
Iterator it = getChildElements();
while (it.hasNext())
{
- SOAPHeaderElement shElement = (SOAPHeaderElement)it.next();
- if (actor.equals(shElement.getActor()) &&
shElement.getMustUnderstand())
- list.add(shElement);
+ Object currentChild = it.next();
+ if (currentChild instanceof SOAPHeaderElement)
+ {
+ SOAPHeaderElement shElement = (SOAPHeaderElement)currentChild;
+ if (actor.equals(shElement.getActor()) &&
shElement.getMustUnderstand())
+ list.add(shElement);
+ }
}
return list.iterator();
}
@@ -163,9 +175,13 @@
Iterator it = getChildElements();
while (it.hasNext())
{
- SOAPHeaderElement shElement = (SOAPHeaderElement)it.next();
- removeChild(shElement);
- list.add(shElement);
+ Object currentChild = it.next();
+ if (currentChild instanceof SOAPHeaderElement)
+ {
+ SOAPHeaderElement shElement = (SOAPHeaderElement)currentChild;
+ removeChild(shElement);
+ list.add(shElement);
+ }
}
return list.iterator();
}
@@ -180,11 +196,15 @@
Iterator it = getChildElements();
while (it.hasNext())
{
- SOAPHeaderElement shElement = (SOAPHeaderElement)it.next();
- if (actor.equals(shElement.getActor()))
+ Object currentChild = it.next();
+ if (currentChild instanceof SOAPHeaderElement)
{
- removeChild(shElement);
- list.add(shElement);
+ SOAPHeaderElement shElement = (SOAPHeaderElement)currentChild;
+ if (actor.equals(shElement.getActor()))
+ {
+ removeChild(shElement);
+ list.add(shElement);
+ }
}
}
return list.iterator();
Modified:
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/MessageFactoryTestCase.java
===================================================================
---
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/MessageFactoryTestCase.java 2007-05-11
14:36:21 UTC (rev 3049)
+++
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/MessageFactoryTestCase.java 2007-05-11
14:38:19 UTC (rev 3050)
@@ -28,18 +28,19 @@
import java.io.IOException;
import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
-import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import org.jboss.test.ws.JBossWSTest;
import org.jboss.ws.Constants;
import org.jboss.ws.core.jaxrpc.Style;
import org.jboss.ws.core.soap.MessageFactoryImpl;
+import org.jboss.ws.core.soap.NameImpl;
import org.jboss.ws.core.utils.DOMUtils;
import org.jboss.ws.core.utils.DOMWriter;
import org.w3c.dom.Element;
@@ -82,7 +83,9 @@
assertEquals("env:Envelope", env.getNodeName());
assertEquals(Constants.NS_SOAP11_ENV, env.getNamespaceURI());
- SOAPBodyElement soapBodyElement =
(SOAPBodyElement)env.getBody().getChildElements().next();
+ Name name = new NameImpl("businessList", null,
"urn:uddi-org:api_v2");
+ SOAPBodyElement soapBodyElement =
(SOAPBodyElement)env.getBody().getChildElements(name).next();
+
assertEquals("urn:uddi-org:api_v2", soapBodyElement.getNamespaceURI());
}
@@ -225,4 +228,38 @@
//System.out.println(wasXML);
assertEquals(expXML, wasXML);
}
-}
\ No newline at end of file
+
+ public void testWriteToPreserveFormatting() throws Exception
+ {
+ String expMessage =
+ "<soapenv:Envelope
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:typ='http://www.jboss.org/support/phonebook/types'>" +
+ " <soapenv:Header></soapenv:Header>" +
+ " <soapenv:Body>" +
+ " <!-- Comment One -->" +
+ " <typ:lookup
xmlns:typ='http://www.jboss.org/support/phonebook/types'>" +
+ " <!-- Comment Two -->" +
+ " <firstName>Joe</firstName>" +
+ " <surname>Bloggs</surname>" +
+ " <!-- Comment Three -->" +
+ " </typ:lookup>" +
+ " <!-- Comment Four -->" +
+ " </soapenv:Body>" +
+ "</soapenv:Envelope>";
+
+ MessageFactoryImpl factory = new MessageFactoryImpl();
+ ByteArrayInputStream inputStream = new
ByteArrayInputStream(expMessage.getBytes());
+ SOAPMessage soapMsg = factory.createMessage(null, inputStream);
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ soapMsg.writeTo(outputStream);
+
+ String actualMessage = new String(outputStream.toByteArray(), "UTF-8");
+
+ //System.out.println("A - " + expMessage);
+ //System.out.println("B - " +
DOMWriter.printNode(soapMsg.getSOAPPart().getEnvelope(), false));
+ //System.out.println("C - " + actualMessage);
+
+ assertEquals(expMessage, actualMessage);
+ }
+
+}
Modified:
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java
===================================================================
---
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java 2007-05-11
14:36:21 UTC (rev 3049)
+++
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java 2007-05-11
14:38:19 UTC (rev 3050)
@@ -33,6 +33,7 @@
import javax.xml.soap.SOAPMessage;
import org.jboss.test.ws.JBossWSTest;
+import org.jboss.ws.core.soap.NameImpl;
/**
* Test the SOAPElement
@@ -114,8 +115,10 @@
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, new
ByteArrayInputStream(xml.getBytes()));
SOAPFactory soapFactory = SOAPFactory.newInstance();
- SOAPElement bearElement =
(SOAPElement)soapMessage.getSOAPBody().getChildElements().next();
+ Name name = new NameImpl("bear", "np",
"http://northpole.net");
+ SOAPElement bearElement =
(SOAPElement)soapMessage.getSOAPBody().getChildElements(name).next();
+
assertEquals(2, getIteratorCount(bearElement.getAllAttributes()));
Iterator it = bearElement.getAllAttributes();
Modified:
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java
===================================================================
---
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java 2007-05-11
14:36:21 UTC (rev 3049)
+++
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java 2007-05-11
14:38:19 UTC (rev 3050)
@@ -38,6 +38,7 @@
import org.jboss.test.ws.JBossWSTest;
import org.jboss.ws.Constants;
import org.jboss.ws.core.jaxrpc.SOAPFaultHelperJAXRPC;
+import org.jboss.ws.core.soap.NameImpl;
import org.jboss.ws.core.utils.DOMUtils;
/**
@@ -76,7 +77,10 @@
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapMessage = factory.createMessage(null, new
ByteArrayInputStream(envStr.getBytes()));
SOAPBody soapBody = soapMessage.getSOAPBody();
- SOAPFault soapFault = (SOAPFault)soapBody.getChildElements().next();
+
+ Name name = new NameImpl("Fault", "env",
"http://schemas.xmlsoap.org/soap/envelope/");
+ SOAPFault soapFault = (SOAPFault)soapBody.getChildElements(name).next();
+
assertEquals("env:Client", soapFault.getFaultCode());
assertEquals("Some fault message", soapFault.getFaultString());
assertEquals("Some fault actor", soapFault.getFaultActor());
Modified:
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPHeaderElementTestCase.java
===================================================================
---
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPHeaderElementTestCase.java 2007-05-11
14:36:21 UTC (rev 3049)
+++
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPHeaderElementTestCase.java 2007-05-11
14:38:19 UTC (rev 3050)
@@ -61,9 +61,10 @@
SOAPMessage soapMessage = factory.createMessage(null, new
ByteArrayInputStream(envStr.getBytes()));
SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnv.getHeader();
- SOAPHeaderElement shElement =
(SOAPHeaderElement)soapHeader.getChildElements().next();
-
+
Name name = new NameImpl("Bar", "ns2",
"http://org.jboss.ws/header2");
+ SOAPHeaderElement shElement =
(SOAPHeaderElement)soapHeader.getChildElements(name).next();
+
assertEquals(name, shElement.getElementName());
assertEquals("BradPitt", shElement.getActor());
@@ -86,9 +87,10 @@
SOAPMessage soapMessage = factory.createMessage(null, new
ByteArrayInputStream(envStr.getBytes()));
SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnv.getHeader();
- SOAPHeaderElement shElement =
(SOAPHeaderElement)soapHeader.getChildElements().next();
-
+
Name name = new NameImpl("Bar", "ns2",
"http://org.jboss.ws/header2");
+ SOAPHeaderElement shElement =
(SOAPHeaderElement)soapHeader.getChildElements(name).next();
+
assertEquals(name, shElement.getElementName());
assertTrue(shElement.getMustUnderstand());
Modified:
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPHeaderTestCase.java
===================================================================
---
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPHeaderTestCase.java 2007-05-11
14:36:21 UTC (rev 3049)
+++
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPHeaderTestCase.java 2007-05-11
14:38:19 UTC (rev 3050)
@@ -206,7 +206,7 @@
assertEquals("SomeHeaderValue", foo.getValue());
assertEquals("SomeOtherValue", bar.getValue());
- assertFalse(soapHeader.getChildElements().hasNext());
+ assertFalse(soapHeader.examineAllHeaderElements().hasNext());
}
public void testExtractHeaderElements() throws Exception
@@ -234,7 +234,7 @@
assertEquals("SomeOtherValue", bar.getValue());
- Iterator childElements = soapHeader.getChildElements();
+ Iterator childElements = soapHeader.examineAllHeaderElements();
SOAPHeaderElement foo = (SOAPHeaderElement)childElements.next();
Name fooName = new NameImpl("Foo", "ns1",
"http://org.jboss.ws/header");
Modified:
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/jaxrpc/jbws1186/JBWS1186TestCase.java
===================================================================
---
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/jaxrpc/jbws1186/JBWS1186TestCase.java 2007-05-11
14:36:21 UTC (rev 3049)
+++
branches/dlofthouse/JBWS-1648/jbossws-tests/src/java/org/jboss/test/ws/jaxrpc/jbws1186/JBWS1186TestCase.java 2007-05-11
14:38:19 UTC (rev 3050)
@@ -24,10 +24,13 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.net.URL;
+import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.rpc.Service;
import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Name;
+import javax.xml.soap.Node;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
@@ -38,6 +41,7 @@
import org.jboss.test.ws.JBossWSTest;
import org.jboss.test.ws.JBossWSTestSetup;
import org.jboss.ws.core.jaxrpc.client.ServiceFactoryImpl;
+import org.jboss.ws.core.soap.NameImpl;
/**
* The prefix "xsi" for attribute "xsi:nil" is not bound
@@ -102,24 +106,33 @@
public void testMessageAccess() throws Exception
{
MessageFactory factory = MessageFactory.newInstance();
-
+
// The xsi namespace is declared on the envelope
String reqStr =
- "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
- " <env:Body>" +
- " <ns1:echo
xmlns:ns1='http://org.jboss.test.ws/jbws1186'>" +
- " <String_1 xsi:nil='1'/>" +
- " <UserType_2>" +
- " <name xsi:nil='1'/>" +
- " </UserType_2>" +
- " </ns1:echo>" +
- " </env:Body>" +
+ "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
+ " <env:Body>" +
+ " <ns1:echo
xmlns:ns1='http://org.jboss.test.ws/jbws1186'>" +
+ " <String_1 xsi:nil='1'/>" +
+ " <UserType_2>" +
+ " <name xsi:nil='1'/>" +
+ " </UserType_2>" +
+ " </ns1:echo>" +
+ " </env:Body>" +
"</env:Envelope>";
-
+
SOAPMessage reqMessage = factory.createMessage(null, new
ByteArrayInputStream(reqStr.getBytes()));
SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage resMessage = con.call(reqMessage, "http://" + getServerHost()
+ ":8080/jaxrpc-jbws1186");
SOAPElement soapElement =
(SOAPElement)resMessage.getSOAPBody().getChildElements().next();
+ Name headerName = new NameImpl("Bar", "ns2",
"http://org.jboss.ws/header2");
+
+ Iterator it = soapElement.getChildElements();
+ while (it.hasNext())
+ {
+ Object currentNode = (Node)it.next();
+ System.out.println(currentNode.getClass().getName());
+ }
+
soapElement = (SOAPElement)soapElement.getChildElements().next();
assertEquals("1", soapElement.getAttribute("xsi:nil"));
}