Notes

You want to do something new with IoT, RFID ?. Drop me a message :).

Monday, June 5, 2017

SOAP and Restful web services with CXF and Spring Framework

This is a simple web application combination of SOAP and Restful webservices in CXF and Spring framework.
Configuration using annotations makes development a webservies application really simple and fast. It is a big change from the past when there were lot of steps need to be done to build a webservices application.
There are two packages in the Maven project. restful.services for Restful services and soap.services for SOAP services.


The configurations for restful and soap webservices have been done in both two interfaces and cxf-beans.xml which is located in \src\main\webapp\WEB-INF\cxf-beans.xml.


Also to configure the CXFServlet in web.xml which will handle all http requests from webservice consumers.
To build project, right click on POM file and select Run As -> Maven Build. 
To copy generated war file (CXFwebservicesMaven-1.0.0.war) to a web server as Tomcat and startup the web server to deploy the application and publish the web services.

Testing:
SOAP services endpoint:
http://localhost:8080/CXFwebservicesMaven-1.0.0/soapservices?wsdl


Restful services endpoint:
http://localhost:8080/CXFwebservicesMaven-1.0.0/restservices


Above is GET request. To test for the POST request, you may use SoapUI (https://www.soapui.org) tool to send the data. SoapUI also supports to call a SOAP service, of course as its name :)).


Go to http://localhost:8080/CXFwebservicesMaven-1.0.0/ to see service list of the application.


The main change here is that we no need a WSDL file to generate stuffs for server side. This has been done in run time by JAX-WS integrated in JDK.

Source code in Github.

No comments: