uCosminexus Application Server, Web Service Development Guide
Create a new 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 the response message.
The following is an example for creating a Web Service Implementation Class in SOAP 1.1. The created AddNumbersImpl.java is stored in the c:\temp\jaxws\works\fromjava\server\src\com\sample\ directory with the UTF-8 format.
package com.sample;
@javax.jws.WebService
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;
}
}
|
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 is created in this subsection.
The following is an example of the creation of an exception class. The created AddNumbersFault.java is stored in the c:\temp\jaxws\works\fromjava\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
@javax.xml.ws.BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
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;
}
}
|
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.