Package net.fp.rp.axis.client

Source Code of net.fp.rp.axis.client.WorkflowStarterClient

package net.fp.rp.axis.client;

import java.util.Iterator;
import java.util.Map;

import net.fp.rp.axis.JaxRpcWorkflowStarter;
import net.fp.rp.common.exception.RpException;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.util.StopWatch;

/**
*  This sample is based on the @link www.spring.org JPetStore sample
*  @todo - make this work against the real thing
*
* Demo client class for remote OrderServices, to be invoked as standalone
* program from the command line, e.g. via "client.bat" or "run.xml".
*
* <p>You need to specify an order ID and optionally a number of calls,
* e.g. for order ID 1000: 'client 1000' for a single call per service or
* 'client 1000 10' for 10 calls each".
*
* <p>Reads in the application context from a "clientContext.xml" file in
* the VM execution directory, calling all OrderService proxies defined in it.
* See that file for details.
*
* @see org.springframework.samples.jpetstore.domain.logic.OrderService
*/
public class WorkflowStarterClient {

  public static final String CLIENT_CONTEXT_CONFIG_LOCATION = "clientContext.xml";

   /** Logger for this class and subclasses */
    protected final Logger log = Logger.getLogger(getClass());

  private final ListableBeanFactory beanFactory;

  public WorkflowStarterClient(ListableBeanFactory beanFactory) {
    this.beanFactory = beanFactory;
  }

  public void invokeOrderServices(int orderId, int nrOfCalls) throws RpException{
    StopWatch stopWatch = new StopWatch(nrOfCalls + " OrderService call(s)");
    Map orderServices = this.beanFactory.getBeansOfType(JaxRpcWorkflowStarter.class);
    for (Iterator it = orderServices.keySet().iterator(); it.hasNext();) {
      String beanName = (String) it.next();
      JaxRpcWorkflowStarter orderService = (JaxRpcWorkflowStarter) orderServices.get(beanName);
      System.out.println("Calling OrderService '" + beanName + "' with order ID " + orderId);
      stopWatch.start(beanName);
      String order = null;
      for (int i = 0; i < nrOfCalls; i++) {
        //order = orderService.startWorkflow();
      }
      stopWatch.stop();
      if (order != null) {
        log.debug("Return Value:"+order);
      }
      else {
        System.out.println("Order with ID " + orderId + " not found");
      }
      System.out.println();
    }
    System.out.println(stopWatch.prettyPrint());
  }

 

  public static void main(String[] args) throws Throwable{
    if (args.length == 0 || "".equals(args[0])) {
      System.out.println(
          "You need to specify an order ID and optionally a number of calls, e.g. for order ID 1000: " +
          "'client 1000' for a single call per service or 'client 1000 10' for 10 calls each");
    }
    else {
      int orderId = Integer.parseInt(args[0]);
      int nrOfCalls = 1;
      if (args.length > 1 && !"".equals(args[1])) {
        nrOfCalls = Integer.parseInt(args[1]);
      }
      ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext(CLIENT_CONTEXT_CONFIG_LOCATION);
      WorkflowStarterClient client = new WorkflowStarterClient(beanFactory);
      client.invokeOrderServices(orderId, nrOfCalls);
    }
  }

}
TOP

Related Classes of net.fp.rp.axis.client.WorkflowStarterClient

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.