You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by mm...@apache.org on 2006/09/08 13:31:17 UTC
svn commit: r441477 - in /incubator/cxf/trunk:
api/src/main/java/org/apache/cxf/message/
common/src/main/java/org/apache/cxf/helpers/
rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/
rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/ rt...
Author: mmao
Date: Fri Sep 8 04:31:16 2006
New Revision: 441477
URL: http://svn.apache.org/viewvc?view=rev&rev=441477
Log:
Support XML/HTTP for JAX-WS dispatch/provider
* Move the XMLMesage into the api, consider create the datamodel module to hold the xml datamodel and soap model in rt module later.
* Support DOMSource/StreamSource/SaxSource and MimePartDataSource/MimePartDataSource in XML/HTTP
* Added unit tests for soapmessage/body readers, need to add more unit test.
* Created messages dir in testutils, considering put all the message xml into this dir for share between the tests.
Added:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/XMLMessage.java
- copied, changed from r441330, incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLMessage.java
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java (with props)
incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPBodyDataReaderTest.java (with props)
incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPMessageDataReaderTest.java (with props)
incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/
incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/
incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java (with props)
incubator/cxf/trunk/testutils/src/main/resources/messages/
incubator/cxf/trunk/testutils/src/main/resources/messages/SOAP_GreetMeDocLiteralReq.xml (with props)
incubator/cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq.xml (with props)
Modified:
incubator/cxf/trunk/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/SOAPBodyDataReader.java
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/SOAPMessageDataReader.java
incubator/cxf/trunk/rt/frontend/jaxws/pom.xml
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java
Copied: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/XMLMessage.java (from r441330, incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLMessage.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/XMLMessage.java?view=diff&rev=441477&p1=incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLMessage.java&r1=441330&p2=incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/XMLMessage.java&r2=441477
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLMessage.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/XMLMessage.java Fri Sep 8 04:31:16 2006
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.cxf.binding.xml;
+package org.apache.cxf.message;
import org.apache.cxf.message.AbstractWrappedMessage;
import org.apache.cxf.message.Message;
Modified: incubator/cxf/trunk/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java?view=diff&rev=441477&r1=441476&r2=441477
==============================================================================
--- incubator/cxf/trunk/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java (original)
+++ incubator/cxf/trunk/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java Fri Sep 8 04:31:16 2006
@@ -30,8 +30,10 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
@@ -46,50 +48,47 @@
import org.apache.cxf.common.logging.LogUtils;
-
public final class XMLUtils {
-
+
private static final Logger LOG = LogUtils.getL7dLogger(XMLUtils.class);
private static DocumentBuilderFactory parserFactory;
private static TransformerFactory transformerFactory;
private static String omitXmlDecl = "no";
private static String charset = "utf-8";
private static int indent = -1;
-
+
static {
parserFactory = DocumentBuilderFactory.newInstance();
parserFactory.setNamespaceAware(true);
-
+
transformerFactory = TransformerFactory.newInstance();
}
-
+
private XMLUtils() {
-
+
}
-
- public static Transformer newTransformer() throws TransformerConfigurationException {
+
+ public static Transformer newTransformer() throws TransformerConfigurationException {
return transformerFactory.newTransformer();
}
public static DocumentBuilder getParser() throws ParserConfigurationException {
return parserFactory.newDocumentBuilder();
}
-
- public static Document parse(InputStream in)
- throws ParserConfigurationException, SAXException, IOException {
+
+ public static Document parse(InputStream in) throws ParserConfigurationException, SAXException,
+ IOException {
if (in == null && LOG.isLoggable(Level.FINE)) {
LOG.fine("XMLUtils trying to parse a null inputstream");
}
return getParser().parse(in);
}
- public static Document parse(String in)
- throws ParserConfigurationException, SAXException, IOException {
+ public static Document parse(String in) throws ParserConfigurationException, SAXException, IOException {
return parse(in.getBytes());
}
- public static Document parse(byte[] in)
- throws ParserConfigurationException, SAXException, IOException {
+ public static Document parse(byte[] in) throws ParserConfigurationException, SAXException, IOException {
if (in == null && LOG.isLoggable(Level.FINE)) {
LOG.fine("XMLUtils trying to parse a null bytes");
}
@@ -101,9 +100,9 @@
}
public static void setOmitXmlDecl(String value) {
- omitXmlDecl = value;
+ omitXmlDecl = value;
}
-
+
public static void setCharsetEncoding(String value) {
charset = value;
}
@@ -115,16 +114,15 @@
private static boolean indent() {
return indent != -1;
}
-
+
public static void writeTo(Node node, OutputStream os) {
try {
Transformer it = newTransformer();
-
+
it.setOutputProperty(OutputKeys.METHOD, "xml");
if (indent()) {
it.setOutputProperty(OutputKeys.INDENT, "yes");
- it.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
- Integer.toString(indent));
+ it.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", Integer.toString(indent));
}
it.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omitXmlDecl);
it.setOutputProperty(OutputKeys.ENCODING, charset);
@@ -133,7 +131,25 @@
e.printStackTrace();
}
}
-
+
+ public static String toString(Source source) throws TransformerException, IOException {
+ return toString(source, null);
+ }
+
+ public static String toString(Source source, Properties props) throws TransformerException, IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ StreamResult sr = new StreamResult(bos);
+ Transformer trans = newTransformer();
+ if (props == null) {
+ props = new Properties();
+ props.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ }
+ trans.setOutputProperties(props);
+ trans.transform(source, sr);
+ bos.close();
+ return bos.toString();
+ }
+
public static String toString(Node node) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
writeTo(node, out);
@@ -175,15 +191,15 @@
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Node node = attributes.item(i);
- System.err.println("## prefix=" + node.getPrefix() + " localname:"
- + node.getLocalName() + " value=" + node.getNodeValue());
+ System.err.println("## prefix=" + node.getPrefix() + " localname:" + node.getLocalName()
+ + " value=" + node.getNodeValue());
}
}
public static QName getNamespace(Map<String, String> namespaces, String str, String defaultNamespace) {
String prefix = null;
String localName = null;
-
+
StringTokenizer tokenizer = new StringTokenizer(str, ":");
if (tokenizer.countTokens() == 2) {
prefix = tokenizer.nextToken();
@@ -202,7 +218,7 @@
public static void generateXMLFile(Element element, Writer writer) {
try {
Transformer it = newTransformer();
-
+
it.setOutputProperty(OutputKeys.METHOD, "xml");
it.setOutputProperty(OutputKeys.INDENT, "yes");
it.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
@@ -220,7 +236,7 @@
public static Element createElementNS(Document root, QName name) {
return createElementNS(root, name.getNamespaceURI(), name.getLocalPart());
}
-
+
public static Element createElementNS(Document root, String namespaceURI, String qualifiedName) {
return root.createElementNS(namespaceURI, qualifiedName);
}
@@ -240,7 +256,7 @@
node.removeChild(entry);
}
}
-
+
public static String writeQName(Definition def, QName qname) {
return def.getPrefix(qname.getNamespaceURI()) + ":" + qname.getLocalPart();
}
@@ -250,7 +266,7 @@
DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
if (impl == null) {
System.setProperty(DOMImplementationRegistry.PROPERTY,
- "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
+ "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
registry = DOMImplementationRegistry.newInstance();
impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
}
Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/SOAPBodyDataReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/SOAPBodyDataReader.java?view=diff&rev=441477&r1=441476&r2=441477
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/SOAPBodyDataReader.java (original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/SOAPBodyDataReader.java Fri Sep 8 04:31:16 2006
@@ -66,7 +66,8 @@
} else if (SAXSource.class.isAssignableFrom(type)) {
InputSource inputSource = new InputSource(XMLUtils.getInputStream(doc));
obj = new SAXSource(inputSource);
- } else if (StreamSource.class.isAssignableFrom(type)) {
+ } else if (StreamSource.class.isAssignableFrom(type)
+ || Source.class.isAssignableFrom(type)) {
obj = new StreamSource(XMLUtils.getInputStream(doc));
} else if (Object.class.isAssignableFrom(type)) {
JAXBContext context = factory.getJAXBContext();
Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/SOAPMessageDataReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/SOAPMessageDataReader.java?view=diff&rev=441477&r1=441476&r2=441477
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/SOAPMessageDataReader.java (original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/SOAPMessageDataReader.java Fri Sep 8 04:31:16 2006
@@ -24,6 +24,7 @@
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
@@ -56,15 +57,13 @@
try {
if (DOMSource.class.isAssignableFrom(type)) {
obj = new DOMSource(src.getSOAPPart());
- } else if (SAXSource.class.isAssignableFrom(type)) {
-
+ } else if (SAXSource.class.isAssignableFrom(type)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
src.writeTo(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
InputSource inputSource = new InputSource(bais);
- obj = new SAXSource(inputSource);
-
- } else if (StreamSource.class.isAssignableFrom(type)) {
+ obj = new SAXSource(inputSource);
+ } else if (StreamSource.class.isAssignableFrom(type) || Source.class.isAssignableFrom(type)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
src.writeTo(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
Added: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java?view=auto&rev=441477
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java (added)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java Fri Sep 8 04:31:16 2006
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxb.io;
+
+import java.io.InputStream;
+
+import javax.activation.DataSource;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimePartDataSource;
+import javax.mail.util.ByteArrayDataSource;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+
+import org.w3c.dom.Document;
+
+import org.xml.sax.InputSource;
+
+import org.apache.cxf.databinding.DataReader;
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.jaxb.JAXBDataReaderFactory;
+import org.apache.cxf.message.XMLMessage;
+
+public class XMLMessageDataReader implements DataReader<XMLMessage> {
+ final JAXBDataReaderFactory factory;
+
+ public XMLMessageDataReader(JAXBDataReaderFactory cb) {
+ factory = cb;
+ }
+
+ public Object read(XMLMessage input) {
+ // Complete
+ return null;
+ }
+
+ public Object read(QName name, XMLMessage input) {
+ // Complete
+ return null;
+ }
+
+ public Object read(QName name, XMLMessage input, Class type) {
+ Object obj = null;
+ InputStream is = input.getContent(InputStream.class);
+ if (is == null) {
+ // TODO LOG ERROR here
+ return null;
+ }
+ try {
+ // Processing Souce type
+ if (DOMSource.class.isAssignableFrom(type)) {
+ Document doc = XMLUtils.parse(is);
+ obj = new DOMSource(doc);
+ } else if (SAXSource.class.isAssignableFrom(type)) {
+ obj = new SAXSource(new InputSource(is));
+ } else if (StreamSource.class.isAssignableFrom(type) || Source.class.isAssignableFrom(type)) {
+ obj = new StreamSource(is);
+ }
+
+ // Processing DataSource type
+ if (MimePartDataSource.class.isAssignableFrom(type)) {
+ // Support JavaMail MimePart DataSource type
+ obj = new MimePartDataSource(new MimeBodyPart(is));
+ } else if (ByteArrayDataSource.class.isAssignableFrom(type)
+ || DataSource.class.isAssignableFrom(type)) {
+ // Support JavaMail ByteArrayDataSource
+ obj = new ByteArrayDataSource(is, null);
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return obj;
+ }
+
+}
Propchange: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPBodyDataReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPBodyDataReaderTest.java?view=auto&rev=441477
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPBodyDataReaderTest.java (added)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPBodyDataReaderTest.java Fri Sep 8 04:31:16 2006
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxb.io;
+
+import java.io.InputStream;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.helpers.XMLUtils;
+
+public class SOAPBodyDataReaderTest extends TestCase {
+
+ SOAPBodyDataReader reader;
+ SOAPBody body;
+ String expected = "<ns4:requestType>TestSOAPInputMessage</ns4:requestType>";
+
+ public void setUp() throws Exception {
+ reader = new SOAPBodyDataReader(null);
+ assertNotNull(reader);
+ MessageFactory msgFactory = MessageFactory.newInstance();
+ InputStream is = getTestStream("/messages/SOAP_GreetMeDocLiteralReq.xml");
+ assertNotNull(is);
+ SOAPMessage message = msgFactory.createMessage(new MimeHeaders(),
+ is);
+ assertNotNull(message);
+ body = message.getSOAPBody();
+ assertNotNull(body);
+ }
+
+ public void testReadSource() throws Exception {
+ Object source = reader.read(null, body, Source.class);
+ assertNotNull(source);
+ assertTrue(source instanceof Source);
+ assertSame(XMLUtils.parse(XMLUtils.toString((Source)source)));
+ }
+
+ public void testReadDomSource() throws Exception {
+ Object source = reader.read(null, body, DOMSource.class);
+ assertNotNull(source);
+ assertTrue(source instanceof DOMSource);
+ Node node = ((DOMSource)source).getNode();
+ assertTrue(node instanceof Document);
+ assertSame((Document)node);
+ }
+
+ private void assertSame(Document doc) {
+ Element element = doc.getDocumentElement();
+ assertEquals("ns4:greetMe", element.getNodeName());
+ NodeList list = element.getChildNodes();
+ assertEquals(1, list.getLength());
+ Node node = list.item(0);
+ assertEquals("ns4:requestType", node.getNodeName());
+ assertEquals("TestSOAPInputMessage", node.getTextContent());
+ }
+
+ private InputStream getTestStream(String resource) {
+ return getClass().getResourceAsStream(resource);
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPBodyDataReaderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPBodyDataReaderTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPMessageDataReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPMessageDataReaderTest.java?view=auto&rev=441477
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPMessageDataReaderTest.java (added)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPMessageDataReaderTest.java Fri Sep 8 04:31:16 2006
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxb.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.w3c.dom.Document;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.helpers.XMLUtils;
+
+public class SOAPMessageDataReaderTest extends TestCase {
+
+ SOAPMessageDataReader reader;
+ SOAPMessage message;
+ String expected = "<ns4:requestType>TestSOAPInputMessage</ns4:requestType>";
+
+ public void setUp() throws Exception {
+ reader = new SOAPMessageDataReader(null);
+ assertNotNull(reader);
+ MessageFactory msgFactory = MessageFactory.newInstance();
+ InputStream is = getTestStream("/messages/SOAP_GreetMeDocLiteralReq.xml");
+ assertNotNull(is);
+ message = msgFactory.createMessage(new MimeHeaders(),
+ is);
+ assertNotNull(message);
+ }
+
+ public void tearDown() throws IOException {
+
+ }
+
+ public void testReadSource() throws Exception {
+ Object source = reader.read(null, message, Source.class);
+
+ assertNotNull(source);
+ assertTrue(source instanceof Source);
+ assertTrue(XMLUtils.toString((Source)source).contains(expected));
+ }
+
+ public void testReadStreamSource() throws Exception {
+ Object source = reader.read(null, message, StreamSource.class);
+ assertNotNull(source);
+ assertTrue(source instanceof StreamSource);
+ assertTrue(XMLUtils.toString((StreamSource)source).contains(expected));
+ }
+
+ public void testReadSOAPMessage() throws Exception {
+ Object source = reader.read(null, message, SOAPMessage.class);
+ assertNotNull(source);
+ assertTrue(source instanceof SOAPMessage);
+ SOAPMessage m = (SOAPMessage) source;
+ Document doc = m.getSOAPBody().extractContentAsDocument();
+ assertEquals("TestSOAPInputMessage", doc.getFirstChild().getTextContent());
+ }
+
+ private InputStream getTestStream(String resource) {
+ return getClass().getResourceAsStream(resource);
+ }
+}
Propchange: incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPMessageDataReaderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/SOAPMessageDataReaderTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/cxf/trunk/rt/frontend/jaxws/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/pom.xml?view=diff&rev=441477&r1=441476&r2=441477
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/pom.xml (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/pom.xml Fri Sep 8 04:31:16 2006
@@ -73,6 +73,13 @@
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-bindings-xml</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-local</artifactId>
@@ -83,6 +90,10 @@
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.xml.soap</groupId>
+ <artifactId>saaj-api</artifactId>
+ </dependency>
</dependencies>
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java?view=diff&rev=441477&r1=441476&r2=441477
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java Fri Sep 8 04:31:16 2006
@@ -53,7 +53,7 @@
import org.apache.cxf.transport.MessageObserver;
public class DispatchImpl<T> extends BindingProviderImpl implements Dispatch<T>, MessageObserver {
- private static final Logger LOG = LogUtils.getL7dLogger(EndpointInvocationHandler.class);
+ private static final Logger LOG = LogUtils.getL7dLogger(DispatchImpl.class);
private Bus bus;
@@ -109,7 +109,7 @@
message.setContent(Object.class, obj);
- PhaseInterceptorChain chain = getDispatchChain();
+ PhaseInterceptorChain chain = getDispatchOutChain();
message.setInterceptorChain(chain);
// setup conduit
@@ -154,7 +154,7 @@
}
- private PhaseInterceptorChain getDispatchChain() {
+ private PhaseInterceptorChain getDispatchOutChain() {
PhaseManager pm = bus.getExtension(PhaseManager.class);
PhaseInterceptorChain chain = new PhaseInterceptorChain(pm.getOutPhases());
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java?view=diff&rev=441477&r1=441476&r2=441477
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java Fri Sep 8 04:31:16 2006
@@ -34,6 +34,7 @@
import org.apache.cxf.binding.soap.Soap12;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.SoapVersion;
+import org.apache.cxf.binding.xml.XMLMessage;
import org.apache.cxf.databinding.DataReader;
import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
import org.apache.cxf.interceptor.Fault;
@@ -68,8 +69,12 @@
DataReader<SOAPBody> dataReader = getDataReader(message, SOAPBody.class);
message.setContent(Object.class, dataReader.read(null, soapMessage.getSOAPBody(), type));
}
+ } else if (message instanceof XMLMessage) {
+ DataReader<XMLMessage> dataReader = getDataReader(message, XMLMessage.class);
+ message.setContent(Object.class,
+ dataReader.read(null,
+ (XMLMessage)message, type));
}
- // TODO XMLMessage
} catch (Exception e) {
e.printStackTrace();
}
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java?view=diff&rev=441477&r1=441476&r2=441477
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java Fri Sep 8 04:31:16 2006
@@ -19,6 +19,7 @@
package org.apache.cxf.jaxws.interceptors;
+import java.io.IOException;
import java.io.OutputStream;
import javax.activation.DataSource;
@@ -33,7 +34,9 @@
import javax.xml.ws.Service;
import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.xml.XMLMessage;
import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
import org.apache.cxf.interceptor.Fault;
@@ -60,24 +63,36 @@
if (obj instanceof SOAPMessage) {
((SOAPMessage)obj).writeTo(os);
} else if (obj instanceof Source) {
- doTransform((Source)obj, os);
+ doTransform(obj, os);
} else if (obj instanceof DataSource) {
- throw new RuntimeException("DataSource is not valid in Message mode for SOAP/HTTP");
+ throw new RuntimeException(obj.getClass()
+ + " is not valid in Message mode for SOAP/HTTP");
}
} else if (m == Service.Mode.PAYLOAD) {
SOAPMessage msg = initSOAPMessage();
DataWriter<SOAPBody> dataWriter = getDataWriter(message, SOAPBody.class);
if (obj instanceof Source || obj instanceof Object) {
dataWriter.write(obj, msg.getSOAPBody());
- } else if (obj instanceof SOAPMessage) {
- throw new RuntimeException("SOAPMessage is not valid in PAYLOAD mode for SOAP/HTTP");
- } else if (obj instanceof DataSource) {
- throw new RuntimeException("DataSource is not valid in PAYLOAD mode for SOAP/HTTP");
+ } else if (obj instanceof SOAPMessage || obj instanceof DataSource) {
+ throw new RuntimeException(obj.getClass()
+ + " is not valid in PAYLOAD mode with SOAP/HTTP");
}
msg.writeTo(os);
}
+ } else if (message instanceof XMLMessage) {
+ if (m == Service.Mode.MESSAGE) {
+ if (obj instanceof SOAPMessage) {
+ throw new RuntimeException("SOAPMessage is not valid in MESSAGE mode with XML/HTTP");
+ }
+ } else if (m == Service.Mode.PAYLOAD) {
+ if (obj instanceof SOAPMessage || obj instanceof DataSource) {
+ throw new RuntimeException(obj.getClass()
+ + " is not valid in PAYLOAD mode with XML/HTTP");
+ }
+ }
+ doTransform(obj, os);
}
- // TODO XMLMessage
+ // Finish the message processing, do flush
os.flush();
} catch (Exception e) {
e.printStackTrace();
@@ -95,9 +110,14 @@
return msg;
}
- private void doTransform(Source src, OutputStream os) throws TransformerException {
- Transformer transformer = XMLUtils.newTransformer();
- transformer.transform(src, new StreamResult(os));
+ private void doTransform(Object obj, OutputStream os) throws TransformerException, IOException {
+ if (obj instanceof Source) {
+ Transformer transformer = XMLUtils.newTransformer();
+ transformer.transform((Source)obj, new StreamResult(os));
+ }
+ if (obj instanceof DataSource) {
+ IOUtils.copy(((DataSource)obj).getInputStream(), os);
+ }
}
}
Added: incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java?view=auto&rev=441477
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java (added)
+++ incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java Fri Sep 8 04:31:16 2006
@@ -0,0 +1,35 @@
+package org.apache.cxf.hello_world_xml_http.wrapped;
+
+import org.apache.hello_world_xml_http.wrapped.Greeter;
+import org.apache.hello_world_xml_http.wrapped.PingMeFault;
+import org.apache.hello_world_xml_http.wrapped.types.FaultDetail;
+
+@javax.jws.WebService(serviceName = "XMLService",
+ portName = "XMLPort",
+ endpointInterface = "org.apache.hello_world_xml_http.wrapped.Greeter",
+ targetNamespace = "http://objectweb.org/hello_world_xml_http/wrapped")
+
+@javax.xml.ws.BindingType(value = "http://celtix.objectweb.org/bindings/xmlformat")
+
+public class GreeterImpl implements Greeter {
+
+ public String greetMe(String me) {
+ return "Hello " + me;
+ }
+
+ public void greetMeOneWay(String me) {
+ System.out.println("Executing operation greetMeOneWay\n");
+ System.out.println("Hello there " + me);
+ }
+
+ public String sayHi() {
+ return "Bonjour";
+ }
+
+ public void pingMe() throws PingMeFault {
+ FaultDetail faultDetail = new FaultDetail();
+ faultDetail.setMajor((short)2);
+ faultDetail.setMinor((short)1);
+ throw new PingMeFault("PingMeFault raised by server", faultDetail);
+ }
+}
Propchange: incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/testutils/src/main/resources/messages/SOAP_GreetMeDocLiteralReq.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/resources/messages/SOAP_GreetMeDocLiteralReq.xml?view=auto&rev=441477
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/resources/messages/SOAP_GreetMeDocLiteralReq.xml (added)
+++ incubator/cxf/trunk/testutils/src/main/resources/messages/SOAP_GreetMeDocLiteralReq.xml Fri Sep 8 04:31:16 2006
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body><ns4:greetMe xmlns:ns4="http://apache.org/hello_world_soap_http/types"><ns4:requestType>TestSOAPInputMessage</ns4:requestType></ns4:greetMe></SOAP-ENV:Body></SOAP-ENV:Envelope>
Propchange: incubator/cxf/trunk/testutils/src/main/resources/messages/SOAP_GreetMeDocLiteralReq.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/testutils/src/main/resources/messages/SOAP_GreetMeDocLiteralReq.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/testutils/src/main/resources/messages/SOAP_GreetMeDocLiteralReq.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq.xml?view=auto&rev=441477
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq.xml (added)
+++ incubator/cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq.xml Fri Sep 8 04:31:16 2006
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<ns2:greetMe xmlns="http://www.w3.org/2005/08/addressing/wsdl"
+ xmlns:ns2="http://apache.org/hello_world_xml_http/wrapped/types">
+ <ns2:requestType>tli</ns2:requestType>
+</ns2:greetMe>
Propchange: incubator/cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml