In tutorial you will learn to publish and consume SOAP based JAXWS webservice using maven
SOAP stands for Simple Object Access Protocol, it's a transport protocol based on XML and HTTP. It sends and receives requests and responses.
WSDL or Web Services Description Language is an XML notation for describing a web service.
JaxWS stands for Java API for XML Web Services. It builds web services and clients that communicate using XML.
SoapUI is an API Testing Tool, it is used for RESTful Web Services or HTTP based services as well as SOAP Web Services.
- A web service
- A JAXWS server
- SoapUI for testing purposes
Add a new java class, let's call it StarwarsCharacter
Now add another java class and let's call this one StarwarsService.
Within this class declare these 2 methods:
getStarwarsCharacter(): returns a new StarwarsCharacter
starwarsCharacterList(): returns a new list of StarwarsCharacters
This class is going to serve as our Webservice endpoint. In order to do that annotate it with the @Webservice annotation. And to expose its 2 methods to web service clients we're going to annotate each of them with the @WebMethod annotation.
But before we can do any of that add this dependency to you POM.XL file:
<!-- https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-ri -->
Our class should look like this:
Now let's deploy our webservice
Add a Server class that will publish the webservice endpoint to accept incoming requests using the method publish()
This method takes as arguments: the http server address and an instance of the webservice.
It return an http server that runs on the port passed in the address parameter and it is used to access the webservice passed as the implementor parameter.
To access the wsdl :
Link to download SoapUI:
To test the first method make a request and pass it your arguments
On to the next method, this one doesn't take any arguments:
Create a new project and add the JAX dependency to the POM.XML file
Before we can proceed you need to install this plugin
Search for Generate Java code from Wsdl
It's going to generate the java classes inside your package
Add a new class that's going to use a middleware to consume your webservice
Result is as follows :