THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
- Right click on Java Resources: src and select New->Package.
!!
- Name the package as org.apache.geronimo.samples.jws. Select Finish.
!!
- Right click on the new package and Select New->Interface.
- Name the interface as Calculator. Select Finish.
!!
- Add the following code to the Calculator interface class
Code Block title Calculator.class borderStyle solid package org.apache.geronimo.samples.jws; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; import javax.xml.ws.RequestWrapper; import javax.xml.ws.ResponseWrapper; @WebService(name="CalculatorPortType", portName="CalculatorPort", targetNamespace = "http://jws.samples.geronimo.apache.org") public interface Calculator { /** * @param value1 * @param value2 * @return * returns int * */ @WebMethod(operationName = "add") @WebResult(name = "return", targetNamespace = "http://jws.samples.geronimo.apache.org") @RequestWrapper(localName = "add", targetNamespace = "http://jws.samples.geronimo.apache.org", className = "org.apache.geronimo.samples.jws.Add") @ResponseWrapper(localName = "addResponse", targetNamespace = "http://jws.samples.geronimo.apache.org", className = "org.apache.geronimo.samples.jws.AddResponse") public int add(@WebParam(name = "value1", targetNamespace = "http://jws.samples.geronimo.apache.org") int value1, @WebParam(name = "value2", targetNamespace = "http://jws.samples.geronimo.apache.org") int value2); }
Warning title Warning add explanation for the code
- Right click on the package org.apache.geronimo.samples.jws and select
New->Class. - Name the class CalculatorService
- Accept all the defaults and click Select Finish.
!!
- Add the following code to CalculatorService.class
Code Block title CalculatorService.class borderStyle solid package org.apache.geronimo.samples.jws; import javax.annotation.Resource; import javax.jws.WebService; import javax.xml.ws.WebServiceContext; @WebService(serviceName = "Calculator", portName="CalculatorPort", endpointInterface = "org.apache.geronimo.samples.jws.Calculator", targetNamespace = "http://jws.samples.geronimo.apache.org") public class CalculatorService implements Calculator { @Resource private WebServiceContext context; /** * @return * returns javax.xml.ws.WebServiceContext */ public WebServiceContext getContext() { return context; } /** * @param value1 * @param value2 * @return * returns int */ public int add(int value1, int value2) { System.out.println("User Principal: " + context.getUserPrincipal()); System.out.println("value1: " + value1 + " value2: " + value2); return value1 + value2; } }