Author: ay
Date: Mon Oct 15 17:39:40 2012
New Revision: 1398414
URL: http://svn.apache.org/viewvc?rev=1398414&view=rev
Log:
[CXF-4566] StaxTransformFeature outTransformElements does not work when
conversing namespaces
Added:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq5.xml
(with props)
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn5.xml
(with props)
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java?rev=1398414&r1=1398413&r2=1398414&view=diff
==============================================================================
---
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
(original)
+++
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
Mon Oct 15 17:39:40 2012
@@ -306,6 +306,8 @@ public class InTransformReader extends D
String actualNs = nsMap.get(ns);
if (actualNs != null) {
return actualNs;
+ } else if (ns.equals(reader.getNamespaceURI())) {
+ return getNamespaceURI();
} else {
return ns;
}
@@ -320,6 +322,8 @@ public class InTransformReader extends D
} else {
return "";
}
+ } else if (ns.equals(reader.getNamespaceURI())) {
+ return getPrefix();
} else {
return namespaceContext.getPrefix(ns);
}
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java?rev=1398414&r1=1398413&r2=1398414&view=diff
==============================================================================
---
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
(original)
+++
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
Mon Oct 15 17:39:40 2012
@@ -108,11 +108,13 @@ public class OutTransformWriter extends
if (defaultNamespace != null && defaultNamespace.equals(uri)) {
super.writeDefaultNamespace(uri);
+ namespaceContext.addPrefix("", uri);
} else {
if (prefix.length() == 0) {
prefix = namespaceContext.findUniquePrefix(uri);
}
super.writeNamespace(prefix, uri);
+ namespaceContext.addPrefix(prefix, uri);
}
writtenUris.get(0).add(uri);
}
@@ -135,7 +137,7 @@ public class OutTransformWriter extends
return;
}
super.writeDefaultNamespace(uri);
-
+ namespaceContext.addPrefix("", uri);
writtenUris.get(0).add(uri);
}
@@ -363,13 +365,13 @@ public class OutTransformWriter extends
namespaceContext.addPrefix(prefix, qname.getNamespaceURI());
}
- }
+ }
if (isDefaultNamespaceRedefined(qname.getNamespaceURI())) {
prefix = "";
}
-
super.writeStartElement(prefix, qname.getLocalPart(),
qname.getNamespaceURI());
- if (writeNs) {
+ if (writeNs
+ ||
!qname.getNamespaceURI().equals(namespaceContext.getNamespaceURI(prefix))) {
this.writeNamespace(prefix, qname.getNamespaceURI());
}
}
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java?rev=1398414&r1=1398413&r2=1398414&view=diff
==============================================================================
---
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java
(original)
+++
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java
Mon Oct 15 17:39:40 2012
@@ -97,7 +97,8 @@ public final class TransformUtils {
QName lname = XMLUtils.convertStringToQName(entry.getKey());
QName rname = XMLUtils.convertStringToQName(entry.getValue());
elementsMap.put(lname, rname);
- if (nsMap != null && !isEmptyQName(rname)) {
+ if (nsMap != null && !isEmptyQName(rname)
+ && ("*".equals(lname.getLocalPart()) &&
"*".equals(rname.getLocalPart()))) {
nsMap.put(lname.getNamespaceURI(),
rname.getNamespaceURI());
}
}
Added:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq5.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq5.xml?rev=1398414&view=auto
==============================================================================
---
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq5.xml
(added)
+++
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq5.xml
Mon Oct 15 17:39:40 2012
@@ -0,0 +1,29 @@
+<?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:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Header/>
+ <soap:Body>
+ <ns2:subscribeResponse
xmlns="http://cxf.apache.org/vgop/serviceorder/v1_0/common"
xmlns:ns2="http://cxf.apache.org/vgop/serviceorder/v1_0">
+ <ns2:SubscribeResp>
+ <result xmlns="">0</result>
+ </ns2:SubscribeResp>
+ </ns2:subscribeResponse>
+ </soap:Body>
+</soap:Envelope>
Propchange:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq5.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn5.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn5.xml?rev=1398414&view=auto
==============================================================================
---
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn5.xml
(added)
+++
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn5.xml
Mon Oct 15 17:39:40 2012
@@ -0,0 +1,29 @@
+<?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:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Header/>
+ <soap:Body>
+ <ns2:subscribeResponse
xmlns="http://cxf.apache.org/vgop/serviceorder/v1_0/common"
xmlns:ns2="http://cxf.apache.org/vgop/serviceorder/v1_0">
+ <ns2:SubscribeResp>
+ <ns2:result>0</ns2:result>
+ </ns2:SubscribeResp>
+ </ns2:subscribeResponse>
+ </soap:Body>
+</soap:Envelope>
Propchange:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn5.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java?rev=1398414&r1=1398413&r2=1398414&view=diff
==============================================================================
---
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
(original)
+++
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
Mon Oct 15 17:39:40 2012
@@ -115,9 +115,9 @@ public class OutTransformWriterTest exte
String xmlPI = "<?xml version='1.0' encoding='UTF-8'?>";
String start = "<testBean xmlns=\"http://testbeans.com/v2\"";
String expected1 = xmlPI + start
- + " xmlns:ps2=\"http://testbeans.com/v3\"><ps2:bean/></testBean>";
+ + " xmlns:ps1=\"http://testbeans.com/v3\"><ps1:bean/></testBean>";
String expected2 = xmlPI + start
- + "><ps2:bean xmlns:ps2=\"http://testbeans.com/v3\"/></testBean>";
+ + "><ps1:bean xmlns:ps1=\"http://testbeans.com/v3\"/></testBean>";
String out = os.toString();
assertTrue("Output \"" + out + "\" does not match expected values",
expected1.equals(out) || expected2.equals(out));
@@ -286,6 +286,20 @@ public class OutTransformWriterTest exte
}
@Test
+ public void testRemoveOneNamespace() throws Exception {
+ Map<String, String> inMap = new HashMap<String, String>();
+ inMap.put("{http://www.chinamobile.com/vgop/serviceorder/v1_0}result",
"result");
+ XMLStreamReader reader =
+
TransformTestUtils.createOutTransformedStreamReader("../resources/complexReqIn5.xml",
+ inMap, null,
null, null, false, null);
+
+ XMLStreamReader reader2 =
+ StaxUtils.createXMLStreamReader(
+
InTransformReader.class.getResourceAsStream("../resources/complexReq5.xml"));
+ TransformTestUtils.verifyReaders(reader2, reader, true, true);
+ }
+
+ @Test
public void testReadWithReplaceAppend() throws Exception {
Map<String, String> transformElements = new HashMap<String, String>();
transformElements.put("requestValue",