Hello everyone, welcome to module two, lesson one of the Web Services 2 course. This is the second lesson overall. In this lesson, we'll be developing a JAX-WS web service and we'll also inspect the WSDL that's produced by this JAX-WS endpoint. So like all web services, JAX-WS operates on a client server architecture. It allows developers to implement both parts purely in Java. JAX-WS abstractions allow developers to complete this process using only Java, handling xML responses behind the scenes. In JAX-WS, web services are created using two main components, the service endpoint interface and the service endpoint implementation class. Both can easily be created in JAX-WS using mostly just annotations. However, each must adhere to requirements outlined by JAX-WS. The service endpoint interfaces are regular Java interfaces, they just use a handful of annotations. They let JAX-WS know that the developer is defining an endpoint. In JAX-WS explicitly defining a service endpoint interface is optional. JAX-WS will implicitly generate a service endpoint interface for a service endpoint implementation class if the developer does not explicitly define one. So let's look at an example. In this example, we'll be creating a to do list service. So, first on the left, we've got a to do class that will serve as the pogo that'll store basic information about a single to do item. So each to do list item has an ID, a description, and the time that it was added to the list. It also has getters and setters below, but those are just shown by a comment at the moment. The surface endpoint interface will be a normal Java interface declared using public interface ToDoSEI, SEI for service endpoint interface. At the very top however, goes an annotation @WebService. This is the annotation that tells JAX-WS that this is a service in one interface. For the abstract methods of the interface, we'll also want to add the @WebMethod annotation. This annotation tells JAX-WS that these are methods that a client can use over the internet for this service endpoint interface. So this service endpoint interface has a method that will allow us to add a new to do item to the to do list. It has a method that will show us all the current to do list items. And it has a method that will complete a to do list item and remove it from the list. Service endpoint implementation classes are regular old Java classes with some annotations and they also implement a service endpoint interface. These classes handle the business behaviors required of a JAX-WS endpoint. Like service endpoint interfaces, they're annotated with web service and their methods are exposed using @WebMethod. The only difference is that the service endpoint implementation class provides concrete implementations to the web methods. Here's an example of a service endpoint implementation class. You see it has the web service annotation, but it also initializes the endpoint interface optional element. That optional element is set to the value of the fully qualified class name of the service endpoint interface. So in this case it's going to be com.example.ToDoSEI. Notice that in the class definition we also implement that interface. Now we have to implement the methods who are ToDoImp1. You'll see it delegates off to a ToDoRepository class for data storage and that repository will be used in this first method, addToDo. addToDo is going to take in a string for the description of a to do item and then it will use that description to create a to do object. It will derive the ID for a to do list item from the current size of the repository. It will use the description that's passed in as an argument and it will set the time to the current time in milliseconds. Then it will return the return of the save method from the repository. And the save method in the repository will store that to do to a hash map so that it can be persisted. The other two method implementations for allToDos and completeToDo delegate off to the ToDoRepository. allToDos gets the to do list which is a map with keys of integers and values of to dos and it casts them down to a hash map. The cast is necessary because web methods and JAX-WS cannot return interfaces. They have to return concrete classes. So because hash map is a concrete class, it can be returned but you can't actually return a map in JAX-WS because a map in Java is an interface. Finally, the completeToDo method takes in an int for the idea of the to do item that should be completed or removed. And the first thing it does is find that to do item in the repository using the ID. And then once it is found, it will use that object to delete it from their repository, then it will return the to do that it deleted. As I mentioned, JAX-WS has some requirements that the documentation outlines which implementers must follow. The first of which is that the service endpoint implementation class must be annotated with @WebService. Secondly, the service endpoint implementation class may explicitly define an SEI or if not, one will be provided for it. Methods of the implementation class must be public, the web methods. Methods of the implementation class cannot be final or static. They must be instanc. Methods being exposed in the implementation class must be marked with web method or they can optionally inherit it from the SEI as long as the SEI marks them as web methods. The methods being exposed as web methods must return valid JAXBdata types. You can read about the JAXB data types in the reading section of this lesson. The implementation class must not be final or abstract. The implementation class must have a public zero-argument constructor. The implementation class cannot override finalize and the implementation class can optionally use the @PostConstruct annotation and the @PreDestroy annotation on top of methods that will be used to manage the lifecycle of that implementation class. @PostConstruct is used to define a method that runs before the implementation class response to messages. And @PreDestroy is used to define a method that runs before the implementation classes removed as an endpoint. Finally, let's look at an example of WSDL for a service. So this will be the WSDL returned by our to do service. It can be accessed at http://localhost8080/the name of the project, which in this case is soap-ws-example/the name of the web service, which for us will be ToDoImplService. Notice that the class of the implementation class was actually named ToDoImpl, but JAX-WS will append the word service onto the end of the name of the implementation class for the default name of the endpoint. Finally, to view the WSDL, you must append the query param question mark, WSDL onto the end of the URL. And if you do this correctly, you should be returned an xml document that looks something like the following. Otherwise, you're going to get a 404 error.