Author: bimargulies
Date: Thu Jul 16 18:10:28 2009
New Revision: 794771
URL: http://svn.apache.org/viewvc?rev=794771&view=rev
Log:
CXF-2309, avoid exposing unwanted XML element for Document mapping.
Added:
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/DOMMappingTest.java
(with props)
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/BeanWithDOM.java
(with props)
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/DocumentService.java
(with props)
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/IDocumentService.java
(with props)
Modified:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/WrappedTest.java
Modified:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java?rev=794771&r1=794770&r2=794771&view=diff
==============================================================================
---
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java
(original)
+++
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java
Thu Jul 16 18:10:28 2009
@@ -25,6 +25,7 @@
import javax.xml.stream.XMLStreamReader;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.apache.cxf.aegis.Context;
import org.apache.cxf.aegis.DatabindingException;
@@ -64,20 +65,32 @@
public Object readObject(MessageReader mreader, Context context) throws
DatabindingException {
try {
XMLStreamReader reader =
((ElementReader)mreader).getXMLStreamReader();
- return StaxUtils.read(builder, new FragmentStreamReader(reader),
true);
+ // we need to eat the surrounding element.
+ reader.nextTag();
+ Object tree = StaxUtils.read(builder, new
FragmentStreamReader(reader), true);
+ reader.nextTag(); // eat the end tag.
+ return tree;
} catch (XMLStreamException e) {
throw new DatabindingException("Could not parse xml.", e);
}
}
@Override
- public void writeObject(Object object, MessageWriter writer,
+ public void writeObject(Object object, MessageWriter writer,
Context context) throws DatabindingException {
Document doc = (Document)object;
try {
- StaxUtils.writeElement(doc.getDocumentElement(),
((ElementWriter)writer).getXMLStreamWriter(),
- false);
+ Element docElement = doc.getDocumentElement();
+ if (docElement == null) {
+ if (isNillable()) {
+ writer.writeXsiNil();
+ } else {
+ throw new DatabindingException("Could not write xml: null
document element.");
+ }
+ } else {
+ StaxUtils.writeElement(docElement,
((ElementWriter)writer).getXMLStreamWriter(), false);
+ }
} catch (XMLStreamException e) {
throw new DatabindingException("Could not write xml.", e);
}
Added:
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/DOMMappingTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/DOMMappingTest.java?rev=794771&view=auto
==============================================================================
---
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/DOMMappingTest.java
(added)
+++
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/DOMMappingTest.java
Thu Jul 16 18:10:28 2009
@@ -0,0 +1,97 @@
+/**
+ * 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.aegis.integration;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.Text;
+
+import org.apache.cxf.aegis.AbstractAegisTest;
+import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.aegis.services.BeanWithDOM;
+import org.apache.cxf.aegis.services.DocumentService;
+import org.apache.cxf.aegis.services.IDocumentService;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.endpoint.ClientImpl;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test mapping DOM.
+ * Commented out code for the case of an embedded Node object,
+ * which doesn't work at all, and perhaps isn't supposed to.
+ */
+public class DOMMappingTest extends AbstractAegisTest {
+
+ private IDocumentService docClient;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ createService(DocumentService.class, "DocService");
+ ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
+ ReflectionServiceFactoryBean factory = new
ReflectionServiceFactoryBean();
+ factory.getServiceConfigurations()
+ .add(0, new
org.apache.cxf.aegis.databinding.XFireCompatibilityServiceConfiguration());
+ proxyFac.setServiceFactory(factory);
+ proxyFac.setDataBinding(new AegisDatabinding());
+
+ proxyFac.setAddress("local://DocService");
+ proxyFac.setServiceClass(IDocumentService.class);
+ proxyFac.setBus(getBus());
+
+ Object proxyObj = proxyFac.create();
+ docClient = (IDocumentService)proxyObj;
+ Client client = ClientProxy.getClient(proxyObj);
+ ClientImpl clientImpl = (ClientImpl)client;
+ clientImpl.setSynchronousTimeout(1000000000);
+ }
+
+ @Test
+ public void testSimpleString() throws Exception {
+ String s = docClient.simpleStringReturn();
+ assertEquals("simple", s);
+ }
+
+ @Test
+ public void testDocService() throws Exception {
+ Document doc = docClient.returnDocument();
+ Element rootElement = doc.getDocumentElement();
+ assertEquals("carrot", rootElement.getNodeName());
+ }
+
+ @Test
+ public void testBeanCases() throws Exception {
+ BeanWithDOM bwd = docClient.getBeanWithDOM();
+ Element rootElement = bwd.getDocument().getDocumentElement();
+ assertEquals("carrot", rootElement.getNodeName());
+ /*
+ Node shouldBeText = bwd.getNode();
+ assertTrue(shouldBeText instanceof Text);
+ Text text = (Text) shouldBeText;
+ assertEquals("Is a root vegetable.", text);
+ */
+ }
+}
Propchange:
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/DOMMappingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/WrappedTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/WrappedTest.java?rev=794771&r1=794770&r2=794771&view=diff
==============================================================================
---
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/WrappedTest.java
(original)
+++
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/WrappedTest.java
Thu Jul 16 18:10:28 2009
@@ -158,7 +158,7 @@
assertEquals("before items", arrayService.getBeforeValue());
assertEquals(3, arrayService.getW3cArray().length);
org.w3c.dom.Document e = arrayService.getW3cArray()[0];
- assertValid("/a:anyType/iam:walrus", e);
+ assertValid("/iam:walrus", e);
assertEquals("after items", arrayService.getAfterValue());
}
Added:
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/BeanWithDOM.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/BeanWithDOM.java?rev=794771&view=auto
==============================================================================
---
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/BeanWithDOM.java
(added)
+++
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/BeanWithDOM.java
Thu Jul 16 18:10:28 2009
@@ -0,0 +1,78 @@
+/**
+ * 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.aegis.services;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+//import org.w3c.dom.Node;
+//import org.w3c.dom.Text;
+
+/**
+ *
+ */
+public class BeanWithDOM {
+ private Document document;
+// private Node node;
+
+
+ public void fillWithSomeData() {
+ DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
+ DocumentBuilder db;
+ try {
+ db = documentBuilderFactory.newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
+ }
+ Document doc = db.newDocument();
+ Element rootElement = doc.createElement("carrot");
+ rootElement.appendChild(doc.createTextNode("Is a root vegetable"));
+ doc.appendChild(rootElement);
+ document = doc;
+ /*
+ doc = db.newDocument();
+ rootElement = doc.createElement("beet");
+ doc.appendChild(rootElement);
+ Text beetText = doc.createTextNode("Is a root vegetable.");
+ rootElement.appendChild(beetText);
+ node = beetText;
+ */
+ }
+
+ public Document getDocument() {
+ return document;
+ }
+ public void setDocument(Document document) {
+ this.document = document;
+ }
+
+ /*
+ public Node getNode() {
+ return node;
+ }
+ public void setNode(Node node) {
+ this.node = node;
+ }
+ */
+
+}
Propchange:
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/BeanWithDOM.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/DocumentService.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/DocumentService.java?rev=794771&view=auto
==============================================================================
---
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/DocumentService.java
(added)
+++
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/DocumentService.java
Thu Jul 16 18:10:28 2009
@@ -0,0 +1,63 @@
+/**
+ * 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.aegis.services;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Test for mapping to DOM Document.
+ */
+public class DocumentService implements IDocumentService {
+
+ private DocumentBuilderFactory documentBuilderFactory;
+
+ public DocumentService() {
+ documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ }
+
+ /** {...@inheritdoc}*/
+ public Document returnDocument() {
+ try {
+ DocumentBuilder db = documentBuilderFactory.newDocumentBuilder();
+ Document doc = db.newDocument();
+ Element rootElement = doc.createElement("carrot");
+ rootElement.appendChild(doc.createTextNode("Is a root vegetable"));
+ doc.appendChild(rootElement);
+ return doc;
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public BeanWithDOM getBeanWithDOM() {
+ BeanWithDOM bwd = new BeanWithDOM();
+ bwd.fillWithSomeData();
+ return bwd;
+ }
+
+ public String simpleStringReturn() {
+ return "simple";
+ }
+}
Propchange:
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/DocumentService.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/IDocumentService.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/IDocumentService.java?rev=794771&view=auto
==============================================================================
---
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/IDocumentService.java
(added)
+++
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/IDocumentService.java
Thu Jul 16 18:10:28 2009
@@ -0,0 +1,28 @@
+/**
+ * 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.aegis.services;
+
+import org.w3c.dom.Document;
+
+public interface IDocumentService {
+ Document returnDocument();
+ BeanWithDOM getBeanWithDOM();
+ String simpleStringReturn(); // purposes of comparison
+}
Propchange:
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/IDocumentService.java
------------------------------------------------------------------------------
svn:eol-style = native