synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject svn commit: r572289 - in /webservices/synapse/trunk/java/modules/samples: ./ services/LoadbalanceFailoverService/src/samples/services/ src/main/java/samples/userguide/ src/main/java/samples/util/ src/test/java/org/apache/synapse/samples/n2n/
Date Mon, 03 Sep 2007 12:07:15 GMT
Author: ruwan
Date: Mon Sep  3 05:07:14 2007
New Revision: 572289

URL: http://svn.apache.org/viewvc?rev=572289&view=rev
Log:
Fixing SynapseSample_54_Integration to work on the build.

Modified:
    webservices/synapse/trunk/java/modules/samples/pom.xml
    webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService1.java
    webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/LoadbalanceFailoverClient.java
    webservices/synapse/trunk/java/modules/samples/src/main/java/samples/util/SampleAxis2Server.java
    webservices/synapse/trunk/java/modules/samples/src/test/java/org/apache/synapse/samples/n2n/AbstractAutomationTestCase.java
    webservices/synapse/trunk/java/modules/samples/src/test/java/org/apache/synapse/samples/n2n/SynapseSample_54_Integration.java

Modified: webservices/synapse/trunk/java/modules/samples/pom.xml
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/pom.xml?rev=572289&r1=572288&r2=572289&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/samples/pom.xml (original)
+++ webservices/synapse/trunk/java/modules/samples/pom.xml Mon Sep  3 05:07:14 2007
@@ -202,6 +202,48 @@
                                             <fileset dir="${RSQ.dir}"/>
                                         </jar>
 
+                                        <property name="src5"
+                                                  value="services/LoadbalanceFailoverService/src"/>
+                                        <delete dir="${temp.dir}"/>
+                                        <mkdir dir="${temp.dir}"/>
+                                        <mkdir dir="${classes}"/>
+                                        <javac debug="on" destdir="${classes}" fork="true">
+                                            <src path="${src5}"/>
+                                            <classpath refid="maven.compile.classpath"/>
+                                        </javac>
+
+                                        <property name="LBFA1.dir" value="${temp.dir}/LBService1"/>
+                                        <mkdir dir="${LBFA1.dir}"/>
+
+                                        <mkdir dir="${LBFA1.dir}/META-INF"/>
+                                        <copy file="${src5}/../conf/service1/services.xml"
+                                              tofile="${LBFA1.dir}/META-INF/services.xml"/>
+                                        <copy toDir="${LBFA1.dir}">
+                                            <fileset dir="${classes}">
+                                                <include name="**/LBService1.class"/>
+                                            </fileset>
+                                        </copy>
+
+                                        <jar destfile="${services}/LBService1.aar">
+                                            <fileset dir="${LBFA1.dir}"/>
+                                        </jar>
+
+                                        <property name="LBFA2.dir" value="${temp.dir}/LBService2"/>
+                                        <mkdir dir="${LBFA2.dir}"/>
+
+                                        <mkdir dir="${LBFA2.dir}/META-INF"/>
+                                        <copy file="${src5}/../conf/service2/services.xml"
+                                              tofile="${LBFA2.dir}/META-INF/services.xml"/>
+                                        <copy toDir="${LBFA2.dir}">
+                                            <fileset dir="${classes}">
+                                                <include name="**/LBService2.class"/>
+                                            </fileset>
+                                        </copy>
+
+                                        <jar destfile="${services}/LBService2.aar">
+                                            <fileset dir="${LBFA2.dir}"/>
+                                        </jar>
+
                                     </tasks>
                                 </configuration>
                                 <goals>

Modified: webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService1.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService1.java?rev=572289&r1=572288&r2=572289&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService1.java
(original)
+++ webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService1.java
Mon Sep  3 05:07:14 2007
@@ -39,8 +39,13 @@
     public OMElement sampleOperation(OMElement param) {
         param.build();
         param.detach();
-
-        String sName = System.getProperty("server_name");
+        
+        String sName = "";
+        if (System.getProperty("test_mode") != null) {
+            sName = org.apache.axis2.context.MessageContext.getCurrentMessageContext().getTo().getAddress();
+        } else {
+            sName = System.getProperty("server_name");
+        }
         if (sName != null) {
             param.setText("Response from server: " + sName);
         } else {

Modified: webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/LoadbalanceFailoverClient.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/LoadbalanceFailoverClient.java?rev=572289&r1=572288&r2=572289&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/LoadbalanceFailoverClient.java
(original)
+++ webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/LoadbalanceFailoverClient.java
Mon Sep  3 05:07:14 2007
@@ -39,31 +39,35 @@
 
 import javax.xml.namespace.QName;
 import java.util.Random;
+import java.io.File;
 
 public class LoadbalanceFailoverClient {
 
     /**
-     * @param args  0: simple | session
-     *              1: port
-     *              2: iteration
+     * @param args 0: simple | session
+     *             1: port
+     *             2: iteration
      */
     public static void main(String[] args) {
 
         String mode = System.getProperty("mode");
-
-        if (mode != null) {
-            if (mode.equalsIgnoreCase("session")) {
-                new LoadbalanceFailoverClient().sessionfullClient();
-            } else if (mode.equalsIgnoreCase("simple") || mode.equalsIgnoreCase("")) {
+        try {
+            if (mode != null) {
+                if (mode.equalsIgnoreCase("session")) {
+                    new LoadbalanceFailoverClient().sessionfullClient();
+                } else if (mode.equalsIgnoreCase("simple") || mode.equalsIgnoreCase(""))
{
+                    new LoadbalanceFailoverClient().sessionlessClient();
+                }
+            } else {
+                // default is simple client
                 new LoadbalanceFailoverClient().sessionlessClient();
             }
-        } else {
-            // default is simple client
-            new LoadbalanceFailoverClient().sessionlessClient();
+        } catch (AxisFault axisFault) {
+            System.out.println(axisFault.getMessage());
         }
     }
 
-    private void sessionlessClient() {
+    public String sessionlessClient() throws AxisFault {
 
         String synapsePort = "8080";
         int iterations = 100;
@@ -76,7 +80,7 @@
             try {
                 stringToInt(pPort);
                 synapsePort = System.getProperty("port");
-            } catch(NumberFormatException e) {
+            } catch (NumberFormatException e) {
                 // run with default value
             }
         }
@@ -84,10 +88,10 @@
         if (pIterations != null) {
             try {
                 iterations = stringToInt(pIterations);
-                if(iterations != -1) {
+                if (iterations != -1) {
                     infinite = false;
                 }
-            } catch(NumberFormatException e) {
+            } catch (NumberFormatException e) {
                 // run with default values
             }
         }
@@ -101,27 +105,34 @@
 
         options.setAction("sampleOperation");
 
-        try {
-            ConfigurationContext configContext = ConfigurationContextFactory.
+        String repo = System.getProperty("repository");
+        ConfigurationContext configContext;
+        if (repo != null) {
+            configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
+                    repo, repo + File.separator + "conf" + File.separator + "axis2.xml");
+        } else {
+            configContext = ConfigurationContextFactory.
                     createConfigurationContextFromFileSystem("client_repo", null);
-            ServiceClient client = new ServiceClient(configContext, null);
-            options.setTimeOutInMilliSeconds(10000000);
+        }
+        ServiceClient client = new ServiceClient(configContext, null);
+        options.setTimeOutInMilliSeconds(10000000);
 
-            client.setOptions(options);
-            client.engageModule("addressing");
+        client.setOptions(options);
+        client.engageModule("addressing");
 
-            long i = 0;
-            while(i < iterations || infinite) {
-                OMElement responseElement = client.sendReceive(value);
-                String response = responseElement.getText();
+        String testString = "";
 
-                i++;
-                System.out.println("Request: " + i + " ==> " + response);
-            }
+        long i = 0;
+        while (i < iterations || infinite) {
+            OMElement responseElement = client.sendReceive(value);
+            String response = responseElement.getText();
 
-        } catch (AxisFault axisFault) {
-            System.out.println(axisFault.getMessage());
+            i++;
+            System.out.println("Request: " + i + " ==> " + response);
+            testString += (":" + i + ">" + response + ":");
         }
+
+        return testString;
     }
 
     /**
@@ -129,7 +140,7 @@
      * choose one envelope for each iteration and send it to the ESB. ESB should be configured
with
      * session affinity load balancer and the SampleClientInitiatedSession dispatcher. This
will
      * output request number, session number and the server ID for each iteration. So it
can be
-     * observed that one session number always associated with one server ID.       
+     * observed that one session number always associated with one server ID.
      */
     private void sessionfullClient() {
 
@@ -144,7 +155,7 @@
             try {
                 stringToInt(pPort);
                 synapsePort = System.getProperty("port");
-            } catch(NumberFormatException e) {
+            } catch (NumberFormatException e) {
                 // run with default value
             }
         }
@@ -152,10 +163,10 @@
         if (pIterations != null) {
             try {
                 iterations = stringToInt(pIterations);
-                if(iterations != -1) {
+                if (iterations != -1) {
                     infinite = false;
                 }
-            } catch(NumberFormatException e) {
+            } catch (NumberFormatException e) {
                 // run with default values
             }
         }
@@ -180,7 +191,7 @@
 
             int i = 0;
             int sessionNumber = 0;
-            while(i < iterations || infinite) {
+            while (i < iterations || infinite) {
 
                 i++;
 

Modified: webservices/synapse/trunk/java/modules/samples/src/main/java/samples/util/SampleAxis2Server.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/src/main/java/samples/util/SampleAxis2Server.java?rev=572289&r1=572288&r2=572289&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/samples/src/main/java/samples/util/SampleAxis2Server.java
(original)
+++ webservices/synapse/trunk/java/modules/samples/src/main/java/samples/util/SampleAxis2Server.java
Mon Sep  3 05:07:14 2007
@@ -57,7 +57,11 @@
      * @throws Exception
      */
     public static void main(String[] args) throws Exception {
-		String repoLocation = null;
+        startServer(args);
+    }
+
+    public static ListenerManager startServer(String[] args) {
+        String repoLocation = null;
 		String confLocation = null;
 
 		CommandLineOptionParser optionsParser = new CommandLineOptionParser(args);
@@ -72,7 +76,7 @@
 		if ((invalidOptionsList.size()>0)||(args.length>4))
 		{
 			printUsage();
-			return;
+			return null;
 		}
 
 		Map optionsMap = optionsParser.getAllOptions();
@@ -105,10 +109,12 @@
             ListenerManager listenerManager =  new ListenerManager();
 				listenerManager.init(configctx);
 			listenerManager.start();
-			log.info("[SimpleAxisServer] Started");
-		} catch (Throwable t) {
+            log.info("[SimpleAxisServer] Started");
+            return listenerManager;
+        } catch (Throwable t) {
             log.fatal("[SimpleAxisServer] Shutting down. Error starting SimpleAxisServer",
t);
         }
+        return null;
     }
 
     private static void configurePort(ConfigurationContext configCtx) {

Modified: webservices/synapse/trunk/java/modules/samples/src/test/java/org/apache/synapse/samples/n2n/AbstractAutomationTestCase.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/src/test/java/org/apache/synapse/samples/n2n/AbstractAutomationTestCase.java?rev=572289&r1=572288&r2=572289&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/samples/src/test/java/org/apache/synapse/samples/n2n/AbstractAutomationTestCase.java
(original)
+++ webservices/synapse/trunk/java/modules/samples/src/test/java/org/apache/synapse/samples/n2n/AbstractAutomationTestCase.java
Mon Sep  3 05:07:14 2007
@@ -21,6 +21,7 @@
 
 import org.apache.axiom.om.OMElement;
 import org.apache.synapse.ServerManager;
+import org.apache.axis2.engine.ListenerManager;
 import org.custommonkey.xmlunit.NamespaceContext;
 import org.custommonkey.xmlunit.SimpleNamespaceContext;
 import org.custommonkey.xmlunit.XMLTestCase;
@@ -67,6 +68,13 @@
         OutputStream os = new ByteArrayOutputStream();
         elem.serialize(os);
         return os.toString();
+    }
+
+    protected ListenerManager startCustomAxis2Server(String httpPort, String httpsPort) throws
Exception {
+        System.setProperty("http_port", httpPort);
+        System.setProperty("https_port", httpsPort);
+        return SampleAxis2Server.startServer(new String[]{"-repo", "modules/samples/target/test_repos/axis2Server/",
+                    "-conf", "modules/samples/target/test_repos/axis2Server/conf/axis2.xml"});
     }
 
     protected void tearDown() throws Exception {

Modified: webservices/synapse/trunk/java/modules/samples/src/test/java/org/apache/synapse/samples/n2n/SynapseSample_54_Integration.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/src/test/java/org/apache/synapse/samples/n2n/SynapseSample_54_Integration.java?rev=572289&r1=572288&r2=572289&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/samples/src/test/java/org/apache/synapse/samples/n2n/SynapseSample_54_Integration.java
(original)
+++ webservices/synapse/trunk/java/modules/samples/src/test/java/org/apache/synapse/samples/n2n/SynapseSample_54_Integration.java
Mon Sep  3 05:07:14 2007
@@ -1,24 +1,45 @@
 package org.apache.synapse.samples.n2n;
 
 import org.apache.synapse.Constants;
+import org.apache.axis2.engine.ListenerManager;
+import org.apache.axis2.context.ConfigurationContext;
 import samples.userguide.StockQuoteClient;
+import samples.userguide.LoadbalanceFailoverClient;
+import samples.util.SampleAxis2Server;
 
 /**
  *
  */
 public class SynapseSample_54_Integration extends AbstractAutomationTestCase {
 
+    ListenerManager listenerManager = null;
+
     protected void setUp() throws Exception {
         System.setProperty(Constants.SYNAPSE_XML, SAMPLE_CONFIG_ROOT_PATH + "synapse_sample_54.xml");
         System.setProperty("addurl", SYNAPSE_BASE_URL);
         System.setProperty("symbol", "IBM");
         System.setProperty("mode", "quote");
-        super.setUp();
+        System.setProperty("repository", "modules/samples/target/test_repos/axis2Client");
+        setUpNSContext();
+        System.setProperty("test_mode", "true");
+        System.setProperty("i", "3");
     }
 
     public void testSample() throws Exception {
-        String resultString = getStringResultOfTest(StockQuoteClient.executeTestClient());
-        assertXpathExists("ns:getQuoteResponse", resultString);
-        assertXpathExists("ns:getQuoteResponse/ns:return", resultString);
+        setUpSynapseEnv();
+        startCustomAxis2Server("9001", "9005");
+        startCustomAxis2Server("9002", "9006");
+        listenerManager = startCustomAxis2Server("9003", "9007");
+        String resultString = (new LoadbalanceFailoverClient()).sessionlessClient();
+        assertTrue(resultString.contains("9001"));
+        assertTrue(resultString.contains("9002"));
+        assertTrue(resultString.contains("9003"));
+
+        listenerManager.destroy();
+        listenerManager.isStopped();
+        resultString = (new LoadbalanceFailoverClient()).sessionlessClient();
+        assertTrue(resultString.contains("9001"));
+        assertTrue(resultString.contains("9002"));
+        assertFalse(resultString.contains("9003"));
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message