Web Service Implementation

Now that the Web Service interfaces are defined (HelloWorld.java,FileManagement.java), let's look at their implementation details.

  • The HelloWorldImpl.java implements HelloWorld.java and returns the string message. Notice the annotation @WebService(endpointInterface = "com.yosanai.tutorial.ws.hellowebservice.HelloWorld") which basically defines the end points interface contract.
    package com.yosanai.tutorial.ws.hellowebservice;
    
    import javax.jws.WebService;
    
    /**
     * @author Saravana P Shanmugam
     * 
     */
    @WebService(endpointInterface = "com.yosanai.tutorial.ws.hellowebservice.HelloWorld")
    public class HelloWorldImpl implements HelloWorld {
    
    	public String sayHi(String text) {
    		return "Hello " + text;
    	}
    }
    
  • Similarly the FileManagementImpl.java implements FileManagement.java and receives the incoming File.java object; reads the file content present in it and returns a string message with the file name and file length in it. Notice the annotation @WebService(endpointInterface = "com.yosanai.tutorial.ws.hellowebservice.FileManagement") which defines the end points interface contract.
    package com.yosanai.tutorial.ws.hellowebservice;
    
    import java.io.InputStream;
    
    import javax.jws.WebService;
    
    import org.apache.cxf.helpers.IOUtils;
    
    /**
     * @author Saravana P Shanmugam
     * 
     */
    @WebService(endpointInterface = "com.yosanai.tutorial.ws.hellowebservice.FileManagement")
    public class FileManagementImpl implements FileManagement {
    
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see
    	 * com.yosanai.tutorial.ws.hellowebservice.FileManagement#upload(com.yosanai
    	 * .tutorial.ws.hellowebservice.File)
    	 */
    	@Override
    	public String upload(File file) throws Exception {
    		String ret = null;
    		InputStream ins = file.getFileContent().getInputStream();
    		byte[] bytes = IOUtils.readBytesFromStream(ins);
    		ret = "Read " + bytes.length + " bytes of data from the uploaded file "
    				+ file.getFileName();
    		return ret;
    	}
    
    }
    
  • That's it the web service implementation is done :-). With simple annotations we have exposed the web service.

Who's online

There are currently 0 users and 1 guest online.

Who's new

  • Saravana Peruma...