JAX-WS: Hello World With Tomcat – RPC Style

Connect with

RPC style web service exampleRPC style web service example, JAX-WS hello world RPC style, is a way of producing and consuming SOAP styled Java web service.

1. Overview of RPC style web service example

JAX-WS is a successor of JAX-RPC (Java API for Remote Procedure Call). RPC style web service example is one of the ways of creating JAX-WS Java web service. In this RPC style web service example you know how RPC style of web service works and how you expose java web service.
In this post, we go through basic of JAX-WS, we are not coverting any build tool i.e. maven , gradle , ant or any another for creating jax-ws artifacts. we use wsgen command line utility tool to create jaxb artifact for input request and output response class.

2. Environment & Technologies

This is a JAX-WS hello world RPC style example and I have tested this rpc style web service example with following environment:

  • Eclipse IDE
  • JDK 7
  • Tomcat 7
  • wsgen

3. Steps to Create and deploye JAX-WS Hello World RPC style

step #1. create DynamicWeb project in Eclipse

Step #2. copy jar files (jaxb-api.jar, jaxb-impl.jar, jaxws-rt, stax-ex.jar, streambuffer.jar) into application lib (i.e. /WEB-INF/lib/) folder.

Step #3. Write java web services class i.e. SEI (Service Endpoint Interface) and SEB (Service endpoint Bean)

Step #4. write sun-jaxws.xml (SUN java web services deployment descriptor) under you project i.e.

Step #5. generate JAXB artifact or classes for input and output types using wsgen by using command-line utility or any other way.

Step #6. copy generated files into a package i.e. JAXB or JAX-WS(com.mysoftkey.helloworld.jaxws) of your application

Step #7. deploy the application in you webserver (Tomcat )

4. Directory Structure of JAX-WS hello world RPC style

Following are the directory structure for RPC style web service example.

 
HelloWorldWS
│   .classpath
│   .project
│   readMe.txt
│
├───src
│   └───com
│       └───mysoftkey
│           └───jaxws
│               └───hellowold
│                   │   HelloWorld.java
│                   │   HelloWorldImpl.java
│                   │
│                   └───jaxws
│                           SayHelloWorld.java
│                           SayHelloWorldResponse.java
│
└───WebContent
    └───WEB-INF
        │   sun-jaxws.xml
        │   web.xml
        │
        ├───classes
        │   └───com
        │       └───mysoftkey
        │           └───jaxws
        │               └───hellowold
        │                   │   HelloWorld.class
        │                   │   HelloWorldImpl.class
        │                   │
        │                   └───jaxws
        │                           SayHelloWorld.class
        │                           SayHelloWorldResponse.class
        │
        └───lib
                jaxb-api.jar
                jaxb-impl.jar
                jaxb-xjc.jar
                jaxws-api.jar
                jaxws-rt.jar
                jaxws-tools.jar
                stax-ex.jar
                streambuffer.jar


5. SEI (Service Endpoint Interface)

Service Endpoint Interface (SEI) of RPC style web service example deployed in Tomcat web server.
File: HelloWorld.java

 
package com.mysoftkey.jaxws.hellowold;
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService // SEI (Service Endpoint Interface) SIB (Service Implementation Bean)
public interface HelloWorld {

	//@WebMethod(exclude=true)
	@WebMethod
	public String sayHelloWorld(String name);
}

6. SIB (Service Implementation Bean) class

File: HelloWorldImpl .java

 
package com.mysoftkey.jaxws.hellowold;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(endpointInterface = "com.mysoftkey.jaxws.hellowold.HelloWorld")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class HelloWorldImpl implements HelloWorld {

 //@WebMethod()
 public String sayHelloWorld(String name) {
  return "Hello world JAX-WS, " + name;
 }

}

7. Web Deployment Descriptor web.xml

 


     HelloWorldWS
    	 	 	 	 	 	 	 	 	 	 	 	 	 	
      	 	 	 	 	 	 	 	 	 	 	 	 	 	
        com.sun.xml.ws.transport.http.servlet.WSServletContextListener
     
   
  
   
      HelloWorldWS
      
        com.sun.xml.ws.transport.http.servlet.WSServlet
      
   
  
   
     HelloWorldWS
     /HelloWorldWS
   
   

8. Sun Java webservice deployement descriptor (sun-jaxws.xml)

sun-jaxws.xml is a proprietary deployment descriptor which is needed when java web services are deployed as a standard WAR (as .war fashioned) on a non-Java EE5 servlet container using the SUN’s reference implementation.

Sun’s RI (Reference implementation) uses WSServletContextListener as the listener for servlet context events and WSServlet as the dispatcher servlet( like spring Front controller or any frontController); both of which have to be mentioned in web.xml (web deployment descriptor). The sun-jaxws.xml file is then required to define web service end points for the WSServlet to let it know to which end point a service request must be dispatched.

In this way, web services can be run in any JAX-WS RI enabled servlet container, although they won’t be portable.
File: sun-jaxws.xml

 


  
  
     
 

Note: in the above wsdlLocation is optional attribute under endpoint element of sun-jaxws.xml.

9. Create JAXB artifact using wsgen tool

step #1. open cmd/terminal ( window/linux)
follow any one of the following steps
– Go up to src (e:\workspace\HelloWorldWS\src\) till com folder and run following
– wsgen
step #2.

 

10. Deploy web application in Tomcat

There are different approaches to deploying web applications but I have choosen to deploy this JAX-WS hello world RPC style example in Apache Tomcat. You can choose any one of your comfortable web servers to deploy.
– build a .war file and copy in ${tomcat}/webapp/ folder and restart the tomcat
– configure local server of Tomcat under Eclipse to run web project

11. Access JAX-WS web Application

Now you are ready to access java JAX-WS hello world RPC style example web service. There is a different way of running the Java Web service application.

URL: http://localhost:8080/HelloWorldWS/HelloWorldWS
Web Services

Port Name : HelloWorldWS,
Status: ACTIVE ,
Information: Address: http://localhost:8080/HelloWorldWS/HelloWorldWS
WSDL: http://localhost:8080/HelloWorldWS/HelloWorldWS?wsdl
Port QName: {http://hellowold.jaxws.mysoftkey.com/}HelloWorldImplPort
Implementation class: com.mysoftkey.jaxws.hellowold.HelloWorldImpl

12. WSDL (Web Service Deployement Descriptor Language)

 


	
	
	
	


	


	



	
		
		
	



  
  
   
   
     
   
   
     
   
  



  
    
  


13. XSD (XML Schema Definition) for hello world RPC style

Generated XSD can be accessed via following URL.

XSD URL: http://localhost:8080/HelloWorldWS/HelloWorldWS?xsd=1

 








  
	
  



  
	
  


14. Run RPC style web service example

There are different way of accessing web service as:
– by using SOAPUI
– Generate java client by using wsdl (http://localhost:8080/HelloWorldWS/HelloWorldWS?wsdl )

15. Download

You can download this source code from github. open git terminal and run following code

 
git clone https://github.com/ranrose/HelloWorldWS.git

or you can download source code of Hello Wold WS web project from mysoftkey portal.

16. Reference for Java RPC style web service example

For more details of Java RPC style web service example you can visit Java JAX-WS RPC style web service

Thanks for visiting this article for RPC style web service.
Happy Learning 🙂 for Java web service example, you can visit JAX-WS web services tutorial page.
Your comments are welcome to improve this post. Happy Learning! 🙂


Connect with

4 thoughts on “JAX-WS: Hello World With Tomcat – RPC Style”

Leave a Comment

Your email address will not be published. Required fields are marked *