uCosminexus Application Server, Web Service Development Guide

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

7.3.1 Creating Web Services Implementation Class

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 the Web Service Implementation Class that returns the response message.

The following is an example of creating a Web Service Implementation Class for SOAP 1.1. The created AddNumbersImpl.java file is saved in the c:\temp\jaxws\works\annotations\server\src\com\sample\ directory with the UTF-8 format.

package com.sample;
 
@javax.jws.WebService(name = "TestJaxWs",
  targetNamespace = "http://example.org/sample",
  serviceName = "TestJaxWsService", portName = "testJaxWs")
@javax.xml.ws.BindingType(javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING)
@javax.jws.soap.SOAPBinding(style = javax.jws.soap.SOAPBinding.Style.DOCUMENT, use = javax.jws.soap.SOAPBinding.Use.LITERAL)
public class AddNumbersImpl{
  
  @javax.jws.WebMethod(operationName = "jaxWsTest1")
  @javax.jws.WebResult(name = "return")
  public int add( @javax.jws.WebParam(name="num1")int number1, @javax.jws.WebParam(name="num2")int number2 ) throws AddNumbersFault{
 
    if( ( number1 < 0 ) || ( number2 < 0 ) ){
      throw new AddNumbersFault( "Negative number cannot be added!",
        "Numbers: " + number1 + ", " + number2 );
    }
    return number1 + number2;
  }
 
}

The exception class com.sample.AddNumbersFault thrown using com.sample.AddNumbersImplwill also be created. Normally, the creation of the exception class is optional, but an exception class will be created here.

The following is an example of creating an exception class. The created AddNumbersFault.java file is saved in the c:\temp\jaxws\works\annotations\server\src\com\sample\ directory with the 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;
  }
}

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

package com.sample;
 
@javax.jws.WebService(name = "TestJaxWs",
    targetNamespace = "http://example.org/sample",
    serviceName = "TestJaxWsService", portName = "testJaxWs")
@javax.xml.ws.BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
@javax.jws.soap.SOAPBinding(style = javax.jws.soap.SOAPBinding.Style.DOCUMENT, use = javax.jws.soap.SOAPBinding.Use.LITERAL)
public class AddNumbersImpl{
    
    @javax.jws.WebMethod(operationName = "jaxWsTest1")
    @javax.jws.WebResult(name = "return")
    public int add( @javax.jws.WebParam(name="num1")int number1, @javax.jws.WebParam(name="num2")int number2 ) throws AddNumbersFault{
 
        if( ( number1 < 0 ) || ( number2 < 0 ) ){
            throw new AddNumbersFault( "Negative number cannot be added!",
                "Numbers: " + number1 + ", " + number2 );
        }
        return number1 + number2;
    }
 
}