Web Services with Java EE
|
|
|
With this article we start a new article series about Web Services from the basics to the advanced techniques to test web services with Mock objects and frameworks like arquillian.
This sample service will serve as a base to delve into all the aspect of Web Services in the Java world. The service used as a sample is decoding an IBAN (International Banking Account Number) into all its constituent parts. The resulting object in an Account data object containing the decoded information contained in the IBAN.
In the following example we will use the built-in JAX-WS api contained in the JDK. JAX-WS means Java Api for XML Web Services .JAX-WS replaced the JAX-RPC api in Java EE5.
Iban decoder service
Let's start by declaring our Web service using the JAX-WS api.
In line 7 we are declaring the class as a Web service using the java.jws.WebService annotation. The purpose of this annotation is to mark this class as implementing a Web Service, or a java interface as defining a Web service interface.
Line 8, we are defining the name of the Web Service used as the name of the wsdl:portType according to WSDL 1.1.
Line 9 is defining the service name of the Web Service used as the name of the wsdl:service when mapped to WSDL 1.1
Line 10 we are defining the XML namespace used for the WSDL and XML elements generated from this Web
Service.
To make it available at runtime without processing annotations we are using static string.
Line 17 we are declaring the following method as a WebMethod using the java.jws.WebMethod annotation.
@WebMethod annotation customizes a method that is exposed as a Web Service operation.
Line 18 with the @WebParam annotation we are customizing the mapping of the iban parameter to a Web Service message part and XML element.
Our new service deployed
We will cover the deployment of our service in another article in this serie. In this chapter we will simply describe the artifacts available.
We have deployed our Web Service in a Web application using the context root /sample. To get a description of our Web Services available we are calling the following url :
http://localhost:8080/sample/AccountService?wsdl
As a result we have received an XMl based interface description called WDSL description. It provides a machine-readable description of how the service can be called, what parameters it expects, and what data structures it returns. It thus serves a roughly similar purpose as a method signature in a programming language.
This is the end of the first article dedicated to Web services development using Java and JAX-WS.
If you have any remark or questions feel free to put a comment.If you enjoyed this tutorial and want to promote it don't hesitate to click on
t: TNUQDKPZCMUG
Tags: java , import , object , jax-ws , account , service , services , iban , contained