Home » synapse-1.2-src » samples.services » [javadoc | source]

    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.context.OperationContext;
   24   import org.apache.axis2.context.ServiceContext;
   25   
   26   import javax.xml.namespace.QName;
   27   
   28   public class LBService2 {
   29   
   30       private ServiceContext serviceContext = null;
   31   
   32       public void init(ServiceContext serviceContext) {
   33           this.serviceContext = serviceContext;
   34       }
   35   
   36       public OMElement sleepOperation(OMElement topParam) {
   37   
   38           topParam.build();
   39           topParam.detach();
   40   
   41           OMElement param = topParam.getFirstChildWithName(new QName("load"));
   42           String l = param.getText();
   43           long time = Long.parseLong(l);
   44   
   45           try {
   46               Thread.sleep(time);
   47           } catch (InterruptedException e) {
   48               e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
   49           }
   50   
   51           Long c = null;
   52           Object o = serviceContext.getProperty("count");
   53           if (o == null) {
   54               c = new Long(1);
   55               serviceContext.setProperty("count", c);
   56           } else {
   57               c = (Long) o;
   58               c = new Long(c.longValue() + 1);
   59               serviceContext.setProperty("count", c);
   60           }
   61   
   62           String cName = "anonymous";
   63           Object cn = serviceContext.getProperty("cName");
   64           if (cn != null) {
   65               cName = (String) cn;
   66   
   67           }
   68   
   69           String sName = "anonymous";
   70           Object s = System.getProperty("server_name");
   71           if (s != null) {
   72               sName = (String) s;
   73           }
   74   
   75           String msg = "Server: " + sName + " processed the request " + c.toString() + " from client: " + cName;
   76           System.out.println(msg);
   77   
   78           param.setText(msg);
   79   
   80           return topParam;
   81       }
   82   
   83       public OMElement loadOperation(OMElement topParam) {
   84   
   85           topParam.build();
   86           topParam.detach();
   87   
   88           OMElement param = topParam.getFirstChildWithName(new QName("load"));
   89           String l = param.getText();
   90           long load = Long.parseLong(l);
   91   
   92           for (long i = 0; i < load; i++) {
   93               System.out.println("Iteration: " + i);
   94           }
   95   
   96           Long c = null;
   97           Object o = serviceContext.getProperty("count");
   98           if (o == null) {
   99               c = new Long(1);
  100               serviceContext.setProperty("count", c);
  101           } else {
  102               c = (Long) o;
  103               c = new Long(c.longValue() + 1);
  104               serviceContext.setProperty("count", c);
  105           }
  106   
  107           String cName = "anonymous";
  108           Object cn = serviceContext.getProperty("cName");
  109           if (cn != null) {
  110               cName = (String) cn;
  111   
  112           }
  113   
  114           String sName = "anonymous";
  115           Object s = System.getProperty("server_name");
  116           if (s != null) {
  117               sName = (String) s;
  118           }
  119   
  120           String msg = "Server: " + sName + " processed the request " + c.toString() + " from client: " + cName;
  121           System.out.println(msg);
  122   
  123           param.setText(msg);
  124   
  125           return topParam;
  126       }
  127   
  128       public OMElement setClientName(OMElement name) {
  129   
  130           name.build();
  131           name.detach();
  132   
  133           String cName = name.getText();
  134           serviceContext.setProperty("cName", cName);
  135   
  136           String sName = "anonymous";
  137           Object s = System.getProperty("server_name");
  138           if (s != null) {
  139               sName = (String) s;
  140           }
  141   
  142           String msg = "Server " + sName + " started a session with client " + cName;
  143           System.out.println(msg);
  144           name.setText(msg);
  145   
  146           return name;
  147       }
  148   }

Home » synapse-1.2-src » samples.services » [javadoc | source]