public static void main(String[] args) throws AxisFault, IOException {
System.out.println("\nTHIS IS A SAMPLE APPLICATION TO DEMONSTRATE THE FUNCTIONALITY OF SERVICE GROUPS");
System.out.println("===============================================================================");
Call call = new Call();
Options options = new Options();
options.setListenerTransportProtocol(Constants.TRANSPORT_HTTP);
options.setUseSeparateListener(false);
call.setClientOptions(options);
boolean exit = false;
String serviceGroupContextId = null;
while (!exit) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\n\nNew round (n) /continue round (c).../exit (e)");
String option = reader.readLine();
if ("e".equalsIgnoreCase(option)) {
System.out.println("Exiting calculator...");
return;
}
if (!"n".equalsIgnoreCase(option) && !"c".equalsIgnoreCase(option)) {
System.out.println("Error: Invalid option");
continue;
}
System.out.print("Please Select the service ( '+' / '-' / '*' )....");
String operation = reader.readLine();
if (!"+".equalsIgnoreCase(operation) && !"-".equalsIgnoreCase(operation) && !"*".equalsIgnoreCase(operation)) {
System.out.println("Error: Invalid option");
continue;
}
if ("+".equals(operation))
options.setTo(new EndpointReference(addService));
else if ("-".equals(operation))
options.setTo(new EndpointReference(substractService));
else if ("*".equals(operation))
options.setTo(new EndpointReference(multiplyService));
if ("n".equalsIgnoreCase(option)) {
System.out.print("Enter parameter 1...");
String param1Str = reader.readLine();
System.out.print("Enter parameter 2...");
String param2Str = reader.readLine();
int param1 = Integer.parseInt(param1Str);
int param2 = Integer.parseInt(param2Str);
String opStr = null;
if ("+".equals(operation)) {
opStr = "add";
} else if ("-".equals(operation)) {
opStr = "substract";
} else if ("*".equals(operation)) {
opStr = "multiply";
}
System.out.println("Invoking...");
SOAPEnvelope result = call.invokeBlocking(opStr, getRequestEnvelope(opStr, param1, param2,
serviceGroupContextId));
printResult(result);
if (serviceGroupContextId == null)
serviceGroupContextId = getServiceGroupContextId(result);
} else if ("c".equalsIgnoreCase(option)) {
if (serviceGroupContextId == null) {
System.out.println("Error: First operation must be a New one. Please select 'n'");
continue;
}
System.out.print("Enter parameter...");
String paramStr = reader.readLine();
int param = Integer.parseInt(paramStr);
String opStr = null;
if ("+".equals(operation)) {
opStr = "addPrevious";
} else if ("-".equals(operation)) {
opStr = "substractPrevious";
} else if ("*".equals(operation)) {
opStr = "multiplyPrevious";
}
System.out.println("Invoking...");
SOAPEnvelope result = call.invokeBlocking(opStr, getPreviousRequestEnvelope(opStr, param,
serviceGroupContextId));
printResult(result);
}