package net.programmera.ws.calculator; import javax.xml.rpc.ServiceException; import javax.xml.rpc.server.ServiceLifecycle; import javax.xml.rpc.server.ServletEndpointContext; public class CalculatorImpl implements Calculator, ServiceLifecycle{ private ServletEndpointContext sepCtx; public void init(Object ctx) throws ServiceException{ this.sepCtx=(ServletEndpointContext) ctx; System.out.println("Calculator: ServletEndpointContext retrieved."); this.sepCtx.getHttpSession().setAttribute("counter",new Integer(0)); } public void destroy(){ } public int multiplication(MultiplicationRequestType multiplicationRequestPart) throws java.rmi.RemoteException{ int result = 0; int multiplicand = multiplicationRequestPart.getMultiplicand(); int multiplier = multiplicationRequestPart.getMultiplier(); result = multiplicand * multiplier; count((float) result); return result; } public float division(DivisionRequestType divisionRequestPart) throws net.programmera.ws.calculator.DivideZeroFaultType, java.rmi.RemoteException{ float result = 0; int dividend = divisionRequestPart.getDividend(); int divisor = divisionRequestPart.getDivisor(); if (divisor == 0){ DivideZeroFaultType dzft= new DivideZeroFaultType(divisor,"Division by zero is not possible."); throw dzft; } result = (float) dividend / divisor; count(result); return result; } private void count(float res){ // Increase counter Integer counter= (Integer) this.sepCtx.getHttpSession().getAttribute("counter"); Integer count2= counter.intValue() +1; this.sepCtx.getHttpSession().setAttribute("counter", count2); System.out.println("Calculator: Call "+ count2 +", result="+ res); } }