Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Right click on Java Resources: src and select New->Package.
    !!

    Image Added


  2. Name the package as org.apache.geronimo.samples.jws. Select Finish.
    !!

    Image Added


  3. Right click on the new package and Select New->Interface.


    Image Added


  4. Name the interface as Calculator. Select Finish.
    !!

    Image Added


  5. Add the following code to the Calculator interface class
    Code Block
    titleCalculator.class
    borderStylesolid
    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
    titleWarning

    add explanation for the code

  1. Right click on the package org.apache.geronimo.samples.jws and select
    New->Class.
  2. Name the class CalculatorService
  3. Accept all the defaults and click Select Finish.
    !!

    Image Added


  4. Add the following code to CalculatorService.class
    Code Block
    titleCalculatorService.class
    borderStylesolid
    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;
    }
    }