airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chath...@apache.org
Subject svn commit: r1513550 - in /airavata/trunk/modules: commons/ commons/json/ commons/json/src/ commons/json/src/main/ commons/json/src/main/java/ commons/json/src/main/java/org/ commons/json/src/main/java/org/apache/ commons/json/src/main/java/org/apache/...
Date Tue, 13 Aug 2013 15:28:21 GMT
Author: chathuri
Date: Tue Aug 13 15:28:20 2013
New Revision: 1513550

URL: http://svn.apache.org/r1513550
Log:
applying patch from Shameera for AIRAVATA-898

Added:
    airavata/trunk/modules/commons/json/
    airavata/trunk/modules/commons/json/pom.xml
    airavata/trunk/modules/commons/json/src/
    airavata/trunk/modules/commons/json/src/main/
    airavata/trunk/modules/commons/json/src/main/java/
    airavata/trunk/modules/commons/json/src/main/java/org/
    airavata/trunk/modules/commons/json/src/main/java/org/apache/
    airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/
    airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/json/
    airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/json/StaxonJSONBuilder.java
    airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/json/StaxonJSONFormatter.java
Modified:
    airavata/trunk/modules/commons/pom.xml
    airavata/trunk/modules/distribution/airavata-server/pom.xml
    airavata/trunk/modules/distribution/airavata-server/src/main/assembly/bin-assembly.xml
    airavata/trunk/modules/distribution/airavata-server/src/main/resources/conf/axis2.xml

Added: airavata/trunk/modules/commons/json/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/commons/json/pom.xml?rev=1513550&view=auto
==============================================================================
--- airavata/trunk/modules/commons/json/pom.xml (added)
+++ airavata/trunk/modules/commons/json/pom.xml Tue Aug 13 15:28:20 2013
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>commons</artifactId>
+        <groupId>org.apache.airavata</groupId>
+        <version>0.9-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>json</artifactId>
+    <packaging>jar</packaging>
+    <name>Airavata JSON </name>
+    <url>http://airavata.apache.org/</url>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.axis2</groupId>
+            <artifactId>axis2-kernel</artifactId>
+            <version>${axis2.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>de.odysseus.staxon</groupId>
+            <artifactId>staxon</artifactId>
+            <version>1.2</version>
+        </dependency>
+        <dependency>
+            <groupId>de.odysseus.staxon</groupId>
+            <artifactId>staxon-jackson</artifactId>
+            <version>1.2</version>
+        </dependency>
+
+
+    </dependencies>
+
+</project>

Added: airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/json/StaxonJSONBuilder.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/json/StaxonJSONBuilder.java?rev=1513550&view=auto
==============================================================================
--- airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/json/StaxonJSONBuilder.java
(added)
+++ airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/json/StaxonJSONBuilder.java
Tue Aug 13 15:28:20 2013
@@ -0,0 +1,42 @@
+package org.apache.airavata.json;
+
+import de.odysseus.staxon.json.JsonXMLConfig;
+import de.odysseus.staxon.json.JsonXMLConfigBuilder;
+import de.odysseus.staxon.json.JsonXMLInputFactory;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.builder.Builder;
+import org.apache.axis2.context.MessageContext;
+
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.InputStream;
+
+
+public class StaxonJSONBuilder implements Builder {
+    @Override
+    public OMElement processDocument(InputStream inputStream, String s, MessageContext messageContext)
throws AxisFault {
+        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
+        SOAPEnvelope envelope = factory.createSOAPEnvelope();
+        // configure JSON to XML conversion property
+        JsonXMLConfig config = new JsonXMLConfigBuilder().multiplePI(false).prettyPrint(false).build();
+        //
+        try {
+            String charSetEncoding = (String) messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+            XMLStreamReader reader = new JsonXMLInputFactory(config).createXMLStreamReader(inputStream,
charSetEncoding);
+            StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(reader);
+            OMElement message = stAXOMBuilder.getDocumentElement();
+            envelope.getBody().addChild(message);
+        } catch (XMLStreamException e) {
+            throw new AxisFault("Error while creating XMLStreamReader with JsonXMLInputFactory");
+        }
+        return envelope;
+    }
+}

Added: airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/json/StaxonJSONFormatter.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/json/StaxonJSONFormatter.java?rev=1513550&view=auto
==============================================================================
--- airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/json/StaxonJSONFormatter.java
(added)
+++ airavata/trunk/modules/commons/json/src/main/java/org/apache/airavata/json/StaxonJSONFormatter.java
Tue Aug 13 15:28:20 2013
@@ -0,0 +1,85 @@
+package org.apache.airavata.json;
+
+import de.odysseus.staxon.json.JsonXMLConfig;
+import de.odysseus.staxon.json.JsonXMLConfigBuilder;
+import de.odysseus.staxon.json.JsonXMLOutputFactory;
+import de.odysseus.staxon.json.stream.jackson.JacksonStreamFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.transport.MessageFormatter;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.*;
+import javax.xml.transform.stax.StAXResult;
+import javax.xml.transform.stax.StAXSource;
+import java.io.OutputStream;
+import java.net.URL;
+
+public class StaxonJSONFormatter implements MessageFormatter {
+    @Override
+    public byte[] getBytes(MessageContext messageContext, OMOutputFormat omOutputFormat)
throws AxisFault {
+        return new byte[0];
+    }
+
+    @Override
+    public void writeTo(MessageContext messageContext, OMOutputFormat omOutputFormat, OutputStream
outputStream,
+                        boolean preserve) throws AxisFault {
+        String charSetEncoding = (String) messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+        JsonXMLConfig config = new JsonXMLConfigBuilder()
+                .autoArray(true)
+                .autoPrimitive(true)
+                .prettyPrint(true)
+                .build();
+
+
+
+        try {
+            OMElement outMessage = messageContext.getEnvelope().getBody().getFirstElement();
+            XMLStreamReader reader = null;
+            if (preserve) {
+                // do not consume the OM
+                reader = outMessage.getXMLStreamReader();
+            }else{
+                // consume the OM
+                reader = outMessage.getXMLStreamReaderWithoutCaching();
+            }
+            Source source = new StAXSource(reader);
+
+            XMLStreamWriter writer = new JsonXMLOutputFactory(config, new JacksonStreamFactory())
+                    .createXMLStreamWriter(outputStream, charSetEncoding);
+            Result result = new StAXResult(writer);
+            String backupProp = System.getProperty("javax.xml.transform.TransformerFactory");
+            System.setProperty("javax.xml.transform.TransformerFactory",
+                    "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
+            TransformerFactory.newInstance().newTransformer().transform(source, result);
+            System.setProperty("javax.xml.transform.TransformerFactory", backupProp);
+        } catch (XMLStreamException e) {
+            throw new AxisFault("Error while writing OMElement to output writer ", e);
+        } catch (TransformerConfigurationException e) {
+            throw new AxisFault("StaxonJSONFormatter threw an error while writing to output
",e);
+        } catch (TransformerException e) {
+            throw new AxisFault("StaxonJSONFormatter threw an error while writing to output",e);
+        }
+
+    }
+
+    @Override
+    public String getContentType(MessageContext messageContext, OMOutputFormat omOutputFormat,
String s) {
+        return (String) messageContext.getProperty(Constants.Configuration.CONTENT_TYPE);
+    }
+
+    @Override
+    public URL getTargetAddress(MessageContext messageContext, OMOutputFormat omOutputFormat,
URL url) throws AxisFault {
+        return null;
+    }
+
+    @Override
+    public String formatSOAPAction(MessageContext messageContext, OMOutputFormat omOutputFormat,
String s) {
+        return null;
+    }
+}

Modified: airavata/trunk/modules/commons/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/commons/pom.xml?rev=1513550&r1=1513549&r2=1513550&view=diff
==============================================================================
--- airavata/trunk/modules/commons/pom.xml (original)
+++ airavata/trunk/modules/commons/pom.xml Tue Aug 13 15:28:20 2013
@@ -22,7 +22,7 @@
     <packaging>pom</packaging>
     <name>Airavata Commons</name>
     <url>http://airavata.apache.org/</url>
-    
+
     <profiles>
         <profile>
             <id>default</id>
@@ -34,6 +34,7 @@
                 <module>gfac-schema</module>
                 <module>utils</module>
                 <module>workflow-execution-context</module>
+                <module>json</module>
             </modules>
         </profile>
     </profiles>

Modified: airavata/trunk/modules/distribution/airavata-server/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/distribution/airavata-server/pom.xml?rev=1513550&r1=1513549&r2=1513550&view=diff
==============================================================================
--- airavata/trunk/modules/distribution/airavata-server/pom.xml (original)
+++ airavata/trunk/modules/distribution/airavata-server/pom.xml Tue Aug 13 15:28:20 2013
@@ -364,6 +364,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.airavata</groupId>
+            <artifactId>json</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.airavata</groupId>
             <artifactId>airavata-messenger-client</artifactId>
             <version>${project.version}</version>
         </dependency>

Modified: airavata/trunk/modules/distribution/airavata-server/src/main/assembly/bin-assembly.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/distribution/airavata-server/src/main/assembly/bin-assembly.xml?rev=1513550&r1=1513549&r2=1513550&view=diff
==============================================================================
--- airavata/trunk/modules/distribution/airavata-server/src/main/assembly/bin-assembly.xml
(original)
+++ airavata/trunk/modules/distribution/airavata-server/src/main/assembly/bin-assembly.xml
Tue Aug 13 15:28:20 2013
@@ -255,6 +255,7 @@
                 <include>org.apache.airavata:airavata-rest-mappings</include>
                 <include>org.apache.airavata:airavata-rest-services</include>
                 <include>org.apache.airavata:airavata-security</include>
+                <include>org.apache.airavata:json</include>
                 <include>org.apache.openjpa:openjpa-all:jar</include>
                 <include>com.sun.jersey:jersey-client:jar</include>
                 <include>com.sun.jersey:jersey-core:jar</include>
@@ -294,6 +295,8 @@
 				<include>j2ssh:j2ssh-common</include>
                 <include>org.apache.httpcomponents:httpcore:jar:4.1</include>
                 <include>org.apache.httpcomponents:httpclient:jar:4.1</include>
+                <include>de.odysseus.staxon:staxon:jar:1.2</include>
+                <include>de.odysseus.staxon:staxon-jackson:jar:1.2</include>
             </includes>
         </dependencySet>
         <dependencySet>

Modified: airavata/trunk/modules/distribution/airavata-server/src/main/resources/conf/axis2.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/distribution/airavata-server/src/main/resources/conf/axis2.xml?rev=1513550&r1=1513549&r2=1513550&view=diff
==============================================================================
--- airavata/trunk/modules/distribution/airavata-server/src/main/resources/conf/axis2.xml
(original)
+++ airavata/trunk/modules/distribution/airavata-server/src/main/resources/conf/axis2.xml
Tue Aug 13 15:28:20 2013
@@ -170,6 +170,8 @@
             class="org.apache.axis2.transport.http.SOAPMessageFormatter" />
         <messageFormatter contentType="application/soap+xml"
             class="org.apache.axis2.transport.http.SOAPMessageFormatter" />
+        <messageFormatter contentType="application/json"
+                          class="org.apache.airavata.json.StaxonJSONFormatter"/>
     </messageFormatters>
 
     <!-- ================================================= -->
@@ -186,6 +188,8 @@
             class="org.apache.axis2.builder.XFormURLEncodedBuilder" />
         <messageBuilder contentType="multipart/form-data"
             class="org.apache.axis2.builder.MultipartFormDataBuilder" />
+        <messageBuilder contentType="application/json"
+                        class="org.apache.airavata.json.StaxonJSONBuilder"/>
     </messageBuilders>
 
     <!-- ================================================= -->



Mime
View raw message