uCosminexus Application Server, Web Service Development Guide

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

31.3.1 Creating a Web Service Implementation Class

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

This example describes how to calculate the contents of the received request message and create a Web Service Implementation Class that returns a response message.

The following example shows how to create a Web Service Implementation Class.

package com.sample;
 
import java.awt.Image;
import javax.jws.Web Service;
import javax.xml.ws.soap.MTOM;
import javax.xml.bind.annotation.XmlMimeType;
 
@MTOM
@Web Service(serviceName="UserInfoService",targetNamespace="http://sample.com")
public class UserInfoImpl {
 
    public UserData getUserData(String in0, @XmlMimeType("image/png")Image in1)
        throws UserInfoException {
 
//Register the photograph to employee information
......
 
        UserData userdata = new UserData();
        //Set the registered employee name and affiliation
        if (in0.equals("1")) {
            userdata.setName("HitachiTaro");
            userdata.setSection("The personnel section");
        } if ( ......) {
            ......
    } ......
 
//Set registration confirmation message
        if (in1 == null) {
            userdata.setMessage("Failure(no image).");
        } else {
            userdata.setMessage("Success.");
        }
        return userdata;
}
}

Save the created UserInfoImpl.java in the c:\temp\jaxws\works\mtom\server\src\com\sample\ directory in UTF-8 format.

Also, create a user-defined class com.sample.UserData used in com.sample.UserInfoImpl. Typically, creation of an exception class is optional, but in this example an exception class is created:

The following is an example for creating a user-defined class:

package com.sample;
 
import java.lang.String;
 
public class UserData {
 
    private String message;
    private String name;
    private String section;
 
    public UserData() {
    }
 
    public String getMessage() {
        return this.message;
    }
 
    public void setMessage(String message) {
        this.message = message;
    }
 
    public String getName() {
        return this.name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getSection() {
        return this.section;
    }
 
    public void setSection(String section) {
        this.section = section;
    }
}

The created UserData.java is stored in the c:\temp\jaxws\works\mtom\server\src\com\sample\ directory in UTF-8 format.

Also, create an exception class com.sample.UserInfoException thrown in com.sample.UserInfoImpl. Typically, creation of an exception class is optional, but in this example an exception class is created:

The following is an example for creating an exception class:

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

The created UserInfoException.java class is stored in the c:\temp\jaxws\works\mtom\server\src\com\sample\ directory in UTF-8 format.