uCosminexus Application Server, Web Service Development Guide

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

8.3.1 Creating Web Services Implementation Class(starting from SEI and EJB Web Service)

Create a Web Service Implementation Class that codes the processing of the Web Service.

In this subsection, calculate the contents of the received request message and create a Web Service Implementation Class that returns a response message. Save the created AddNumbersImpl.java to the c:\temp\jaxws\works\statelessjava\server\src\com\sample\ directory in UTF-8 format.

package com.sample;
 
@javax.ejb.Stateless
@javax.jws.Web Service
public class AddNumbersImpl{
 
    public int add( int number1, int number2 ) throws AddNumbersFault{
        
        if( ( number1 < 0 ) || ( number2 < 0 ) ){
            throw new AddNumbersFault( "Negative number cannot be added!",
                "Numbers: " + number1 + ", " + number2 );
        }
        return number1 + number2;
    }
 
}

Also, create an exception class com.sample.AddNumbersFault thrown in com.sample.AddNumbersImpl. Usually, creating the exception class is optional. We will however, create the exception class in this example.

The following is an example of creating an exception class. Save the created AddNumbersFault.java in the c:\temp\jaxws\works\statelessjava\server\src\com\sample\ directory in UTF-8 format.

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;
    }
}