Web services for Java EE 5 in Glassfish (3)

02:03AM jun 04, 2007 en categoria Java por Enrique Rodriguez Lasterra

Etiquetas:


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

Attending beginning Client on watch Web with Netbeans 6

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.

Attending Client on watch Web with Netbeans 6, description selection in project

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.

Direction of the WSDL in the console of administration of Glassfish To stick the direction of the WSDL in the field of the assistant and to specify the package

We must specify the package that will be assigned to the code generated by the assistant, in my case:

org.lasterra.glassfish.client
When we click Finish button, Netbeans call task wsimport of JAX-WS and add a Web service reference to the project

Generation of code through wsimport and visualization of reference to the service Web in 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

To drag the operation of the service Web to the place where to make the call Code generated by Netbeans to make the call

We only have to assign values to parameters of the Web service, and executing JSP, we obtain the result

Result called to extreme service Web

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:

Location code generated by wsimport in Netbeans 6

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.

Comentarios:

Enviar un comentario:
Los comentarios han sido deshabilitados.