You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2010/09/02 16:02:58 UTC

svn commit: r991939 - in /cxf/trunk/common/common/src: main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java test/java/org/apache/cxf/staxutils/StaxUtilsTest.java test/java/org/apache/cxf/staxutils/resources/AddRequest.xml

Author: ffang
Date: Thu Sep  2 14:02:58 2010
New Revision: 991939

URL: http://svn.apache.org/viewvc?rev=991939&view=rev
Log:
[CXF-2969]StreamWriterContentHandler.getPrefix shouldn't return null if DEFAULT_NS_PREFIX is used

Added:
    cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/AddRequest.xml
Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
    cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java?rev=991939&r1=991938&r2=991939&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java Thu Sep  2 14:02:58 2010
@@ -163,16 +163,22 @@ public class StreamWriterContentHandler 
 
     /**
      * Method getPrefix.
+     * @param namespaceURI 
      *
      * @param qname
      * @return Returns String.
      */
-    private String getPrefix(String ns) {
+    private String getPrefix(String ns, String namespaceURI) {
         int idx = ns.indexOf(':');
         if (idx != -1) {
             return ns.substring(0, idx);
+        } else if (namespaceURI != null && namespaceURI.length() > 0) {
+            //this is the case that have namespaceURI but use DEFAULT_NS_PREFIX
+            return "";
+        } else {
+            //this is the case that namespaceURI is just empty, so NS_PREFIX is null
+            return null;
         }
-        return null;
     }
 
     /**
@@ -189,7 +195,7 @@ public class StreamWriterContentHandler 
                              String qName,
                              Attributes atts) throws SAXException {
         try {
-            String prefix = getPrefix(qName);
+            String prefix = getPrefix(qName, namespaceURI);
             
             // it is only the prefix we want to learn from the QName! so we can get rid of the
             // spliting QName

Modified: cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java?rev=991939&r1=991938&r2=991939&view=diff
==============================================================================
--- cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java (original)
+++ cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java Thu Sep  2 14:02:58 2010
@@ -23,6 +23,7 @@ import java.io.*;
 
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Source;
@@ -269,4 +270,22 @@ public class StaxUtilsTest extends Asser
         assertFalse(output.contains("<?pi in='the sky'?>"));
         assertFalse(output.contains("<?e excl='gads'?>"));
     }
+    
+    @Test
+    public void testDefaultPrefix() throws Exception {
+        try {
+            String soapMessage = "./resources/AddRequest.xml";     
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            XMLStreamReader reader = StaxUtils.createXMLStreamReader(getTestStream(soapMessage));
+            XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(baos);
+            StaxSource staxSource = new StaxSource(reader);
+            StaxUtils.copy(staxSource, writer);
+            writer.flush();
+            baos.flush();
+        } catch (XMLStreamException e) {
+            fail("shouldn't catch this exception");
+        }
+           
+        
+    }
 }

Added: cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/AddRequest.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/AddRequest.xml?rev=991939&view=auto
==============================================================================
--- cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/AddRequest.xml (added)
+++ cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/AddRequest.xml Thu Sep  2 14:02:58 2010
@@ -0,0 +1,20 @@
+<?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://www.w3.org/2003/05/soap-envelope"><soap:Body><add xmlns="http://apache.org/cxf/calculator/types"><arg0>1</arg0><arg1>2</arg1></add></soap:Body></soap:Envelope>