You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by na...@apache.org on 2009/11/17 14:58:31 UTC

svn commit: r881293 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-api/src/main/java/org/apache/axiom/om/ds/ axiom-tests/src/test/java/org/apache/axiom/om/

Author: nagy
Date: Tue Nov 17 13:58:30 2009
New Revision: 881293

URL: http://svn.apache.org/viewvc?rev=881293&view=rev
Log:
Revised patch for fixing potential NPE during serialization if an encoding has not been set for the OMOutputFormat.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java?rev=881293&r1=881292&r2=881293&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java Tue Nov 17 13:58:30 2009
@@ -208,10 +208,9 @@
     }
 
     /**
-     * Returns the character set encoding scheme. If the value of the charSetEncoding is not set
-     * then the default will be returned.
+     * Returns the character set encoding scheme.
      *
-     * @return Returns encoding string.
+     * @return Returns encoding string or null if it has not been set.
      */
     public String getCharSetEncoding() {
         return this.charSetEncoding;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java?rev=881293&r1=881292&r2=881293&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java Tue Nov 17 13:58:30 2009
@@ -19,6 +19,7 @@
 package org.apache.axiom.om.ds;
 
 import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -77,9 +78,15 @@
     }
 
     public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+        if (encoding == null)
+        {
+          encoding = OMOutputFormat.DEFAULT_CHAR_SET_ENCODING;
+        }
+
         if (DEBUG_ENABLED) {
             log.debug("getXMLBytes encoding="+encoding);
         }
+
         // Return the byte array directly if it is the same encoding
         // Otherwise convert the bytes to the proper encoding
         if (!byteArray.encoding.equalsIgnoreCase(encoding)) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java?rev=881293&r1=881292&r2=881293&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java Tue Nov 17 13:58:30 2009
@@ -140,6 +140,15 @@
         assertTrue("The obtained bytes did not match the payload",
                    payload1.equals(payload));
         
+       
+        // Test getting the raw bytes with the default encoding
+        OMOutputFormat outputFormat = new OMOutputFormat();
+        baos = new ByteArrayOutputStream();
+        ds.serialize(baos, outputFormat);
+        output = baos.toString(OMOutputFormat.DEFAULT_CHAR_SET_ENCODING);
+        System.out.println(output);
+        assertTrue("The obtained bytes did not match the payload",
+                   payload1.equals(output));     
     }
     
     /**



Re: svn commit: r881293 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-api/src/main/java/org/apache/axiom/om/ds/ axiom-tests/src/test/java/org/apache/axiom/om/

Posted by Deepal jayasinghe <de...@gmail.com>.
Seems like you have forgotten to remove the 
System.out.println(output);   :-)
Thanks,
Deepal
> Author: nagy
> Date: Tue Nov 17 13:58:30 2009
> New Revision: 881293
>
> URL: http://svn.apache.org/viewvc?rev=881293&view=rev
> Log:
> Revised patch for fixing potential NPE during serialization if an encoding has not been set for the OMOutputFormat.
>
> Modified:
>     webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
>     webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java
>     webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java
>
> Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
> URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java?rev=881293&r1=881292&r2=881293&view=diff
> ==============================================================================
> --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java (original)
> +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java Tue Nov 17 13:58:30 2009
> @@ -208,10 +208,9 @@
>      }
>  
>      /**
> -     * Returns the character set encoding scheme. If the value of the charSetEncoding is not set
> -     * then the default will be returned.
> +     * Returns the character set encoding scheme.
>       *
> -     * @return Returns encoding string.
> +     * @return Returns encoding string or null if it has not been set.
>       */
>      public String getCharSetEncoding() {
>          return this.charSetEncoding;
>
> Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java
> URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java?rev=881293&r1=881292&r2=881293&view=diff
> ==============================================================================
> --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java (original)
> +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java Tue Nov 17 13:58:30 2009
> @@ -19,6 +19,7 @@
>  package org.apache.axiom.om.ds;
>  
>  import org.apache.axiom.om.OMDataSourceExt;
> +import org.apache.axiom.om.OMOutputFormat;
>  import org.apache.axiom.om.util.StAXUtils;
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
> @@ -77,9 +78,15 @@
>      }
>  
>      public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
> +        if (encoding == null)
> +        {
> +          encoding = OMOutputFormat.DEFAULT_CHAR_SET_ENCODING;
> +        }
> +
>          if (DEBUG_ENABLED) {
>              log.debug("getXMLBytes encoding="+encoding);
>          }
> +
>          // Return the byte array directly if it is the same encoding
>          // Otherwise convert the bytes to the proper encoding
>          if (!byteArray.encoding.equalsIgnoreCase(encoding)) {
>
> Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java
> URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java?rev=881293&r1=881292&r2=881293&view=diff
> ==============================================================================
> --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java (original)
> +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java Tue Nov 17 13:58:30 2009
> @@ -140,6 +140,15 @@
>          assertTrue("The obtained bytes did not match the payload",
>                     payload1.equals(payload));
>          
> +       
> +        // Test getting the raw bytes with the default encoding
> +        OMOutputFormat outputFormat = new OMOutputFormat();
> +        baos = new ByteArrayOutputStream();
> +        ds.serialize(baos, outputFormat);
> +        output = baos.toString(OMOutputFormat.DEFAULT_CHAR_SET_ENCODING);
> +        System.out.println(output);
> +        assertTrue("The obtained bytes did not match the payload",
> +                   payload1.equals(output));     
>      }
>      
>      /**
>
>
>
>   


-- 
Thank you!


http://blogs.deepal.org
http://deepal.org