001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package samples.services;
021:
022: import org.apache.axiom.om.OMElement;
023: import org.apache.axis2.AxisFault;
024:
025: import javax.xml.namespace.QName;
026:
027: public class LBService1 {
028:
029: public OMElement setClientName(OMElement cName) {
030:
031: cName.build();
032: cName.detach();
033:
034: cName.setText("Sessions are not supported in this service.");
035:
036: return cName;
037: }
038:
039: public OMElement sampleOperation(OMElement param) {
040: param.build();
041: param.detach();
042:
043: String sName = "";
044: if (System.getProperty("test_mode") != null) {
045: sName = org.apache.axis2.context.MessageContext
046: .getCurrentMessageContext().getTo().getAddress();
047: } else {
048: sName = System.getProperty("server_name");
049: }
050: if (sName != null) {
051: param.setText("Response from server: " + sName);
052: } else {
053: param.setText("Response from anonymous server");
054: }
055: return param;
056: }
057:
058: public OMElement sleepOperation(OMElement param) throws AxisFault {
059:
060: param.build();
061: param.detach();
062:
063: OMElement timeElement = param.getFirstChildWithName(new QName(
064: "load"));
065: String time = timeElement.getText();
066: try {
067: Thread.sleep(Long.parseLong(time));
068: } catch (InterruptedException e) {
069: throw new AxisFault(
070: "Service is interrupted while sleeping.");
071: }
072:
073: String sName = System.getProperty("server_name");
074: if (sName != null) {
075: timeElement.setText("Response from server: " + sName);
076: } else {
077: timeElement.setText("Response from anonymous server");
078: }
079: return param;
080: }
081:
082: public OMElement loadOperation(OMElement param) throws AxisFault {
083:
084: param.build();
085: param.detach();
086:
087: OMElement loadElement = param.getFirstChildWithName(new QName(
088: "load"));
089: String l = loadElement.getText();
090: long load = Long.parseLong(l);
091:
092: for (long i = 0; i < load; i++) {
093: System.out.println("Iteration: " + i);
094: }
095:
096: String sName = System.getProperty("server_name");
097: if (sName != null) {
098: loadElement.setText("Response from server: " + sName);
099: } else {
100: loadElement.setText("Response from anonymous server");
101: }
102: return param;
103: }
104: }
|