FileDocCategorySizeDatePackage
OrderServiceClient.javaAPI DocExample3491Sat Dec 27 18:02:20 GMT 2003org.springframework.samples.jpetstore.service.client

OrderServiceClient

public class OrderServiceClient extends Object
Demo client class for remote OrderServices, to be invoked as standalone program from the command line, e.g. via "client.bat" or "run.xml".

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".

Reads in the application context from "clientContext.xml", calling all OrderService proxies defined in it. See that file for details.

author
Juergen Hoeller
since
26.12.2003
see
org.springframework.samples.jpetstore.domain.logic.OrderService

Fields Summary
private final org.springframework.beans.factory.ListableBeanFactory
beanFactory
Constructors Summary
public OrderServiceClient(org.springframework.beans.factory.ListableBeanFactory beanFactory)

		this.beanFactory = beanFactory;
	
Methods Summary
public voidinvokeOrderServices(int orderId, int nrOfCalls)

		StopWatch stopWatch = new StopWatch(nrOfCalls + " OrderService call(s)");
		Map orderServices = this.beanFactory.getBeansOfType(OrderService.class, true, true);
		for (Iterator it = orderServices.keySet().iterator(); it.hasNext();) {
			String beanName = (String) it.next();
			OrderService orderService = (OrderService) orderServices.get(beanName);
			System.out.println("Calling OrderService '" + beanName + "' with order ID " + orderId);
			stopWatch.start(beanName);
			Order order = null;
			for (int i = 0; i < nrOfCalls; i++) {
				order = orderService.getOrder(orderId);
			}
			stopWatch.stop();
			if (order != null) {
				printOrder(order);
			}
			else {
				System.out.println("Order with ID " + orderId + " not found");
			}
			System.out.println();
		}
		System.out.println(stopWatch.prettyPrint());
	
public static voidmain(java.lang.String[] args)

		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("clientContext.xml");
			OrderServiceClient client = new OrderServiceClient(beanFactory);
			client.invokeOrderServices(orderId, nrOfCalls);
		}
	
protected voidprintOrder(org.springframework.samples.jpetstore.domain.Order order)

		System.out.println("Got order with order ID " + order.getOrderId() + " and order date " + order.getOrderDate());
		System.out.println("Shipping address is: " + order.getShipAddress1());
		for (Iterator lineItems = order.getLineItems().iterator(); lineItems.hasNext();) {
			LineItem lineItem = (LineItem) lineItems.next();
			System.out.println("LineItem " + lineItem.getLineNumber() + ": " + lineItem.getQuantity() +
												 " piece(s) of item " + lineItem.getItemId());
		}