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 ch...@apache.org on 2005/09/23 19:42:44 UTC

svn commit: r291171 - in /webservices/axis2/trunk/java/modules/samples: ./ script/SGCCalculator/ script/SGCCalculator/images/ src/sample/sgccalculator/ src/sample/sgccalculator/META-INF/ xdocs/SGCCalculator/ xdocs/SGCCalculator/images/

Author: chamikara
Date: Fri Sep 23 10:41:38 2005
New Revision: 291171

URL: http://svn.apache.org/viewcvs?rev=291171&view=rev
Log:
A sample application to demonstrate the power of ServiceGroupContext (SGCCalculator).
(please read the SGCCalculator/readme.html)

Added:
    webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/
    webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/
    webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image1.JPG   (with props)
    webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image2.JPG   (with props)
    webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image3.JPG   (with props)
    webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image4.JPG   (with props)
    webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/readme.html
    webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/run.bat
    webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/run.sh
    webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/
    webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/AddService.java
    webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/CalcClient.java
    webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/Constants.java
    webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/META-INF/
    webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/META-INF/services.xml
    webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/MultiplyService.java
    webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/SubstractService.java
    webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/
    webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/
    webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image1.JPG   (with props)
    webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image2.JPG   (with props)
    webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image3.JPG   (with props)
    webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image4.JPG   (with props)
    webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/readme.html
Modified:
    webservices/axis2/trunk/java/modules/samples/maven.xml

Modified: webservices/axis2/trunk/java/modules/samples/maven.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/maven.xml?rev=291171&r1=291170&r2=291171&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/samples/maven.xml Fri Sep 23 10:41:38 2005
@@ -38,6 +38,7 @@
         <attainGoal name="mtomSample"/>
         <attainGoal name="groovy"/>
         <attainGoal name="securitySample"/>
+	  <attainGoal name="sgccalculator"/>
     </goal>
 
     <!-- ================================================================ -->
@@ -296,6 +297,32 @@
 
 	<delete dir="target/security/"/>
 
+    </goal>
+
+    <!-- ================================================================ -->
+    <!--- ServiceGroupContext Calculator Sample -->
+    <!-- ================================================================ -->
+    <goal name="sgccalculator">
+        <mkdir dir="target/samples"/>
+        <mkdir dir="${samples.dir}/SGCCalculator"/>
+        <mkdir dir="${samples.dir}/SGCCalculator/src"/>
+        <ant:copy todir="${samples.dir}/SGCCalculator/src">
+            <ant:fileset dir="src">
+                <ant:include name="sample/sgccalculator/**"/>
+            </ant:fileset>
+        </ant:copy>
+        <jar destfile="${samples.dir}/SGCCalculator/SGCCalculator.jar">
+            <fileset dir="target/classes">
+                <include name="sample/sgccalculator/**"/>
+            </fileset>
+            <fileset dir="src/sample/sgccalculator/">
+                <include name="META-INF/**"/>
+            </fileset>
+        </jar>
+        <copy file="${samples.dir}/SGCCalculator/SGCCalculator.jar"
+            tofile="target/toWar/services/SGCCalculator.aar"/>
+	  <copy toDir="${samples.dir}/SGCCalculator"
+            file="script/SGCCalculator/run.bat"/>
     </goal>
 
     <preGoal name="itest:compile">

Added: webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image1.JPG
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image1.JPG?rev=291171&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image1.JPG
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image2.JPG
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image2.JPG?rev=291171&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image2.JPG
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image3.JPG
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image3.JPG?rev=291171&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image3.JPG
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image4.JPG
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image4.JPG?rev=291171&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/images/image4.JPG
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/readme.html
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/readme.html?rev=291171&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/readme.html (added)
+++ webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/readme.html Fri Sep 23 10:41:38 2005
@@ -0,0 +1,86 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<HTML>
+<HEAD>
+	<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
+	<TITLE></TITLE>
+	<META NAME="GENERATOR" CONTENT="OpenOffice.org 1.1.4  (Win32)">
+	<META NAME="AUTHOR" CONTENT="Chamikara Jayalath">
+	<META NAME="CREATED" CONTENT="20050923;21203268">
+	<META NAME="CHANGEDBY" CONTENT="Chamikara Jayalath">
+	<META NAME="CHANGED" CONTENT="20050923;22064610">
+</HEAD>
+<BODY LANG="en-US" DIR="LTR">
+<H2><U><B>Sample application to demonstrate the functionality of
+service groups</B></U></H2>
+<P>Service Groups are a brand new concept introduced by Axis2. With
+Service Groups, users can group several services together. This
+concept gives two main advantages to users.</P>
+<OL>
+	<LI><P>Several related sevices can be easily managed and deployed.</P>
+	<LI><P>Can share information between different services of the same
+	Servie Group at run time.</P>
+</OL>
+<P>This sample application demonstrate how you can create a service
+group and how you can use the functionalities offered by axis2 to
+share information between services of the same group at runtime.</P>
+<P><BR><BR>
+</P>
+<P><U>The idea</U></P>
+<P STYLE="text-decoration: none">The ides behind the sample is pretty
+simple. We have developed a Calculator service group with three
+services AddService, SubstractService and MultiplyService. Each
+service has two operations. For e.g. AddServices has a 'add'
+operation and a 'addPrevious' operation.  
+</P>
+<P STYLE="text-decoration: none">The 'add' operation is used to add
+two integers and produce a result. When a operation is run the result
+will be saved in the current ServiceGroupContext which is the Context
+that has to be used to share information between services of the same
+service group.</P>
+<P STYLE="text-decoration: none">When the addPrevious operation is
+run (which takes a single integer as the parameter) the saved value
+of the last operation will be added to the integer valus that comes
+as a parameter.</P>
+<P STYLE="text-decoration: none">You can even call operations of the
+other two services. These services can also use the value saved from
+the previous operation.</P>
+<P STYLE="text-decoration: none">You can use the client class
+provided to run this in a interactive manner.</P>
+<P><U>How to run the sample</U></P>
+<P>Please run axis2 and deploy the provided Calculator.aar service by
+simply droping it to the Axis2_webapp/WEB-INF/services directory (see
+axis user guide for more details).</P>
+<P>Run the run.bat file.</P>
+<P>You will see the following screen.</P>
+<P><BR><BR>
+</P>
+<P><IMG SRC="images/image1.JPG" NAME="Graphic1" ALIGN=LEFT WIDTH=701 HEIGHT=168 BORDER=0><BR CLEAR=LEFT><BR><BR>
+</P>
+<P>Select 'n' to start a new round.</P>
+<P><BR><BR>
+</P>
+<P><IMG SRC="images/image2.JPG" NAME="Graphic2" ALIGN=LEFT WIDTH=701 HEIGHT=211 BORDER=0><BR CLEAR=LEFT><BR><BR>
+</P>
+<P>Now select the service. + for AddService, - for SubstractService,
+* for MultiplyService. And press enter. 
+</P>
+<P>Enter the two parameters.</P>
+<P>You will see the result.</P>
+<P><BR><BR>
+</P>
+<P><IMG SRC="images/image3.JPG" NAME="Graphic3" ALIGN=LEFT WIDTH=701 HEIGHT=231 BORDER=0><BR CLEAR=LEFT><BR><BR>
+</P>
+<P>Now select the option 'c' to continue the round. Select the
+operation. You have to give a single parameter and press enter.</P>
+<P>The result will be generated using the entered valus and the
+result of the previous operation (which is obtained from the
+ServiceGroupContext).</P>
+<P><BR><BR>
+</P>
+<P><IMG SRC="images/image4.JPG" NAME="Graphic4" ALIGN=LEFT WIDTH=701 HEIGHT=307 BORDER=0><BR CLEAR=LEFT><BR><BR>
+</P>
+<P>You can continue this interactively any number of times.</P>
+<P><BR><BR>
+</P>
+</BODY>
+</HTML>
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/run.bat
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/run.bat?rev=291171&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/run.bat (added)
+++ webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/run.bat Fri Sep 23 10:41:38 2005
@@ -0,0 +1,40 @@
+@echo off
+rem ---------------------------------------------------------------------------
+rem Start script for running the ServiceGroupContext Calculator
+rem
+rem ---------------------------------------------------------------------------
+
+rem store the current directory
+set CURRENT_DIR=%cd%
+
+rem check the AXIS_HOME environment variable
+if not "%AXIS_HOME%" == "" goto gotHome
+
+rem guess the home. Jump two directories up and take that as the home
+cd ..
+cd ..
+set AXIS_HOME=%cd%
+
+echo using Axis Home %AXIS_HOME%
+
+
+:gotHome
+if EXIST "%AXIS_HOME%\lib\axis2*.jar" goto okHome
+echo The AXIS_HOME environment variable seems not to point to the correct loaction!
+echo This environment variable is needed to run this program
+pause
+exit
+
+:okHome
+cd %CURRENT_DIR%
+
+setlocal EnableDelayedExpansion
+rem loop through the libs and add them to the class path
+set AXIS2_CLASS_PATH=%AXIS_HOME%
+FOR %%c in (%AXIS_HOME%\lib\*.jar) DO set AXIS2_CLASS_PATH=!AXIS2_CLASS_PATH!;%%c
+
+set AXIS2_CLASS_PATH=%AXIS2_CLASS_PATH%;"%CURRENT_DIR%\SGCCalculator.jar"
+
+java -cp %AXIS2_CLASS_PATH% sample.sgccalculator.CalcClient
+endlocal
+:end
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/run.sh
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/run.sh?rev=291171&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/run.sh (added)
+++ webservices/axis2/trunk/java/modules/samples/script/SGCCalculator/run.sh Fri Sep 23 10:41:38 2005
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+export AXIS2_HOME=../..
+AXIS2_CLASSPATH=$AXIS2_CLASSPATH:SGCCalculator.jar
+for f in $AXIS2_HOME/lib/*.jar
+do
+  AXIS2_CLASSPATH=$AXIS2_CLASSPATH:$f
+done
+export AXIS2_CLASSPATH
+echo classpath: $AXIS2_CLASSPATH
+
+java -classpath $AXIS2_CLASSPATH sample.sgccalculator.CalcClient &
+

Added: webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/AddService.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/AddService.java?rev=291171&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/AddService.java (added)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/AddService.java Fri Sep 23 10:41:38 2005
@@ -0,0 +1,105 @@
+/*
+ * 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.
+ */
+package sample.sgccalculator;
+
+import java.util.Iterator;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+
+public class AddService {
+
+	MessageContext msgContext = null;
+	
+	public void init (MessageContext msgContext) {
+		this.msgContext = msgContext;
+	}
+	
+	public OMElement add (OMElement elem) {		
+		Iterator iter = elem.getChildElements();
+		String param1Str = ((OMElement) iter.next()).getText();
+		String param2Str = ((OMElement) iter.next()).getText();
+		
+		int param1 = Integer.parseInt(param1Str);
+		int param2 = Integer.parseInt(param2Str);
+		int result = param1 + param2;
+		
+		if (msgContext!=null)
+			System.out.println ("ServiceGroupContextID:" + msgContext.getServiceGroupContextId());
+		else
+			System.out.println ("Message Context is null");
+		
+		OMFactory fac = OMAbstractFactory.getOMFactory();
+		OMNamespace namespace = fac.createOMNamespace("http://axis2/test/namespace1","ns1");
+		
+		OMElement resultElem = fac.createOMElement("result",namespace);
+		resultElem.setText(Integer.toString(result ));
+		
+		msgContext.getServiceGroupContext().setProperty(Constants.CALCULATOR_PREVIOUS_KEY,Integer.toString(result));
+		return resultElem;
+	}
+	
+	public OMElement addPrevious (OMElement elem) {
+		Iterator iter = elem.getChildElements();
+		String paramStr = ((OMElement) iter.next()).getText();
+		
+		int param = Integer.parseInt(paramStr);
+
+		if (msgContext==null){
+			System.out.println ("message context is null");
+			return null;
+		}
+		
+		ServiceGroupContext sgc = msgContext.getServiceGroupContext();
+		if (sgc==null){
+			System.out.println ("message context is null");
+			return null;
+		}
+		
+		String previousStr = (String) sgc.getProperty(Constants.CALCULATOR_PREVIOUS_KEY);
+		if (previousStr==null) {
+			System.out.println ("Previous is null");
+			return null;
+		}
+		
+		int previous = Integer.parseInt(previousStr);
+		
+		int result = previous + param;
+		
+		if (msgContext!=null)
+			System.out.println ("ServiceGroupContextID:" + msgContext.getServiceGroupContextId());
+		else
+			System.out.println ("Message Context is null");
+		
+		OMFactory fac = OMAbstractFactory.getOMFactory();
+		OMNamespace namespace = fac.createOMNamespace("http://axis2/test/namespace1","ns1");
+		
+		OMElement resultElem = fac.createOMElement("result",namespace);
+		resultElem.setText(Integer.toString(result ));
+		
+		msgContext.getServiceGroupContext().setProperty(Constants.CALCULATOR_PREVIOUS_KEY,Integer.toString(result));
+		return resultElem;
+	}
+}

Added: webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/CalcClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/CalcClient.java?rev=291171&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/CalcClient.java (added)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/CalcClient.java Fri Sep 23 10:41:38 2005
@@ -0,0 +1,219 @@
+/*
+ * 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.
+ */
+package sample.sgccalculator;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.clientapi.Call;
+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.soap.SOAPEnvelope;
+import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.soap.SOAPHeaderBlock;
+import org.apache.xml.serializer.ToStream;
+
+public class CalcClient {
+
+	final static String addService = "http://localhost:8080/axis2/services/AddService";
+
+	final static String substractService = "http://localhost:8080/axis2/services/SubstractService";
+
+	final static String multiplyService = "http://localhost:8080/axis2/services/MultiplyService";
+
+	public static void main(String[] args) throws AxisFault,IOException {
+
+		System.out.println ("\nTHIS IS A SAMPLE APPLICATION TO DEMONSTRATE THE FUNCTIONALITY OF SERVICE GROUPS");
+		System.out.println ("===============================================================================");
+		Call call = new Call();
+		call.setTransportInfo(Constants.TRANSPORT_HTTP,
+				Constants.TRANSPORT_HTTP, false);
+		
+		
+		boolean exit = false;
+		String serviceGroupContextId = null;
+		while (!exit) {
+			BufferedReader reader = new BufferedReader (new InputStreamReader (System.in));
+
+			System.out.print ("\n\nNew round (n) /continue round (c).../exit (e)");
+			String option = reader.readLine();
+			if ("e".equalsIgnoreCase(option)){
+				System.out.println ("Exiting calculator...");
+				return;
+			}
+			
+			if (!"n".equalsIgnoreCase(option) && !"c".equalsIgnoreCase(option)){
+				System.out.println ("Error: Invalid option");
+				continue;
+			}
+			
+			System.out.print ("Please Select the service ( '+' / '-' / '*' )....");
+			String operation = reader.readLine();
+			if (!"+".equalsIgnoreCase(operation) && !"-".equalsIgnoreCase(operation) && !"*".equalsIgnoreCase(operation)){
+				System.out.println ("Error: Invalid option");
+				continue;
+			}
+			
+			if ("+".equals(operation))
+				call.setTo(new EndpointReference (addService));
+			else if ("-".equals(operation))
+				call.setTo(new EndpointReference (substractService));
+			else if ("*".equals(operation))
+				call.setTo(new EndpointReference (multiplyService));
+			
+			if ("n".equalsIgnoreCase(option)){
+				System.out.print ("Enter parameter 1...");
+				String param1Str = reader.readLine();
+				System.out.print ("Enter parameter 2...");
+				String param2Str = reader.readLine();
+				int param1 = Integer.parseInt(param1Str);
+				int param2 = Integer.parseInt(param2Str);
+				
+				String opStr = null;
+				if ("+".equals(operation)){
+					opStr = "add";
+				}else if ("-".equals(operation)){
+					opStr = "substract";
+				}else if ("*".equals(operation)){
+					opStr = "multiply";
+				}
+				System.out.println("Invoking..."); 
+				SOAPEnvelope result = call.invokeBlocking(opStr,getRequestEnvelope(opStr,param1,param2,
+						serviceGroupContextId));
+				printResult(result);
+				
+				if (serviceGroupContextId==null)
+					serviceGroupContextId = getServiceGroupContextId(result);
+				
+				
+			}else if ("c".equalsIgnoreCase(option)){
+				if (serviceGroupContextId==null)
+				{
+					System.out.println ("Error: First operation must be a New one. Please select 'n'");
+					continue;
+				}
+				
+				System.out.print ("Enter parameter...");
+				String paramStr = reader.readLine();
+				int param = Integer.parseInt(paramStr);
+				String opStr = null;
+				if ("+".equals(operation)){
+					opStr = "addPrevious";
+				}else if ("-".equals(operation)){
+					opStr = "substractPrevious";
+				}else if ("*".equals(operation)){
+					opStr = "multiplyPrevious";
+				}
+				
+				System.out.println("Invoking..."); 
+				SOAPEnvelope result = call.invokeBlocking(opStr,getPreviousRequestEnvelope(opStr,param,
+						serviceGroupContextId));
+				printResult(result);
+				
+			}
+			
+		}
+	}
+	
+	public static void printResult (SOAPEnvelope result) {
+		try {
+			XMLStreamWriter writer = XMLOutputFactory.newInstance()
+					.createXMLStreamWriter(System.out);
+			if (result != null){
+				OMElement resultOM = result.getBody().getFirstChildWithName(new QName ("result"));
+				System.out.println ("Result is:" + resultOM.getText());
+			}else
+				System.out.println("Result is null");
+		} catch (XMLStreamException e) {
+			e.printStackTrace();
+		} catch (FactoryConfigurationError e) {
+			e.printStackTrace();
+		}
+	}
+
+	public static SOAPEnvelope getRequestEnvelope(String operationName,
+			int param1, int param2, String groupContextId) {
+		SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
+		SOAPEnvelope envelope = fac.getDefaultEnvelope();
+		OMNamespace namespace = fac.createOMNamespace(
+				"http://axis2/test/namespace1", "ns1");
+
+		OMElement params = fac.createOMElement(operationName, namespace);
+		OMElement param1OM = fac.createOMElement("param1", namespace);
+		OMElement param2OM = fac.createOMElement("param2", namespace);
+		param1OM.setText(Integer.toString(param1));
+		param2OM.setText(Integer.toString(param2));
+		params.addChild(param1OM);
+		params.addChild(param2OM);
+		envelope.getBody().setFirstChild(params);
+
+		if (groupContextId != null) {
+			OMNamespace axis2Namespace = fac.createOMNamespace(
+					Constants.AXIS2_NAMESPACE_URI,
+					Constants.AXIS2_NAMESPACE_PREFIX);
+			SOAPHeaderBlock soapHeaderBlock = envelope.getHeader()
+					.addHeaderBlock(Constants.SERVICE_GROUP_ID, axis2Namespace);
+			soapHeaderBlock.setText(groupContextId);
+		}
+
+		return envelope;
+	}
+	
+	public static SOAPEnvelope getPreviousRequestEnvelope(String operationName,
+			int param, String groupContextId) {
+		SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
+		SOAPEnvelope envelope = fac.getDefaultEnvelope();
+		OMNamespace namespace = fac.createOMNamespace(
+				"http://axis2/test/namespace1", "ns1");
+
+		OMElement params = fac.createOMElement(operationName, namespace);
+		OMElement paramOM = fac.createOMElement("param", namespace);
+		paramOM.setText(Integer.toString(param));
+		params.addChild(paramOM);
+		envelope.getBody().setFirstChild(params);
+
+		if (groupContextId != null) {
+			OMNamespace axis2Namespace = fac.createOMNamespace(
+					Constants.AXIS2_NAMESPACE_URI,
+					Constants.AXIS2_NAMESPACE_PREFIX);
+			SOAPHeaderBlock soapHeaderBlock = envelope.getHeader()
+					.addHeaderBlock(Constants.SERVICE_GROUP_ID, axis2Namespace);
+			soapHeaderBlock.setText(groupContextId);
+		}		
+		
+		return envelope;
+	}
+	
+	public static String getServiceGroupContextId (SOAPEnvelope resultEnvelope) {
+		String serviceGroupContextId = resultEnvelope.getHeader()
+		.getFirstChildWithName(new QName("ReplyTo"))
+		.getFirstChildWithName(new QName("ReferenceParameters"))
+		.getFirstChildWithName(new QName("ServiceGroupId")).getText();
+		return serviceGroupContextId;
+	}
+}
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/Constants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/Constants.java?rev=291171&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/Constants.java (added)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/Constants.java Fri Sep 23 10:41:38 2005
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+package sample.sgccalculator;
+
+public interface Constants {
+
+	String CALCULATOR_PREVIOUS_KEY = "CalcPreviousKey";
+}

Added: webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/META-INF/services.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/META-INF/services.xml?rev=291171&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/META-INF/services.xml (added)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/META-INF/services.xml Fri Sep 23 10:41:38 2005
@@ -0,0 +1,45 @@
+<serviceGroup>
+
+  <service name="AddService">
+
+    <parameter name="ServiceClass" locked="xsd:false">sample.sgccalculator.AddService</parameter>
+
+    <operation name="add" > 
+          <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />
+    </operation>
+    
+    <operation name="addPrevious" > 
+          <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />
+    </operation>
+    
+  </service>
+  
+  <service name="MultiplyService">
+  
+    <parameter name="ServiceClass" locked="xsd:false">sample.sgccalculator.MultiplyService</parameter>
+
+    <operation name="multiply" > 
+          <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />
+    </operation>
+    
+    <operation name="multiplyPrevious" >
+          <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />
+    </operation>
+     
+  </service>
+ 
+   <service name="SubstractService">
+   
+   <parameter name="ServiceClass" locked="xsd:false">sample.sgccalculator.SubstractService</parameter>
+
+    <operation name="substract" >
+          <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />
+    </operation>
+     
+    <operation name="substractPrevious" > 
+          <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />
+    </operation>
+    
+  </service> 
+  
+</serviceGroup>
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/MultiplyService.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/MultiplyService.java?rev=291171&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/MultiplyService.java (added)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/MultiplyService.java Fri Sep 23 10:41:38 2005
@@ -0,0 +1,105 @@
+/*
+ * 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.
+ */
+package sample.sgccalculator;
+
+import java.util.Iterator;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+
+public class MultiplyService {
+
+	MessageContext msgContext = null;
+	
+	public void init (MessageContext msgContext) {
+		this.msgContext = msgContext;
+	}
+	
+	public OMElement multiply (OMElement elem) {
+		Iterator iter = elem.getChildElements();
+		String param1Str = ((OMElement) iter.next()).getText();
+		String param2Str = ((OMElement) iter.next()).getText();
+		
+		int param1 = Integer.parseInt(param1Str);
+		int param2 = Integer.parseInt(param2Str);
+		int result = param1 * param2;
+		
+		if (msgContext!=null)
+			System.out.println ("ServiceGroupContextID:" + msgContext.getServiceGroupContextId());
+		else
+			System.out.println ("Message Context is null");
+		
+		OMFactory fac = OMAbstractFactory.getOMFactory();
+		OMNamespace namespace = fac.createOMNamespace("http://axis2/test/namespace1","ns1");
+		
+		OMElement resultElem = fac.createOMElement("result",namespace);
+		resultElem.setText(Integer.toString(result ));
+		
+		msgContext.getServiceGroupContext().setProperty(Constants.CALCULATOR_PREVIOUS_KEY,Integer.toString(result));
+		return resultElem;
+	}
+	
+	public OMElement multiplyPrevious (OMElement elem) {
+		Iterator iter = elem.getChildElements();
+		String paramStr = ((OMElement) iter.next()).getText();
+		
+		int param = Integer.parseInt(paramStr);
+
+		if (msgContext==null){
+			System.out.println ("message context is null");
+			return null;
+		}
+		
+		ServiceGroupContext sgc = msgContext.getServiceGroupContext();
+		if (sgc==null){
+			System.out.println ("message context is null");
+			return null;
+		}
+		
+		String previousStr = (String) sgc.getProperty(Constants.CALCULATOR_PREVIOUS_KEY);
+		if (previousStr==null) {
+			System.out.println ("Previous is null");
+			return null;
+		}
+		
+		int previous = Integer.parseInt(previousStr);
+		
+		int result = previous * param;
+		
+		if (msgContext!=null)
+			System.out.println ("ServiceGroupContextID:" + msgContext.getServiceGroupContextId());
+		else
+			System.out.println ("Message Context is null");
+		
+		OMFactory fac = OMAbstractFactory.getOMFactory();
+		OMNamespace namespace = fac.createOMNamespace("http://axis2/test/namespace1","ns1");
+		
+		OMElement resultElem = fac.createOMElement("result",namespace);
+		resultElem.setText(Integer.toString(result ));
+		
+		msgContext.getServiceGroupContext().setProperty(Constants.CALCULATOR_PREVIOUS_KEY,Integer.toString(result));
+		return resultElem;
+	}
+}

Added: webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/SubstractService.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/SubstractService.java?rev=291171&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/SubstractService.java (added)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/sgccalculator/SubstractService.java Fri Sep 23 10:41:38 2005
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+package sample.sgccalculator;
+
+import java.util.Iterator;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+
+public class SubstractService {
+
+	MessageContext msgContext = null;
+	
+	public void init (MessageContext msgContext) {
+		this.msgContext = msgContext;
+	}
+	
+	public OMElement substract (OMElement elem){
+		Iterator iter = elem.getChildElements();
+		String param1Str = ((OMElement) iter.next()).getText();
+		String param2Str = ((OMElement) iter.next()).getText();
+		
+		int param1 = Integer.parseInt(param1Str);
+		int param2 = Integer.parseInt(param2Str);
+		int result = param1 - param2;
+		
+		if (msgContext!=null)
+			System.out.println ("ServiceGroupContextID:" + msgContext.getServiceGroupContextId());
+		else
+			System.out.println ("Message Context is null");
+		
+		OMFactory fac = OMAbstractFactory.getOMFactory();
+		OMNamespace namespace = fac.createOMNamespace("http://axis2/test/namespace1","ns1");
+		
+		OMElement resultElem = fac.createOMElement("result",namespace);
+		resultElem.setText(Integer.toString(result ));
+		
+		msgContext.getServiceGroupContext().setProperty(Constants.CALCULATOR_PREVIOUS_KEY,Integer.toString(result));
+		return resultElem;
+	}
+	
+	public OMElement substractPrevious (OMElement elem) {
+		Iterator iter = elem.getChildElements();
+		String paramStr = ((OMElement) iter.next()).getText();
+		
+		int param = Integer.parseInt(paramStr);
+
+		if (msgContext==null){
+			System.out.println ("message context is null");
+			return null;
+		}
+		
+		ServiceGroupContext sgc = msgContext.getServiceGroupContext();
+		if (sgc==null){
+			System.out.println ("message context is null");
+			return null;
+		}
+		
+		String previousStr = (String) sgc.getProperty(Constants.CALCULATOR_PREVIOUS_KEY);
+		if (previousStr==null) {
+			System.out.println ("Previous is null");
+			return null;
+		}
+		
+		int previous = Integer.parseInt(previousStr);
+		
+		int result = previous - param;
+		
+		if (msgContext!=null)
+			System.out.println ("ServiceGroupContextID:" + msgContext.getServiceGroupContextId());
+		else
+			System.out.println ("Message Context is null");
+		
+		OMFactory fac = OMAbstractFactory.getOMFactory();
+		OMNamespace namespace = fac.createOMNamespace("http://axis2/test/namespace1","ns1");
+		
+		OMElement resultElem = fac.createOMElement("result",namespace);
+		resultElem.setText(Integer.toString(result ));
+		
+		msgContext.getServiceGroupContext().setProperty(Constants.CALCULATOR_PREVIOUS_KEY,Integer.toString(result));
+		return resultElem;
+	}
+	
+}

Added: webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image1.JPG
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image1.JPG?rev=291171&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image1.JPG
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image2.JPG
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image2.JPG?rev=291171&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image2.JPG
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image3.JPG
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image3.JPG?rev=291171&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image3.JPG
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image4.JPG
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image4.JPG?rev=291171&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/images/image4.JPG
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/readme.html
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/readme.html?rev=291171&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/readme.html (added)
+++ webservices/axis2/trunk/java/modules/samples/xdocs/SGCCalculator/readme.html Fri Sep 23 10:41:38 2005
@@ -0,0 +1,86 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<HTML>
+<HEAD>
+	<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
+	<TITLE></TITLE>
+	<META NAME="GENERATOR" CONTENT="OpenOffice.org 1.1.4  (Win32)">
+	<META NAME="AUTHOR" CONTENT="Chamikara Jayalath">
+	<META NAME="CREATED" CONTENT="20050923;21203268">
+	<META NAME="CHANGEDBY" CONTENT="Chamikara Jayalath">
+	<META NAME="CHANGED" CONTENT="20050923;22064610">
+</HEAD>
+<BODY LANG="en-US" DIR="LTR">
+<H2><U><B>Sample application to demonstrate the functionality of
+service groups</B></U></H2>
+<P>Service Groups are a brand new concept introduced by Axis2. With
+Service Groups, users can group several services together. This
+concept gives two main advantages to users.</P>
+<OL>
+	<LI><P>Several related sevices can be easily managed and deployed.</P>
+	<LI><P>Can share information between different services of the same
+	Servie Group at run time.</P>
+</OL>
+<P>This sample application demonstrate how you can create a service
+group and how you can use the functionalities offered by axis2 to
+share information between services of the same group at runtime.</P>
+<P><BR><BR>
+</P>
+<P><U>The idea</U></P>
+<P STYLE="text-decoration: none">The ides behind the sample is pretty
+simple. We have developed a Calculator service group with three
+services AddService, SubstractService and MultiplyService. Each
+service has two operations. For e.g. AddServices has a 'add'
+operation and a 'addPrevious' operation.  
+</P>
+<P STYLE="text-decoration: none">The 'add' operation is used to add
+two integers and produce a result. When a operation is run the result
+will be saved in the current ServiceGroupContext which is the Context
+that has to be used to share information between services of the same
+service group.</P>
+<P STYLE="text-decoration: none">When the addPrevious operation is
+run (which takes a single integer as the parameter) the saved value
+of the last operation will be added to the integer valus that comes
+as a parameter.</P>
+<P STYLE="text-decoration: none">You can even call operations of the
+other two services. These services can also use the value saved from
+the previous operation.</P>
+<P STYLE="text-decoration: none">You can use the client class
+provided to run this in a interactive manner.</P>
+<P><U>How to run the sample</U></P>
+<P>Please run axis2 and deploy the provided Calculator.aar service by
+simply droping it to the Axis2_webapp/WEB-INF/services directory (see
+axis user guide for more details).</P>
+<P>Run the run.bat file.</P>
+<P>You will see the following screen.</P>
+<P><BR><BR>
+</P>
+<P><IMG SRC="images/image1.JPG" NAME="Graphic1" ALIGN=LEFT WIDTH=701 HEIGHT=168 BORDER=0><BR CLEAR=LEFT><BR><BR>
+</P>
+<P>Select 'n' to start a new round.</P>
+<P><BR><BR>
+</P>
+<P><IMG SRC="images/image2.JPG" NAME="Graphic2" ALIGN=LEFT WIDTH=701 HEIGHT=211 BORDER=0><BR CLEAR=LEFT><BR><BR>
+</P>
+<P>Now select the service. + for AddService, - for SubstractService,
+* for MultiplyService. And press enter. 
+</P>
+<P>Enter the two parameters.</P>
+<P>You will see the result.</P>
+<P><BR><BR>
+</P>
+<P><IMG SRC="images/image3.JPG" NAME="Graphic3" ALIGN=LEFT WIDTH=701 HEIGHT=231 BORDER=0><BR CLEAR=LEFT><BR><BR>
+</P>
+<P>Now select the option 'c' to continue the round. Select the
+operation. You have to give a single parameter and press enter.</P>
+<P>The result will be generated using the entered valus and the
+result of the previous operation (which is obtained from the
+ServiceGroupContext).</P>
+<P><BR><BR>
+</P>
+<P><IMG SRC="images/image4.JPG" NAME="Graphic4" ALIGN=LEFT WIDTH=701 HEIGHT=307 BORDER=0><BR CLEAR=LEFT><BR><BR>
+</P>
+<P>You can continue this interactively any number of times.</P>
+<P><BR><BR>
+</P>
+</BODY>
+</HTML>
\ No newline at end of file