Author: chathura_ce
Date: Mon Apr 2 10:52:12 2007
New Revision: 524855
URL: http://svn.apache.org/viewvc?view=rev&rev=524855
Log:
Added multi threaded client for demonstrating load balancing and failover
samples.
Added a statefull sample service to be used in http and soap session based load
balancing.
Modified the axis2server.sh to take server name as a parameter.
Changed the sample client build.xml to run new multi threaded client.
Added:
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service1/
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service1/services.xml
- copied, changed from r524045,
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/services.xml
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service2/
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service2/services.xml
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService1.java
- copied, changed from r524053,
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LoadbalanceFailoverService.java
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService2.java
webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/ServiceInvoker.java
webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/ThreadedClient.java
Removed:
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/services.xml
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LoadbalanceFailoverService.java
Modified:
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/build.xml
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/main/scripts/axis2server.sh
webservices/synapse/trunk/java/modules/samples/src/main/scripts/build.xml
Modified:
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/build.xml
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/build.xml?view=diff&rev=524855&r1=524854&r2=524855
==============================================================================
---
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/build.xml
(original)
+++
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/build.xml
Mon Apr 2 10:52:12 2007
@@ -17,7 +17,7 @@
~ under the License.
-->
-<project default="build-service">
+<project default="build-services">
<property name="synapse.home" value="../../../.."/>
<property name="lib" value="${synapse.home}/lib"/>
@@ -33,6 +33,11 @@
</fileset>
</path>
+ <target name="build-services" depends="compile-all">
+ <ant target="build-service1"/>
+ <ant target="build-service2"/>
+ </target>
+
<target name="init" depends="clean">
<mkdir dir="${temp.dir}"/>
<mkdir dir="${services}"/>
@@ -51,20 +56,37 @@
</javac>
</target>
- <target name="build-service" depends="compile-all">
- <property name="LBFA.dir"
value="${temp.dir}/LoadbalanceFailoverService"/>
- <mkdir dir="${LBFA.dir}"/>
-
- <mkdir dir="${LBFA.dir}/META-INF"/>
- <copy file="conf/services.xml"
tofile="${LBFA.dir}/META-INF/services.xml"/>
- <copy toDir="${LBFA.dir}">
+ <target name="build-service1">
+ <property name="LBFA1.dir" value="${temp.dir}/LBService1"/>
+ <mkdir dir="${LBFA1.dir}"/>
+
+ <mkdir dir="${LBFA1.dir}/META-INF"/>
+ <copy file="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>
+ </target>
+
+ <target name="build-service2">
+ <property name="LBFA2.dir" value="${temp.dir}/LBService2"/>
+ <mkdir dir="${LBFA2.dir}"/>
+
+ <mkdir dir="${LBFA2.dir}/META-INF"/>
+ <copy file="conf/service2/services.xml"
tofile="${LBFA2.dir}/META-INF/services.xml"/>
+ <copy toDir="${LBFA2.dir}">
<fileset dir="${classes}">
- <include name="**/*.class"/>
+ <include name="**/LBService2.class"/>
</fileset>
</copy>
- <jar destfile="${services}/LoadbalanceFailoverService.aar">
- <fileset dir="${LBFA.dir}"/>
+ <jar destfile="${services}/LBService2.aar">
+ <fileset dir="${LBFA2.dir}"/>
</jar>
</target>
Copied:
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service1/services.xml
(from r524045,
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/services.xml)
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service1/services.xml?view=diff&rev=524855&p1=webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/services.xml&r1=524045&p2=webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service1/services.xml&r2=524855
==============================================================================
---
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/services.xml
(original)
+++
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service1/services.xml
Mon Apr 2 10:52:12 2007
@@ -18,13 +18,13 @@
-->
<serviceGroup>
-<service name="LoadbalanceFailoverService">
+<service name="LBService1">
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />
</messageReceivers>
- <parameter locked="false"
name="ServiceClass">samples.services.LoadbalanceFailoverService</parameter>
+ <parameter locked="false"
name="ServiceClass">samples.services.LBService1</parameter>
</service>
</serviceGroup>
Added:
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service2/services.xml
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service2/services.xml?view=auto&rev=524855
==============================================================================
---
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service2/services.xml
(added)
+++
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/conf/service2/services.xml
Mon Apr 2 10:52:12 2007
@@ -0,0 +1,30 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you 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.
+ -->
+
+<serviceGroup>
+<service name="LBService2" scope="transportsession">
+ <messageReceivers>
+ <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
+
class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver" />
+ <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
+
class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />
+ </messageReceivers>
+ <parameter locked="false"
name="ServiceClass">samples.services.LBService2</parameter>
+</service>
+</serviceGroup>
\ No newline at end of file
Copied:
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService1.java
(from r524053,
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LoadbalanceFailoverService.java)
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService1.java?view=diff&rev=524855&p1=webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LoadbalanceFailoverService.java&r1=524053&p2=webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService1.java&r2=524855
==============================================================================
---
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LoadbalanceFailoverService.java
(original)
+++
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService1.java
Mon Apr 2 10:52:12 2007
@@ -22,15 +22,25 @@
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
-public class LoadbalanceFailoverService {
+public class LBService1 {
+
+ public OMElement setClientName(OMElement cName) {
+
+ cName.build();
+ cName.detach();
+
+ cName.setText("Sessions are not supported in this service.");
+
+ return cName;
+ }
public OMElement sampleOperation(OMElement param) {
param.build();
param.detach();
- String port = System.getProperty("http_port");
- if (port != null) {
- param.setText("Response from server: " + port);
+ String sName = System.getProperty("server_name");
+ if (sName != null) {
+ param.setText("Response from server: " + sName);
} else {
param.setText("Response from anonymous server");
}
@@ -49,9 +59,9 @@
throw new AxisFault("Service is interrupted while sleeping.");
}
- String port = System.getProperty("http_port");
- if (port != null) {
- timeElement.setText("Response from server: " + port);
+ String sName = System.getProperty("server_name");
+ if (sName != null) {
+ timeElement.setText("Response from server: " + sName);
} else {
timeElement.setText("Response from anonymous server");
}
@@ -70,9 +80,9 @@
System.out.println("Iteration: " + i);
}
- String port = System.getProperty("http_port");
- if (port != null) {
- loadElement.setText("Response from server: " + port);
+ String sName = System.getProperty("server_name");
+ if (sName != null) {
+ loadElement.setText("Response from server: " + sName);
} else {
loadElement.setText("Response from anonymous server");
}
Added:
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService2.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService2.java?view=auto&rev=524855
==============================================================================
---
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService2.java
(added)
+++
webservices/synapse/trunk/java/modules/samples/services/LoadbalanceFailoverService/src/samples/services/LBService2.java
Mon Apr 2 10:52:12 2007
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 samples.services;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.context.ServiceContext;
+
+public class LBService2 {
+
+ private ServiceContext serviceContext = null;
+
+ public void init(ServiceContext serviceContext) {
+ this.serviceContext = serviceContext;
+ }
+
+ public OMElement sleepOperation(OMElement param) {
+
+ param.build();
+ param.detach();
+
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
+ }
+
+ Long c = null;
+ Object o = serviceContext.getProperty("count");
+ if (o == null) {
+ c = new Long(1);
+ serviceContext.setProperty("count", c);
+ } else {
+ c = (Long) o;
+ c = new Long(c.longValue() + 1);
+ serviceContext.setProperty("count", c);
+ }
+
+ String cName = "anonymous";
+ Object cn = serviceContext.getProperty("cName");
+ if (cn != null) {
+ cName = (String) cn;
+
+ }
+
+ String sName = "anonymous";
+ Object s = System.getProperty("server_name");
+ if (s != null) {
+ sName = (String) s;
+ }
+
+ String msg = "Server: " + sName + " processed the request " +
c.toString() + " from client: " + cName;
+ System.out.println(msg);
+
+ param.setText(msg);
+
+ return param;
+ }
+
+ public OMElement loadOperation(OMElement param) {
+
+ param.build();
+ param.detach();
+
+ String l = param.getText();
+ long load = Long.parseLong(l);
+
+ for (long i = 0; i < load; i++) {
+ System.out.println("Iteration: " + i);
+ }
+
+ Long c = null;
+ Object o = serviceContext.getProperty("count");
+ if (o == null) {
+ c = new Long(1);
+ serviceContext.setProperty("count", c);
+ } else {
+ c = (Long) o;
+ c = new Long(c.longValue() + 1);
+ serviceContext.setProperty("count", c);
+ }
+
+ String cName = "anonymous";
+ Object cn = serviceContext.getProperty("cName");
+ if (cn != null) {
+ cName = (String) cn;
+
+ }
+
+ String sName = "anonymous";
+ Object s = System.getProperty("server_name");
+ if (s != null) {
+ sName = (String) s;
+ }
+
+ String msg = "Server: " + sName + " processed the request " +
c.toString() + " from client: " + cName;
+ System.out.println(msg);
+
+ param.setText(msg);
+
+ return param;
+ }
+
+ public OMElement setClientName(OMElement name) {
+
+ name.build();
+ name.detach();
+
+ String cName = name.getText();
+ serviceContext.setProperty("cName", cName);
+
+ String sName = "anonymous";
+ Object s = System.getProperty("server_name");
+ if (s != null) {
+ sName = (String) s;
+ }
+
+ String msg = "Server " + sName + " started a session with client " +
cName;
+ System.out.println(msg);
+ name.setText(msg);
+
+ return name;
+ }
+}
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?view=diff&rev=524855&r1=524854&r2=524855
==============================================================================
---
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 Apr 2 10:52:12 2007
@@ -97,11 +97,14 @@
value.setText("Sample string");
Options options = new Options();
- options.setTo(new EndpointReference("http://localhost:" + synapsePort
+ "/soap/services/LoadbalanceFailoverService"));
+ options.setTo(new EndpointReference
+ ("http://localhost:" + synapsePort +
"/soap/services/LoadbalanceFailoverService"));
+
options.setAction("sampleOperation");
try {
- ConfigurationContext configContext =
ConfigurationContextFactory.createConfigurationContextFromFileSystem("client_repo",
null);
+ ConfigurationContext configContext = ConfigurationContextFactory.
+ createConfigurationContextFromFileSystem("client_repo",
null);
ServiceClient client = new ServiceClient(configContext, null);
options.setTimeOutInMilliSeconds(10000000);
@@ -159,7 +162,8 @@
}
Options options = new Options();
- options.setTo(new EndpointReference("http://localhost:" + synapsePort
+ "/soap/services/LoadbalanceFailoverService"));
+ options.setTo(new EndpointReference
+ ("http://localhost:" + synapsePort +
"/soap/services/LoadbalanceFailoverService"));
options.setAction("sampleOperation");
options.setTimeOutInMilliSeconds(10000000);
@@ -170,7 +174,8 @@
SOAPEnvelope env3 = buildSoapEnvelope("c3", "v1");
SOAPEnvelope[] envelopes = {env1, env2, env3};
- ConfigurationContext configContext =
ConfigurationContextFactory.createConfigurationContextFromFileSystem("client_repo",
null);
+ ConfigurationContext configContext = ConfigurationContextFactory.
+ createConfigurationContextFromFileSystem("client_repo",
null);
ServiceClient client = new ServiceClient(configContext, null);
client.setOptions(options);
client.engageModule("addressing");
@@ -189,15 +194,19 @@
op.addMessageContext(messageContext);
op.execute(true);
- MessageContext responseContext =
op.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+ MessageContext responseContext =
+
op.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
SOAPEnvelope responseEnvelope = responseContext.getEnvelope();
- OMElement vElement =
responseEnvelope.getBody().getFirstChildWithName(new QName("Value"));
- System.out.println("Request: " + i + " Session number: " +
sessionNumber + " " + vElement.getText());
+ OMElement vElement =
+ responseEnvelope.getBody().getFirstChildWithName(new
QName("Value"));
+ System.out.println(
+ "Request: " + i + " Session number: " +
+ sessionNumber + " " + vElement.getText());
}
} catch (AxisFault axisFault) {
- axisFault.printStackTrace(); //To change body of catch statement
use File | Settings | File Templates.
+ axisFault.printStackTrace();
}
}
@@ -213,14 +222,16 @@
SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();
- OMNamespace wsaNamespace =
soapFactory.createOMNamespace("http://www.w3.org/2005/08/addressing", "wsa");
+ OMNamespace wsaNamespace = soapFactory.
+ createOMNamespace("http://www.w3.org/2005/08/addressing",
"wsa");
SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
SOAPHeader header = soapFactory.createSOAPHeader();
envelope.addChild(header);
- OMNamespace synNamespace =
soapFactory.createOMNamespace("http://ws.apache.org/namespaces/synapse", "syn");
+ OMNamespace synNamespace = soapFactory.
+ createOMNamespace("http://ws.apache.org/namespaces/synapse",
"syn");
OMElement clientIDElement = soapFactory.createOMElement("ClientID",
synNamespace);
clientIDElement.setText(clientID);
header.addChild(clientIDElement);
Added:
webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/ServiceInvoker.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/ServiceInvoker.java?view=auto&rev=524855
==============================================================================
---
webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/ServiceInvoker.java
(added)
+++
webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/ServiceInvoker.java
Mon Apr 2 10:52:12 2007
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 samples.userguide;
+
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+
+import javax.xml.namespace.QName;
+
+public class ServiceInvoker extends Thread {
+
+ private String invokerName = "anonymous";
+ private String operation = null;
+ private ServiceClient client = null;
+ private OMElement msg = null;
+ private long iterations = 10;
+ private boolean statefull = false;
+
+ private OMFactory fac = null;
+
+ private long runningTime = 0;
+
+ public ServiceInvoker(String epr, String operation) {
+
+ this.operation = operation;
+
+ Options options = new Options();
+ options.setTo(new EndpointReference(epr));
+ options.setAction(operation);
+
+ try {
+ ConfigurationContext configContext = ConfigurationContextFactory.
+ createConfigurationContextFromFileSystem("client_repo",
null);
+
+ client = new ServiceClient(configContext, null);
+ options.setTimeOutInMilliSeconds(10000000);
+
+ client.setOptions(options);
+ client.engageModule("addressing");
+
+ } catch (AxisFault axisFault) {
+ axisFault.printStackTrace();
+ }
+
+ fac = OMAbstractFactory.getOMFactory();
+ msg = fac.createOMElement("sleepTime", null);
+ msg.setText("1000");
+ }
+
+ public String getInvokerName() {
+ return invokerName;
+ }
+
+ public void setInvokerName(String invokerName) {
+ this.invokerName = invokerName;
+
+ if (statefull) {
+ client.getOptions().setManageSession(true);
+ client.getOptions().setAction("setClientName");
+
+ OMElement cName = fac.createOMElement("cName", null);
+ cName.setText(invokerName);
+
+ try {
+ OMElement response = client.sendReceive(cName);
+ System.out.println(response.getText());
+ } catch (AxisFault axisFault) {
+ axisFault.printStackTrace();
+ }
+ }
+ }
+
+ public long getRunningTime() {
+ return runningTime;
+ }
+
+ public void setMessage(String msgText) {
+ msg.setText(msgText);
+ }
+
+ public void setClientSessionID(String id) {
+
+ SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();
+
+ OMNamespace synNamespace = soapFactory.
+ createOMNamespace("http://ws.apache.org/namespaces/synapse",
"syn");
+ SOAPHeaderBlock header = soapFactory.createSOAPHeaderBlock("ClientID",
synNamespace);
+ header.setText(id);
+
+ client.addHeader(header);
+ }
+
+ public void setIterations(long i) {
+ iterations = i;
+ }
+
+ public void setStatefull(boolean state) {
+ this.statefull = state;
+ }
+
+ public void run() {
+
+ client.getOptions().setAction(operation);
+
+ try {
+
+ long t1 = System.currentTimeMillis();
+
+ for (long i=0; i < iterations; i++) {
+ OMElement response2 = client.sendReceive(msg);
+ System.out.println(invokerName + ": " + response2.toString());
+ }
+
+ long t2 = System.currentTimeMillis();
+
+
System.out.println("================================================================");
+ System.out.println(invokerName + " completed requests.");
+
System.out.println("================================================================");
+ runningTime = t2 - t1;
+
+ } catch (AxisFault axisFault) {
+ axisFault.printStackTrace(); //To change body of catch statement
use File | Settings | File Templates.
+ }
+ }
+}
Added:
webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/ThreadedClient.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/ThreadedClient.java?view=auto&rev=524855
==============================================================================
---
webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/ThreadedClient.java
(added)
+++
webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/ThreadedClient.java
Mon Apr 2 10:52:12 2007
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 samples.userguide;
+
+public class ThreadedClient {
+
+ public static final int STATELESS = 0;
+ public static final int SOAP_SESSION = 1;
+ public static final int SIMPLE_CLIENT_SESSION = 2;
+ public static final int TRANSPORT_SESSION = 3;
+
+ private int session = STATELESS;
+
+ /**
+ * @param args 1: epr
+ * 2: operation
+ * 3: number of requests
+ * 4: load
+ * 5: number of clients
+ * 6: session (client | transport)
+ */
+ public static void main(String[] args) {
+ new ThreadedClient().work();
+ }
+
+ public void work() {
+
+ String epr1 = System.getProperty("epr");
+ if (epr1 == null) {
+ epr1 = "http://localhost:8080";
+ }
+ System.out.println("EPR: " + epr1);
+
+ String op = System.getProperty("op");
+ if (op == null) {
+ op = "sleepOperation";
+ }
+ System.out.println("Operation: " + op);
+
+ long requests = 10;
+ String requestsProp = System.getProperty("req");
+ if (requestsProp != null) {
+ requests = Long.parseLong(requestsProp);
+ }
+ System.out.println("Number of requests: " + requests);
+
+ String msg = System.getProperty("load");
+ if (msg == null) {
+ msg = "1000";
+ }
+ System.out.println("Load: " + msg);
+
+ String sessionProp = System.getProperty("session");
+ if (sessionProp == null) {
+ session = STATELESS;
+ } else {
+ if (sessionProp.equalsIgnoreCase("client")) {
+ session = SIMPLE_CLIENT_SESSION;
+ } else if (sessionProp.equalsIgnoreCase("transport")) {
+ session = TRANSPORT_SESSION;
+ }
+ }
+
+ int clients = 2;
+ String clientsProp = System.getProperty("t");
+ if (clientsProp != null) {
+ clients = Integer.parseInt(clientsProp);
+ }
+ System.out.println("Number of client threads: " + clients);
+
+ ServiceInvoker[] invokers = new ServiceInvoker[clients];
+
+ for (int i = 0; i< clients; i++) {
+
+ ServiceInvoker invoker = new ServiceInvoker(epr1, op);
+
+ if (session != STATELESS) {
+ invoker.setStatefull(true);
+ }
+
+ invoker.setInvokerName("CLIENT " + i);
+ invoker.setIterations(requests);
+ invoker.setMessage(msg);
+
+ if (session == SIMPLE_CLIENT_SESSION) {
+ invoker.setClientSessionID("CLIENT " + i);
+ }
+
+ invokers[i] = invoker;
+ }
+
+ long t1 = System.currentTimeMillis();
+
+ for (int i = 0; i < clients; i++) {
+ invokers[i].start();
+ }
+
+ try {
+ for (int i = 0; i < clients; i++) {
+ invokers[i].join();
+ }
+ } catch (InterruptedException e) {
+ System.out.println("ERROR: A client thread is interrupted while
sending requests.");
+ }
+
+ long t2 = System.currentTimeMillis();
+
+
System.out.println("\n================================================================\n");
+
+ for (int i = 0; i < clients; i++) {
+ System.out.println(invokers[i].getInvokerName() +
+ " completed requests in " + invokers[i].getRunningTime() +
" milliseconds.");
+ }
+
+ System.out.println
+ ("Time taken for completing all the requests is " + (t2 - t1)
+ " milliseconds.");
+
+ }
+}
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?view=diff&rev=524855&r1=524854&r2=524855
==============================================================================
---
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 Apr 2 10:52:12 2007
@@ -46,7 +46,14 @@
/**
- * @param args
+ * Expected system properties
+ * http_port: Port to bind HTTP transport (default is 9000)
+ * https_port: Port to bind HTTPS transport (default is 9002)
+ * server_name: Name of this instance of the server (optional)
+ *
+ * @param args 1: Axis2 repository
+ * 2: Axis2 configuration file (axis2.xml)
+ *
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Modified:
webservices/synapse/trunk/java/modules/samples/src/main/scripts/axis2server.sh
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/src/main/scripts/axis2server.sh?view=diff&rev=524855&r1=524854&r2=524855
==============================================================================
---
webservices/synapse/trunk/java/modules/samples/src/main/scripts/axis2server.sh
(original)
+++
webservices/synapse/trunk/java/modules/samples/src/main/scripts/axis2server.sh
Mon Apr 2 10:52:12 2007
@@ -112,15 +112,20 @@
PROGRAM_PARAMS="$PROGRAM_PARAMS""-Xdebug -Xnoagent
-Xrunjdwp:transport=dt_socket,server=y,address=8000 "
shift
+ elif [ "$1" = "-name" ]; then
+ PROGRAM_PARAMS="$PROGRAM_PARAMS""-Dserver_name=$2 "
+ shift
+ shift
+
elif [ "$1" = "-http" ]; then
PROGRAM_PARAMS="$PROGRAM_PARAMS""-Dhttp_port=$2 "
- HTTP_PORT_SET="TRUE"
+ HTTP_PORT_SET="TRUE"
shift
shift
elif [ "$1" = "-https" ]; then
PROGRAM_PARAMS="$PROGRAM_PARAMS""-Dhttps_port=$2 "
- HTTPS_PORT_SET="TRUE"
+ HTTPS_PORT_SET="TRUE"
shift
shift
Modified:
webservices/synapse/trunk/java/modules/samples/src/main/scripts/build.xml
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/src/main/scripts/build.xml?view=diff&rev=524855&r1=524854&r2=524855
==============================================================================
--- webservices/synapse/trunk/java/modules/samples/src/main/scripts/build.xml
(original)
+++ webservices/synapse/trunk/java/modules/samples/src/main/scripts/build.xml
Mon Apr 2 10:52:12 2007
@@ -173,6 +173,18 @@
</java>
</target>
+ <target name="threadedclient" depends="compile">
+ <java classname="samples.userguide.ThreadedClient"
+ classpathref="javac.classpath" fork="true">
+ <sysproperty key="epr" value="${epr}"/>
+ <sysproperty key="op" value="${op}"/>
+ <sysproperty key="req" value="${req}"/>
+ <sysproperty key="load" value="${load}"/>
+ <sysproperty key="t" value="${t}"/>
+ <sysproperty key="session" value="${session}"/>
+ </java>
+ </target>
+
<target name="jmsclient" depends="compile">
<java classname="samples.userguide.GenericJMSClient"
classpathref="javac.classpath" fork="true">
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]