You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2018/12/23 16:28:33 UTC

svn commit: r1849644 - in /axis/axis2/java/core/trunk/modules: fastinfoset/src/org/apache/axis2/fastinfoset/ json/src/org/apache/axis2/json/

Author: veithen
Date: Sun Dec 23 16:28:32 2018
New Revision: 1849644

URL: http://svn.apache.org/viewvc?rev=1849644&view=rev
Log:
Implement getBytes using writeTo in JSON and FastInfoset message formatters.

Modified:
    axis/axis2/java/core/trunk/modules/fastinfoset/src/org/apache/axis2/fastinfoset/FastInfosetMessageFormatter.java
    axis/axis2/java/core/trunk/modules/fastinfoset/src/org/apache/axis2/fastinfoset/FastInfosetPOXMessageFormatter.java
    axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/AbstractJSONMessageFormatter.java

Modified: axis/axis2/java/core/trunk/modules/fastinfoset/src/org/apache/axis2/fastinfoset/FastInfosetMessageFormatter.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/fastinfoset/src/org/apache/axis2/fastinfoset/FastInfosetMessageFormatter.java?rev=1849644&r1=1849643&r2=1849644&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/fastinfoset/src/org/apache/axis2/fastinfoset/FastInfosetMessageFormatter.java (original)
+++ axis/axis2/java/core/trunk/modules/fastinfoset/src/org/apache/axis2/fastinfoset/FastInfosetMessageFormatter.java Sun Dec 23 16:28:32 2018
@@ -59,23 +59,9 @@ public class FastInfosetMessageFormatter
      */
     public byte[] getBytes(MessageContext messageContext, OMOutputFormat format)
             throws AxisFault {
-        OMElement element = messageContext.getEnvelope();
         ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-        
-        try {
-            //Creates StAX document serializer which actually implements the XMLStreamWriter
-            XMLStreamWriter streamWriter = new StAXDocumentSerializer(outStream);
-            streamWriter.writeStartDocument();
-            element.serializeAndConsume(streamWriter);
-            //TODO Looks like the SOAP envelop doesn't have an end document tag. Find out why?
-            streamWriter.writeEndDocument();
-            
-            return outStream.toByteArray();
-            
-        } catch (XMLStreamException xmlse) {
-            logger.error(xmlse.getMessage());
-            throw new AxisFault(xmlse.getMessage(), xmlse);
-        }
+        writeTo(messageContext, format, outStream, false);
+        return outStream.toByteArray();
     }
 
     /**

Modified: axis/axis2/java/core/trunk/modules/fastinfoset/src/org/apache/axis2/fastinfoset/FastInfosetPOXMessageFormatter.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/fastinfoset/src/org/apache/axis2/fastinfoset/FastInfosetPOXMessageFormatter.java?rev=1849644&r1=1849643&r2=1849644&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/fastinfoset/src/org/apache/axis2/fastinfoset/FastInfosetPOXMessageFormatter.java (original)
+++ axis/axis2/java/core/trunk/modules/fastinfoset/src/org/apache/axis2/fastinfoset/FastInfosetPOXMessageFormatter.java Sun Dec 23 16:28:32 2018
@@ -59,24 +59,9 @@ public class FastInfosetPOXMessageFormat
      */
     public byte[] getBytes(MessageContext messageContext, OMOutputFormat format)
             throws AxisFault {
-        //For POX drop the SOAP envelope and use the message body
-        OMElement element = messageContext.getEnvelope().getBody().getFirstElement();
         ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-        
-        try {
-            //Creates StAX document serializer which actually implements the XMLStreamWriter
-            XMLStreamWriter streamWriter = new StAXDocumentSerializer(outStream);
-            //Since we drop the SOAP envelop we have to manually write the start document and the end document events
-            streamWriter.writeStartDocument();
-            element.serializeAndConsume(streamWriter);
-            streamWriter.writeEndDocument();
-            
-            return outStream.toByteArray();
-            
-        } catch (XMLStreamException xmlse) {
-            logger.error(xmlse.getMessage());
-            throw new AxisFault(xmlse.getMessage(), xmlse);
-        }
+        writeTo(messageContext, format, outStream, false);
+        return outStream.toByteArray();
     }
 
     /**

Modified: axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/AbstractJSONMessageFormatter.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/AbstractJSONMessageFormatter.java?rev=1849644&r1=1849643&r2=1849644&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/AbstractJSONMessageFormatter.java (original)
+++ axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/AbstractJSONMessageFormatter.java Sun Dec 23 16:28:32 2018
@@ -91,34 +91,9 @@ public abstract class AbstractJSONMessag
      */
 
     public byte[] getBytes(MessageContext msgCtxt, OMOutputFormat format) throws AxisFault {
-        OMElement element = msgCtxt.getEnvelope().getBody().getFirstElement();
-        //if the element is an OMSourcedElement and it contains a JSONDataSource with
-        //correct convention, directly get the JSON string.
-
-        String jsonToWrite = getStringToWrite(element);
-        if (jsonToWrite != null) {
-            return jsonToWrite.getBytes();
-            //otherwise serialize the OM by expanding the tree
-        } else {
-            try {
-                ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
-                XMLStreamWriter jsonWriter = getJSONWriter(bytesOut, format, msgCtxt);
-                element.serializeAndConsume(jsonWriter);
-                jsonWriter.writeEndDocument();
-
-                return bytesOut.toByteArray();
-
-            } catch (XMLStreamException e) {
-                throw AxisFault.makeFault(e);
-            } catch (FactoryConfigurationError e) {
-                throw AxisFault.makeFault(e);
-            } catch (IllegalStateException e) {
-                throw new AxisFault(
-                        "Mapped formatted JSON with namespaces are not supported in Axis2. " +
-                                "Make sure that your request doesn't include namespaces or " +
-                                "use the Badgerfish convention");
-            }
-        }
+        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+        writeTo(msgCtxt, format, bytesOut, true);
+        return bytesOut.toByteArray();
     }
 
     public String formatSOAPAction(MessageContext msgCtxt, OMOutputFormat format,