axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dee...@apache.org
Subject svn commit: r219156 - in /webservices/axis/trunk/java/modules/samples: maven.xml project.xml src/sample/groovy/ src/sample/groovy/GroovyRcv.groovy src/sample/groovy/GroovyReceiver.java src/sample/groovy/META-INF/ src/sample/groovy/META-INF/service.xml
Date Fri, 15 Jul 2005 05:56:29 GMT
Author: deepal
Date: Thu Jul 14 22:56:26 2005
New Revision: 219156

URL: http://svn.apache.org/viewcvs?rev=219156&view=rev
Log:
To proof that Axis2 can support scripting language; we have come up with groovy service. The
service includes custom messageReceiver and service implementation class in Groovy. The web
service implementation done by Thyaparan , Tharshitha , Sahan. I did not write a client to
invoke the service yet and I will do that soon

Added:
    webservices/axis/trunk/java/modules/samples/src/sample/groovy/
    webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyRcv.groovy
    webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyReceiver.java
    webservices/axis/trunk/java/modules/samples/src/sample/groovy/META-INF/
    webservices/axis/trunk/java/modules/samples/src/sample/groovy/META-INF/service.xml
Modified:
    webservices/axis/trunk/java/modules/samples/maven.xml
    webservices/axis/trunk/java/modules/samples/project.xml

Modified: webservices/axis/trunk/java/modules/samples/maven.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/maven.xml?rev=219156&r1=219155&r2=219156&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/maven.xml (original)
+++ webservices/axis/trunk/java/modules/samples/maven.xml Thu Jul 14 22:56:26 2005
@@ -59,6 +59,7 @@
         <attainGoal name="googleSpellcheck"/>
         <attainGoal name="version"/>
         <attainGoal name="mtomSample"/>
+         <attainGoal name="groovy"/>
     </goal>
 
     <!-- ================================================================ -->
@@ -156,6 +157,26 @@
             </fileset>
         </jar>
     </goal>
+
+
+     <!-- ================================================================ -->
+    <!--- Groovy Service Sample -->
+    <!-- ================================================================ -->
+
+    <goal name="groovy">
+        <ant:copy file="./src/sample/groovy/GroovyRcv.groovy" tofile="target/classes/sample/groovy/GroovyRcv.groovy"/>
+        <mkdir dir="target/classes/sample/groovy/lib"/>
+        <ant:copy file="${maven.repo.local}/groovy/jars/groovy-all-1.0-jsr-01.jar" tofile="target/classes/sample/groovy/lib/groovy-all-1.0-jsr-01.jar"/>
+
+         <jar destfile="${samples.dir}/groovyService.aar">
+            <fileset dir="target/classes/sample/groovy">
+            </fileset>
+         </jar>
+    </goal>
+
+
+
+
     <!-- ================================================================ -->
     <!--- Google Search Sample -->
     <!-- ================================================================ -->

Modified: webservices/axis/trunk/java/modules/samples/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/project.xml?rev=219156&r1=219155&r2=219156&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/project.xml (original)
+++ webservices/axis/trunk/java/modules/samples/project.xml Thu Jul 14 22:56:26 2005
@@ -71,6 +71,17 @@
             </properties>
             <url>http://dist.codehaus.org/stax/jars/</url>
         </dependency>
+
+       <dependency>
+            <groupId>groovy</groupId>
+            <artifactId>groovy-all</artifactId>
+            <version>1.0-jsr-01</version>
+            <properties>
+                <module>true</module>
+            </properties>
+            <url>http://dist.codehaus.org/groovy/jars/</url>
+        </dependency>
+
         <dependency>
             <groupId>commons-httpclient</groupId>
             <artifactId>commons-httpclient</artifactId>

Added: webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyRcv.groovy
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyRcv.groovy?rev=219156&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyRcv.groovy (added)
+++ webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyRcv.groovy Thu Jul
14 22:56:26 2005
@@ -0,0 +1,63 @@
+
+import java.io.File;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.apache.xpath.XPathAPI;
+import groovy.xml.*
+import java.io.StringWriter;
+import javax.xml.parsers.DocumentBuilder;
+
+class GroovyRcv{
+
+	//public static void main(args){
+   //	  println "hi"
+
+	Object parseXML(arg){
+
+	 addNodeValues = []
+	 nameNodeValues = []
+	 countEmp = -1
+
+	 factory = DocumentBuilderFactory.newInstance()
+	 builder = factory.newDocumentBuilder()
+	 doc = builder.parse(arg)
+	 //println doc
+	 detNodes = XPathAPI.selectNodeList(doc,"ADDRESS/DET")
+	 for(detNodeIndex in 0..(detNodes.getLength()-1)) {
+	 nameNodes = XPathAPI.selectNodeList(detNodes.item(detNodeIndex),"NAME")
+
+	 for(nameNodeIndex in 0..(nameNodes.getLength()-1)) {
+	 nameNodeValue = nameNodes.item( nameNodeIndex ).getFirstChild()
+	 nameNodeValues += [nameNodeValue]
+	 }
+
+	 addNodes = XPathAPI.selectNodeList(detNodes.item(detNodeIndex),"ADD")
+	 for(addNodeIndex in 0..(addNodes.getLength()-1)) {
+	 addNodeValue = addNodes.item(addNodeIndex).getFirstChild()
+	 addNodeValues += [addNodeValue]
+	 }
+	 countEmp++
+	 }//for
+
+	writer = new StringWriter()
+    xmlBuilder = new MarkupBuilder(writer)
+	xmlBuilder.person(){
+	 	for(x in 0..countEmp){
+	 	employee(){
+	 	name(nameNodeValues[x])
+	 	address(addNodeValues[x])
+	 	tdate(new java.util.Date())
+	 	}
+	  }
+	 }//person
+
+	 //new File("Output.xml").withPrintWriter{ pwriter |
+     //pwriter.println writer.toString()}
+
+    //ProcessedDoc = builder.parse(new File("Output.xml"))
+    //ProcessedDoc = builder.parse(writer)
+   return writer
+   //	return ProcessedDoc
+
+  }//mtd
+}//class
+

Added: webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyReceiver.java?rev=219156&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyReceiver.java (added)
+++ webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyReceiver.java Thu
Jul 14 22:56:26 2005
@@ -0,0 +1,113 @@
+package sample.groovy;
+
+import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver;
+import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.engine.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.ServiceDescription;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.OperationDescription;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.soap.SOAPEnvelope;
+import org.codehaus.groovy.control.CompilationFailedException;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.io.ByteArrayInputStream;
+
+import groovy.lang.GroovyObject;
+import groovy.lang.GroovyClassLoader;
+
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.
+*
+*
+*/
+
+/**
+ * Author : Deepal Jayasinghe
+ * Date: Jul 14, 2005
+ * Time: 3:13:03 PM
+ */
+public class GroovyReceiver  extends AbstractInOutSyncMessageReceiver
+        implements MessageReceiver{
+
+    public void invokeBusinessLogic(MessageContext inMessage, MessageContext outMessage)
throws AxisFault {
+        ServiceDescription service =
+                inMessage.getOperationContext().getServiceContext().getServiceConfig();
+        Parameter implInfoParam = service.getParameter("ServiceClass");
+        if (implInfoParam==null){
+            throw new AxisFault("Service class not specified!");
+        }
+        InputStream groovyFileStream = this.getClass().getResourceAsStream(implInfoParam.getValue().toString());
+
+        //look at the method name. if available this should be a groovy method
+        OperationDescription op = inMessage.getOperationContext().getAxisOperation();
+        if (op == null) {
+            throw new AxisFault("Operation is not located");
+        }
+        String methodName = op.getName().getLocalPart();
+        OMElement firstChild = inMessage.getEnvelope();
+        inMessage.getEnvelope().build();
+        try {
+            StringWriter writer = new StringWriter();
+            firstChild.build();
+            firstChild.serializeWithCache(new OMOutputImpl(XMLOutputFactory.newInstance().createXMLStreamWriter(writer)));
+            writer.flush();
+            String value = writer.toString();
+            System.out.println("In Coming Message: " + value);
+            if (value !=null) {
+                try {
+                    InputStream in = new ByteArrayInputStream(value.getBytes());
+                    GroovyClassLoader loader = new GroovyClassLoader();
+                    Class groovyClass = loader.parseClass(groovyFileStream);
+                    GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
+                    Object[] arg = {in};
+                    Object obj =groovyObject.invokeMethod(methodName, arg );
+                    if (obj==null){
+                        throw new AxisFault("No answer recieved from groovy side!!!!");
+                    }
+
+                    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
+                    SOAPEnvelope envelope = fac.getDefaultEnvelope();
+
+                    OMNamespace ns = fac.createOMNamespace("http://soapenc/", "res");
+                    OMElement responseElement = fac.createOMElement(methodName + "Response",
ns);
+                    String outMessageString =   obj.toString();
+                    System.out.println("outMessageString = " + outMessageString);
+                    responseElement.setText(outMessageString);
+                    envelope.getBody().addChild(responseElement);
+                    outMessage.setEnvelope(envelope);
+                } catch (CompilationFailedException e) {
+                    throw new AxisFault("Groovy compilation error!",e);
+                } catch (InstantiationException e) {
+                    throw new AxisFault("Groovy instantiation problem!",e);
+                } catch (IllegalAccessException e) {
+                    throw new AxisFault("Groovy illegal access!",e);
+                }
+            }
+        } catch (XMLStreamException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
+
+    }
+
+}

Added: webservices/axis/trunk/java/modules/samples/src/sample/groovy/META-INF/service.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/groovy/META-INF/service.xml?rev=219156&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/groovy/META-INF/service.xml (added)
+++ webservices/axis/trunk/java/modules/samples/src/sample/groovy/META-INF/service.xml Thu
Jul 14 22:56:26 2005
@@ -0,0 +1,12 @@
+<service name="GroovyService">
+    <description>
+        This is Groovy service , what this really does is take the incoming SOAP message
+        and hand that over to Groovy class and which process the message and return a SOAP
+        message back to MessageReceiver
+    </description>
+    <parameter name="ServiceClass" locked="xsd:false">GroovyRcv.groovy</parameter>
+
+    <operation name="echo">
+        <messageReceiver class="sample.groovy.GroovyReceiver"/>
+    </operation>
+</service>
\ No newline at end of file



Mime
View raw message