1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 package samples.services; 21 22 import org.apache.axiom.om.OMElement; 23 import org.apache.axis2.AxisFault; 24 25 import javax.xml.namespace.QName; 26 27 public class LBService1 { 28 29 public OMElement setClientName(OMElement cName) { 30 31 cName.build(); 32 cName.detach(); 33 34 cName.setText("Sessions are not supported in this service."); 35 36 return cName; 37 } 38 39 public OMElement sampleOperation(OMElement param) { 40 param.build(); 41 param.detach(); 42 43 String sName = ""; 44 if (System.getProperty("test_mode") != null) { 45 sName = org.apache.axis2.context.MessageContext.getCurrentMessageContext().getTo().getAddress(); 46 } else { 47 sName = System.getProperty("server_name"); 48 } 49 if (sName != null) { 50 param.setText("Response from server: " + sName); 51 } else { 52 param.setText("Response from anonymous server"); 53 } 54 return param; 55 } 56 57 public OMElement sleepOperation(OMElement param) throws AxisFault { 58 59 param.build(); 60 param.detach(); 61 62 OMElement timeElement = param.getFirstChildWithName(new QName("load")); 63 String time = timeElement.getText(); 64 try { 65 Thread.sleep(Long.parseLong(time)); 66 } catch (InterruptedException e) { 67 throw new AxisFault("Service is interrupted while sleeping."); 68 } 69 70 String sName = System.getProperty("server_name"); 71 if (sName != null) { 72 timeElement.setText("Response from server: " + sName); 73 } else { 74 timeElement.setText("Response from anonymous server"); 75 } 76 return param; 77 } 78 79 public OMElement loadOperation(OMElement param) throws AxisFault { 80 81 param.build(); 82 param.detach(); 83 84 OMElement loadElement = param.getFirstChildWithName(new QName("load")); 85 String l = loadElement.getText(); 86 long load = Long.parseLong(l); 87 88 for (long i = 0; i < load; i++) { 89 System.out.println("Iteration: " + i); 90 } 91 92 String sName = System.getProperty("server_name"); 93 if (sName != null) { 94 loadElement.setText("Response from server: " + sName); 95 } else { 96 loadElement.setText("Response from anonymous server"); 97 } 98 return param; 99 } 100 }