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”
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
Step 3: By default, there will be “src” folder
Step 4: check “Generate web.xml DD” and Click Finish
Step 5: Initial project structure (Eclipse Package Explorer view)
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
Step 8: Configure required parameters
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
Step 10: accept default and click Next
Step 11: Click “Start Server”
Step 12: This is optional –> accept default and click Finish
Step 13: After clicking Finish in the above step –> project structure
Project Structure after above steps
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
Step 16: Click BookServiceImpl to view wsdl of the deployed book service
Step 17: BookServiceImpl.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
Step 20: Input the request ISBN as “ISBN-2134”
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 !!