Web services for Java EE 5 in Glassfish (3)
We have already seen how can we do a Web Service in JavaEE 5 and we have dived on the "not" generated code. Now we will see how can we develop a client of the Web service using netbeans 6. Thanks to netbeans we are going to see how easy is generate a client, we did not need to know JSRs, nor specifications, We only need the address of the Web service, the hard side is work for Netbeans and JAX-WS.
The client of the Web service will be another Web application, so the first step is to create a new project. Once we have created it, we create a client of the Web service using netbeans wizard
The wizard gives three options to introduce the address of the Web service descriptor, WSDL. In our case, server and client are Netbeans projects so we can select the first option, project. Netbeans shows us the list of projects with Web services, and we only must select the Web service for which we want generate the client.
The other option, and the one that is commonly used, is introduce the address of the service descriptor. As We already saw in previous days, we can copy the address from the administration console of Glassfish and then we introduce it on the wizard.
We must specify the package that will be assigned to the code generated by the assistant, in my case:
org.lasterra.glassfish.clientWhen we click Finish button, Netbeans call task wsimport of JAX-WS and add a Web service reference to the project
In order to finalize the example we have to locate the place where we want call to the Web service operation. For the example we selected the index JSP and we dragged the add operation there
We only have to assign values to parameters of the Web service, and executing JSP, we obtain the result
I want to stress that in this occasion exist genrerated code form wsimport tool of JAX-WS. Netbeans stores it in a folder that is not seen from the main view of the project. I do not like much this idea to hide the code, but the certain thing is that we do not have any necessity to modify it. In any case its location is the following one:
It is interesting to see this code, also with annotations JSR-175:
- A class with annotation @WebServiceClient, that makes the effects of Stub client of the service Web.
- An interface of the service Web, with annotation @WebService
- Several classes related to the Java-XML mapping through JAXB
You will be agree with me that it is impossible to make it easier.














