You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by de...@apache.org on 2005/07/15 12:49:26 UTC
svn commit: r219175 - in /webservices/axis/trunk/java/modules/samples:
maven.xml src/sample/groovy/GroovyRcv.groovy
src/sample/groovy/GroovyReceiver.java test/org/apache/axis2/groovy/
test/org/apache/axis2/groovy/GroovyServiceTest.java
Author: deepal
Date: Fri Jul 15 03:49:23 2005
New Revision: 219175
URL: http://svn.apache.org/viewcvs?rev=219175&view=rev
Log:
Wrote a testcase to check the groovy service , which send a request to groovy service and get the response
Added:
webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/groovy/
webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/groovy/GroovyServiceTest.java
Modified:
webservices/axis/trunk/java/modules/samples/maven.xml
webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyRcv.groovy
webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyReceiver.java
Modified: webservices/axis/trunk/java/modules/samples/maven.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/maven.xml?rev=219175&r1=219174&r2=219175&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/maven.xml (original)
+++ webservices/axis/trunk/java/modules/samples/maven.xml Fri Jul 15 03:49:23 2005
@@ -39,6 +39,7 @@
<mkdir dir="target/test-resources/MTOM-enabledRepository"/>
<copy file="test/org/apache/axis2/mtom/MTOM-enabled-axis2.xml"
tofile="target/test-resources/MTOM-enabledRepository/axis2.xml"/>
+ <attainGoal name="groovy"/>
</postGoal>
<postGoal name="test:test">
@@ -47,7 +48,7 @@
</postGoal>
<goal name="create-samples">
- <mkdir dir="target/samples"/>
+<!-- <mkdir dir="target/samples"/>-->
<mkdir dir="${samples.dir}/userguide"/>
<mkdir dir="target/samples/wsdl"/>
<copy todir="target/samples/wsdl">
@@ -59,7 +60,7 @@
<attainGoal name="googleSpellcheck"/>
<attainGoal name="version"/>
<attainGoal name="mtomSample"/>
- <attainGoal name="groovy"/>
+<!-- <attainGoal name="groovy"/>-->
</goal>
<!-- ================================================================ -->
@@ -164,6 +165,7 @@
<!-- ================================================================ -->
<goal name="groovy">
+ <mkdir dir="target/samples"/>
<ant:copy file="./src/sample/groovy/GroovyRcv.groovy" tofile="target/classes/sample/groovy/GroovyRcv.groovy"/>
<mkdir dir="target/classes/sample/groovy/lib"/>
<mkdir dir="target/classes/sample/groovy/sample"/>
@@ -175,6 +177,9 @@
<fileset dir="target/classes/sample/groovy">
</fileset>
</jar>
+ <mkdir dir="target/groovyRepo"/>
+ <mkdir dir="target/groovyRepo/services"/>
+ <ant:copy file="${samples.dir}/groovyService.aar" tofile="target/groovyRepo/services/groovyService.aar"/>
</goal>
Modified: 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=219175&r1=219174&r2=219175&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyRcv.groovy (original)
+++ webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyRcv.groovy Fri Jul 15 03:49:23 2005
@@ -11,7 +11,7 @@
//public static void main(args){
// println "hi"
- Object parseXML(arg){
+ Object echo(arg){
addNodeValues = []
nameNodeValues = []
Modified: 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=219175&r1=219174&r2=219175&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyReceiver.java (original)
+++ webservices/axis/trunk/java/modules/samples/src/sample/groovy/GroovyReceiver.java Fri Jul 15 03:49:23 2005
@@ -10,13 +10,17 @@
import org.apache.axis2.om.OMElement;
import org.apache.axis2.om.OMAbstractFactory;
import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMFactory;
import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
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 javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.ByteArrayInputStream;
@@ -65,7 +69,7 @@
throw new AxisFault("Operation is not located");
}
String methodName = op.getName().getLocalPart();
- OMElement firstChild = inMessage.getEnvelope();
+ OMElement firstChild = (OMElement)inMessage.getEnvelope().getBody().getFirstChild();
inMessage.getEnvelope().build();
try {
StringWriter writer = new StringWriter();
@@ -73,7 +77,6 @@
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());
@@ -92,8 +95,9 @@
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);
+ // System.out.println("outMessageString = " + outMessageString);
+ // responseElement.setText(outMessageString);
+ responseElement.addChild(getpayLoad(outMessageString));
envelope.getBody().addChild(responseElement);
outMessage.setEnvelope(envelope);
} catch (CompilationFailedException e) {
@@ -109,5 +113,16 @@
}
}
+
+ private OMElement getpayLoad(String str) throws XMLStreamException {
+ XMLStreamReader xmlReader= XMLInputFactory.newInstance().createXMLStreamReader(new
+ ByteArrayInputStream(str.getBytes()));
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+
+ StAXOMBuilder staxOMBuilder = new
+ StAXOMBuilder(fac,(XMLStreamReader) xmlReader);
+ return staxOMBuilder.getDocumentElement();
+ }
+
}
Added: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/groovy/GroovyServiceTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/groovy/GroovyServiceTest.java?rev=219175&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/groovy/GroovyServiceTest.java (added)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/groovy/GroovyServiceTest.java Fri Jul 15 03:49:23 2005
@@ -0,0 +1,133 @@
+package org.apache.axis2.groovy;
+
+import junit.framework.TestCase;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.description.ServiceDescription;
+import org.apache.axis2.engine.EchoRawXMLTest;
+import org.apache.axis2.integration.TestingUtils;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.soap.SOAPFactory;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLOutputFactory;
+import java.io.ByteArrayInputStream;
+import java.io.StringWriter;
+
+/*
+* 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 15, 2005
+ * Time: 2:20:48 PM
+ */
+public class GroovyServiceTest extends TestCase {
+
+
+ private EndpointReference targetEPR =
+ new EndpointReference(AddressingConstants.WSA_TO,
+ "http://127.0.0.1:"
+ + (UtilServer.TESTING_PORT)
+ + "/axis/services/GroovyService/echo");
+ private QName serviceName = new QName("GroovyService");
+ private QName operationName = new QName("echo");
+
+
+ public GroovyServiceTest() {
+ super(EchoRawXMLTest.class.getName());
+ }
+
+ public GroovyServiceTest(String testName) {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception {
+ String repository = "target/groovyRepo";
+// String repository = "D:\\Projects\\LSF\\Axis2\\Axis1.0\\modules\\samples\\target\\groovyRepo";
+ UtilServer.start(repository);
+ }
+
+ protected void tearDown() throws Exception {
+ UtilServer.unDeployService(serviceName);
+ UtilServer.stop();
+ }
+
+
+ public void testServiceExsit() throws Exception {
+ ServiceDescription desc = UtilServer.getConfigurationContext().
+ getAxisConfiguration().getService(serviceName);
+ assertNotNull(desc);
+ }
+
+
+ public void testEchoXMLSync() throws Exception {
+ SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
+ //OMElement payload = createPayLoad();
+ OMElement payload = getpayLoad();
+
+ org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call();
+
+ call.setTo(targetEPR);
+ call.setTransportInfo(Constants.TRANSPORT_HTTP,
+ Constants.TRANSPORT_HTTP,
+ false);
+
+ OMElement result = (OMElement) call.invokeBlocking(operationName.getLocalPart(),
+ payload);
+ assertNotNull(result);
+ OMElement person = (OMElement)result.getFirstChild();
+ assertEquals(person.getLocalName(),"person");
+
+ StringWriter writer = new StringWriter();
+ result.build();
+ result.serializeWithCache(new OMOutputImpl(XMLOutputFactory.newInstance().createXMLStreamWriter(writer)));
+ writer.flush();
+ call.close();
+ }
+
+
+
+ private OMElement getpayLoad() throws XMLStreamException {
+ String str= "<ADDRESS><DET><NAME>Ponnampalam Thayaparan</NAME> <OCC>Student</OCC>" +
+ "<ADD>3-2/1,Hudson Road,Colombo-03</ADD><GENDER>Male</GENDER>" +
+ "</DET><DET><NAME>Eranka Samaraweera</NAME><OCC>Student</OCC><ADD>Martara</ADD>" +
+ "<GENDER>Male</GENDER></DET><DET><NAME>Sriskantharaja Ahilan</NAME>" +
+ "<OCC>Student</OCC><ADD>Trincomalee</ADD><GENDER>Male</GENDER>" +
+ "</DET></ADDRESS>";
+ XMLStreamReader xmlReader= XMLInputFactory.newInstance().createXMLStreamReader(new
+ ByteArrayInputStream(str.getBytes()));
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+
+ StAXOMBuilder staxOMBuilder = new
+ StAXOMBuilder(fac,(XMLStreamReader) xmlReader);
+ return staxOMBuilder.getDocumentElement();
+ }
+
+
+}