Apache Axis2: JAX-WS based Web Service using Bottom-Up approach

In this article, we will implement/develop SOAP based Web Service using Apache Axis2 reference implementation

Basically, we got two options while developing/implementation of SOAP Web Service

  • Top-Down approach or Contract first
  • Bottom-UP approach or Code first

We will concentrate on the second approach i.e.; Bottom-UP approach. Often developer community finds developing SOAP based Web Service using bottom-up lot easier comparing the former contract based approach

It’s considered a standard approach to design WSDL contract document collaborating with architects, designer and governance team in a large enterprise application, where possibly there could be multiple interactions amongst exposed services. Anyways, it is purely design choice

Note: For simple use case, we can use command line interface to generate java artifacts

Technology Used

  • Java 1.7
  • Eclipse Kepler IDE
  • Apache Axis2-1.6.2
  • Apache Tomcat-8.0.12

Pre-requisite

  • Configure Apache Axis2 plugin in Eclipse IDE
  • Configure Apache Tomcat server in Eclipse IDE

Refer this article for configuring Axis2 plugin in Eclipse IDE

 

We will move on developing bottom-up approach using above configuration

Step 1: In Eclipse, create new “Dynamic Web Project”

1_Apache-Axis2-JAX-WS-Bottom-Up_new_dynamic_web_project

Step 2: Provide “Project Name” and make sure to change the “Dynamic web module version” to 2.5 –> click Next
Reason: Apache Axis2 doesn’t work above 2.5 even with the latest version-1.6.2

2_Apache-Axis2-JAX-WS-Bottom-Up_new_dynamic_web_project_wizard

Step 3: By default, there will be “src” folder

3_Apache-Axis2-JAX-WS-Bottom-Up_new_dynamic_web_project_default_folder

Step 4: check “Generate web.xml DD” and Click Finish

4_Apache-Axis2-JAX-WS-Bottom-Up_new_dynamic_web_xml

Step 5: Initial project structure (Eclipse Package Explorer view)

5_Apache-Axis2-JAX-WS-Bottom-Up_initial_project_structure

Step 6: Add implementation class

BookServiceImpl.class

package com.apache.axis2.endpoint;

public class BookServiceImpl {

	public String getBookByISBNRequestNumber(String isbnNumber) {

		if(isbnNumber.equalsIgnoreCase("ISBN-2134")) {
			return "Microbiology";
		}
		return "Invalid_ISBN_Number";
	}
}

Step 7: Right Click on Project –> New –> Web Service

6_Apache-Axis2-JAX-WS-Bottom-Up_web_service_wizard

Step 8: Configure required parameters

7_Apache-Axis2-JAX-WS-Bottom-Up_web_service_wizard_default

Step 9: Configuring parameters as below for this approach

Web service type: Bottom Up Java bean Web Service
Service implementation: browse through Java implementation class here
Configuration:

  • Server runtime: Tomcat 8.x server
  • Web service runtime: Apache Axis2
  • Service project: Project-name

8_Apache-Axis2-JAX-WS-Bottom-Up_web_service_wizard_change_settings

Step 10: accept default and click Next

9_Apache-Axis2-JAX-WS-Bottom-Up_web_service_wizard_accept_default

Step 11: Click “Start Server

10_Apache-Axis2-JAX-WS-Bottom-Up_web_service_wizard_start_server

Step 12: This is optional –> accept default and click Finish

11_Apache-Axis2-JAX-WS-Bottom-Up_web_service_wizard_accept_default_uddi

Step 13: After clicking Finish in the above step –> project structure

Project Structure after above steps

12_Apache-Axis2-JAX-WS-Bottom-Up_project_structure_after_generated_artifacts

Step 14: Web service implemented –> deploy the service to tomcat server

Deployment

Right click on project –> Run As –> Run on Server
Check whether web service is correctly deployed or not?

Step 15: This is home page, after deploying axis2 based web service in tomcat server. Click services

13_Apache-Axis2-JAX-WS-Bottom-Up_axis2_home_page

Step 16: Click BookServiceImpl to view wsdl of the deployed book service

14_Apache-Axis2-JAX-WS-Bottom-Up_axis2_click_services

Step 17: BookServiceImpl.wsdl

15_Apache-Axis2-JAX-WS-Bottom-Up_axis2_click_services_wsdl

Step 18: With the above steps, a simple SOAP Web Service implemented and deployed onto the tomcat server successfully

Step 19: Testing using SOAP UI –> Get the endpoint URL and load into SOAP UI

16_Apache-Axis2-JAX-WS-Bottom-Up_axis2_services_wsdl_soap_1

17_Apache-Axis2-JAX-WS-Bottom-Up_axis2_services_wsdl_soap_2

Step 20: Input the request ISBN as “ISBN-2134”

18_Apache-Axis2-JAX-WS-Bottom-Up_axis2_services_wsdl_soap_3

Request XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
	xmlns:end="http://endpoint.axis2.apache.com">
	<soapenv:Header />
	<soapenv:Body>
		<end:getBookByISBNRequestNumber>
			<!--Optional: -->
			<end:isbnNumber>ISBN-2134</end:isbnNumber>
		</end:getBookByISBNRequestNumber>
	</soapenv:Body>
</soapenv:Envelope>

Response XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
	<soapenv:Body>
		<ns:getBookByISBNRequestNumberResponse
			xmlns:ns="http://endpoint.axis2.apache.com">
			<ns:return>Microbiology</ns:return>
		</ns:getBookByISBNRequestNumberResponse>
	</soapenv:Body>
</soapenv:Envelope>

Conclusion: Simple JAX-WS based web service implemented, deployed and tested for bottom-up approach using Apache Axis2 Reference Implementation

Download project

Apache-Axis2-JAX-WS-Bottom-Up (154kB)

Happy Coding !!
Happy Learning !!

Apache Axis2: JAX-WS based Web Service using Top-Down approach