Author: heiko.braun(a)jboss.com
Date: 2007-02-07 05:19:29 -0500 (Wed, 07 Feb 2007)
New Revision: 2291
Added:
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/XMLFragmentTestCase.java
Modified:
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/jbossxb/SerializerDeserializerTestCase.java
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/encoded/marshalltest/MarshallTestCase.java
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/jbws1303/ServerHandler.java
Log:
Source and Result are used towards the binding layer. Cleaned up SOAPContentElement
transitions. Introduced a BufferedStreamResult that can be used to represent XML_VALID
state
Modified:
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/jbossxb/SerializerDeserializerTestCase.java
===================================================================
---
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/jbossxb/SerializerDeserializerTestCase.java 2007-02-06
20:20:56 UTC (rev 2290)
+++
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/jbossxb/SerializerDeserializerTestCase.java 2007-02-07
10:19:29 UTC (rev 2291)
@@ -26,9 +26,13 @@
import java.net.URI;
import java.util.Calendar;
import java.util.GregorianCalendar;
+import java.io.ByteArrayInputStream;
import javax.xml.namespace.QName;
import javax.xml.rpc.encoding.TypeMappingRegistry;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
import org.jboss.test.ws.JBossWSTest;
import org.jboss.ws.Constants;
@@ -40,6 +44,7 @@
import org.jboss.ws.core.jaxrpc.binding.SerializationContext;
import org.jboss.ws.core.jaxrpc.binding.SerializerFactoryBase;
import org.jboss.ws.core.jaxrpc.binding.SerializerSupport;
+import org.jboss.ws.core.soap.XMLFragment;
import org.jboss.xb.binding.NamespaceRegistry;
/**
@@ -73,12 +78,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(String.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(String.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- String out = (String)des.deserialize(xmlName, xmlType, xmlFragment, serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ String out = (String)des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(value, out);
}
@@ -90,12 +96,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(Calendar.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(Calendar.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- Calendar out = (Calendar)des.deserialize(xmlName, xmlType, xmlFragment,
serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ Calendar out = (Calendar)des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(value.getTime(), out.getTime());
assertEquals(value.getTimeZone().getRawOffset(),
out.getTimeZone().getRawOffset());
@@ -108,12 +115,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(BigInteger.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(BigInteger.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- BigInteger out = (BigInteger)des.deserialize(xmlName, xmlType, xmlFragment,
serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ BigInteger out = (BigInteger)des.deserialize(xmlName, xmlType, source,
serContext);
assertEquals(value, out);
}
@@ -125,12 +133,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(BigDecimal.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(BigDecimal.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- BigDecimal out = (BigDecimal)des.deserialize(xmlName, xmlType, xmlFragment,
serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ BigDecimal out = (BigDecimal)des.deserialize(xmlName, xmlType, source,
serContext);
assertEquals(value, out);
}
@@ -142,8 +151,8 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(QName.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
// serialization registers the prefix
NamespaceRegistry nsRegistry = serContext.getNamespaceRegistry();
@@ -152,7 +161,8 @@
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(QName.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- QName out = (QName)des.deserialize(xmlName, xmlType, xmlFragment, serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ QName out = (QName)des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(value, out);
}
@@ -164,12 +174,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(URI.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(URI.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- URI out = (URI)des.deserialize(xmlName, xmlType, xmlFragment, serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ URI out = (URI)des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(value, out);
}
@@ -181,12 +192,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(byte[].class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(byte[].class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- byte[] out = (byte[])des.deserialize(xmlName, xmlType, xmlFragment, serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ byte[] out = (byte[])des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(new String(value), new String(out));
}
@@ -198,12 +210,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(byte[].class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(byte[].class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- byte[] out = (byte[])des.deserialize(xmlName, xmlType, xmlFragment, serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ byte[] out = (byte[])des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(new String(value), new String(out));
}
Modified:
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java
===================================================================
---
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java 2007-02-06
20:20:56 UTC (rev 2290)
+++
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java 2007-02-07
10:19:29 UTC (rev 2291)
@@ -35,6 +35,7 @@
import org.jboss.test.ws.JBossWSTest;
import org.jboss.ws.core.soap.NameImpl;
import org.jboss.ws.core.soap.SOAPContentElement;
+import org.jboss.ws.core.soap.XMLFragment;
/**
* Test the SOAPContentElement
@@ -44,25 +45,25 @@
*/
public class SOAPContentElementTestCase extends JBossWSTest
{
-
+
/** Test that we can lazily create the SOAP tree
*/
public void testChildNodeAccess() throws Exception
{
Name name = new NameImpl("Order", "tns",
"http://someURI");
- String xmlFragment =
- "<tns:Order xmlns:tns='http://someURI'>" +
- "<OrderItem>Ferarri</OrderItem>" +
- "<OrderItem>Lamborgini</OrderItem>" +
- "<OrderItem>JBoss Support</OrderItem>" +
- "<Customer>" +
- "<Name>Thomas</Name>" +
- "</Customer>" +
+ String xmlFragment =
+ "<tns:Order xmlns:tns='http://someURI'>" +
+ "<OrderItem>Ferarri</OrderItem>" +
+ "<OrderItem>Lamborgini</OrderItem>" +
+ "<OrderItem>JBoss Support</OrderItem>" +
+ "<Customer>" +
+ "<Name>Thomas</Name>" +
+ "</Customer>" +
"</tns:Order>";
SOAPContentElement soapEl = new SOAPContentElement(name);
- soapEl.setXMLFragment(xmlFragment);
+ soapEl.setXMLFragment( XMLFragment.fromStringFragment(xmlFragment) );
assertEquals(name, soapEl.getElementName());
@@ -94,7 +95,7 @@
String xmlFragment = "<tns:Order xmlns:tns='http://someURI'>No
child element</tns:Order>";
SOAPContentElement soapEl = new SOAPContentElement(name);
- soapEl.setXMLFragment(xmlFragment);
+ soapEl.setXMLFragment( XMLFragment.fromStringFragment(xmlFragment) );
assertEquals(name, soapEl.getElementName());
assertEquals("No child element", soapEl.getValue());
@@ -108,7 +109,7 @@
String xmlFragment = "<tns:Order
xmlns:tns='http://someURI'/>";
SOAPContentElement soapEl = new SOAPContentElement(name);
- soapEl.setXMLFragment(xmlFragment);
+ soapEl.setXMLFragment( XMLFragment.fromStringFragment(xmlFragment) );
assertEquals(name, soapEl.getElementName());
assertFalse(soapEl.hasChildNodes());
@@ -123,7 +124,7 @@
String xmlFragment = "<tns:BadName xmlns:tns='http://someURI'>No
child element</tns:BadName>";
SOAPContentElement soapEl = new SOAPContentElement(name);
- soapEl.setXMLFragment(xmlFragment);
+ soapEl.setXMLFragment( XMLFragment.fromStringFragment(xmlFragment) );
try
{
@@ -146,7 +147,7 @@
SOAPContentElement soapEl = new SOAPContentElement(name);
soapEl.setAttribute("foo", "Kermit");
- soapEl.setXMLFragment(xmlFragment);
+ soapEl.setXMLFragment( XMLFragment.fromStringFragment(xmlFragment) );
assertEquals(name, soapEl.getElementName());
assertEquals("Kermit", soapEl.getAttributeValue(new
NameImpl("foo")));
@@ -163,9 +164,9 @@
"<ns1:hello
xmlns:ns1='http://handlerservice1.org/wsdl'>" +
"<String_1>world</String_1>" +
"</ns1:hello>" +
- "</env:Body>" +
+ "</env:Body>" +
"</env:Envelope>";
-
+
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapMessage = factory.createMessage(null, new
ByteArrayInputStream(envStr.getBytes()));
SOAPBody soapBody = soapMessage.getSOAPBody();
@@ -182,7 +183,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream();
soapMessage.writeTo(baos);
-
+
String expEnv = "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:...
xmlns:ns1='http://handlerservice1.org/wsdl'><String_1>wo... header
was added</String_1></ns1:hello></env:Body></env:Envelope>";
assertEquals(expEnv, baos.toString());
}
Copied:
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/XMLFragmentTestCase.java
(from rev 2290,
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/XMLFragmentTestCase.java)
===================================================================
---
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/XMLFragmentTestCase.java
(rev 0)
+++
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/XMLFragmentTestCase.java 2007-02-07
10:19:29 UTC (rev 2291)
@@ -0,0 +1,62 @@
+/*
+ * 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.test.ws.common.soap;
+
+import junit.framework.TestCase;
+import org.jboss.ws.core.soap.XMLFragment;
+import org.jboss.ws.core.utils.DOMUtils;
+import org.w3c.dom.Element;
+
+import javax.xml.transform.dom.DOMSource;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+
+/**
+ * @author Heiko.Braun(a)jboss.org
+ * @version $Id:$
+ * @since 05.02.2007
+ */
+public class XMLFragmentTestCase extends TestCase {
+
+ public static String XML_STRING =
"<parent><child/></parent>";
+
+ public void testDOMSourceFragment() throws Exception
+ {
+ Element srcElement = DOMUtils.parse(XML_STRING);
+ XMLFragment xmlFragment = new XMLFragment( new DOMSource(srcElement) );
+ testSourceAPI(xmlFragment);
+ }
+
+ private void testSourceAPI(XMLFragment xmlFragment) throws Exception
+ {
+ assertEquals(xmlFragment.toStringFragment(), XML_STRING);
+
+ Element reparsed = xmlFragment.toElement();
+ assertEquals("parent", reparsed.getNodeName());
+ assertEquals("child", reparsed.getFirstChild().getNodeName());
+
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ PrintWriter writer = new PrintWriter( bout);
+ xmlFragment.writeTo(writer);
+ assertEquals(XML_STRING, new String(bout.toByteArray()));
+ }
+}
Modified:
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/encoded/marshalltest/MarshallTestCase.java
===================================================================
---
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/encoded/marshalltest/MarshallTestCase.java 2007-02-06
20:20:56 UTC (rev 2290)
+++
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/encoded/marshalltest/MarshallTestCase.java 2007-02-07
10:19:29 UTC (rev 2291)
@@ -70,7 +70,7 @@
assertEquals(inObj, retObj);
}
- public void testBigDecimalMultiArrayTest() throws Exception
+ public void testBigDecimalMultiArrayTest() throws Exception
{
BigDecimal[] arr1 = new BigDecimal[] { new BigDecimal("100"), new
BigDecimal("200"), new BigDecimal("300") };
BigDecimal[] arr2 = new BigDecimal[] { new BigDecimal("400"), new
BigDecimal("500"), new BigDecimal("600") };
@@ -524,5 +524,5 @@
Short inObj = new Short("1");
Short retObj = port.wrapperShortTest(inObj);
assertEquals(inObj, retObj);
- }
+ }
}
Modified:
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/jbws1303/ServerHandler.java
===================================================================
---
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/jbws1303/ServerHandler.java 2007-02-06
20:20:56 UTC (rev 2290)
+++
branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/jbws1303/ServerHandler.java 2007-02-07
10:19:29 UTC (rev 2291)
@@ -62,7 +62,7 @@
SOAPElement bodyElement =
soapMessage.getSOAPBody().addChildElement("lastmodResponse");
bodyElement.setAttribute("xmlns",
"http://netid.msu.edu:8080/lastmod.pl");
SOAPElement soapElement = bodyElement.addChildElement("TimeChanged");
- soapElement.setAttribute("xsi:type", "xsd:string");
+ soapElement.setAttributeNS("xsi", "type",
"xsd:string");
soapElement.setValue("yesterday");
((SOAPMessageContext)msgContext).setMessage(soapMessage);
}