uCosminexus Application Server, Web Service Development Guide

[Contents][Glossary][Index][Back][Next]

38.3.1 Creating the Web Service Implementation Class

Create a Web Service Implementation Class to code the processing of Web Services. This subsection describes how to calculate the contents of the received request message and create the Web Service Implementation Class that returns response messages.

The following is an example for creating a Web Service Implementation Class:

package com.sample;
 
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.ws.Action;
import javax.xml.ws.FaultAction;
 
@WebService(name = "AddNumbers", targetNamespace = "http://sample.com/")
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL, parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
interface AddNumbers {
 
    @Action(input = "http://sample.com/input",
            output = "http://sample.com/output")
    public int add(int number1, int number2) throws AddNumbersFault;
 
    public int add2(int number1, int number2) throws AddNumbersFault;
 
    @Action(input = "http://sample.com/input3",
            output = "http://sample.com/output3",
            fault = {@FaultAction(className = AddNumbersFault.class, value = "http://sample.com/fault3")})
    public int add3(int number1, int number2) throws AddNumbersFault;
}

The created AddNumbers.java is saved in the c:\temp\jaxws\works\addressing\server\src\com\sample\ directory with the UTF-8 format.

Next, create the main Web Service that implements SEI. This subsection describes how to calculate the contents of the received request message and create the Web Service Implementation Class com.sample.AddNumbersImpl that is returned as a response message.

The following is an example for creating the main Web Service:

package com.sample;
 
import javax.jws.WebService;
import javax.xml.ws.soap.Addressing;
 
@Addressing
@WebService(endpointInterface = "com.sample.AddNumbers")
public class AddNumbersImpl implements AddNumbers {
    public int add(int number1, int number2) throws AddNumbersFault {
        return impl(number1, number2);
    }
 
    public int add2(int number1, int number2) throws AddNumbersFault {
        return impl(number1, number2);
    }
 
    public int add3(int number1, int number2) throws AddNumbersFault {
        return impl(number1, number2);
    }
    int impl(int number1, int number2) throws AddNumbersFault {
        if (number1 < 0 || number2 < 0) {
            throw new AddNumbersFault("Negative numbers can't be added!",
                                      "Numbers: " + number1 + ", " + number2);
        }
        return number1 + number2;
    }
}

The created AddNumbersImpl.java is saved in the c:\temp\jaxws\works\addressing\server\src\com\sample\ directory with the UTF-8 format.

Also create an exception class com.sample.AddNumbersFault thrown in the com.sample.AddNumbersImpl class.

The following is an example for creating an exception class:

package com.sample;
 
public class AddNumbersFault extends Exception {
 
    String detail;
 
    public AddNumbersFault(String message, String detail) {
        super(message);
        this.detail = detail;
    }
 
    public String getDetail() {
        return detail;
    }
}

The created AddNumbersFault.java is saved in the c:\temp\jaxws\works\addressing\server\src\com\sample\ directory with the UTF-8 format.