The goal of this tutorial is to create a web application
that contains a web service. The web service should delegate
to the previously-created EJB module for the retrieval of images. Therefore,
you need to put the EJB module on the web application's
classpath.
In the following procedure, you create the web service for this learning trail. The web service uses the previously created EJB module to retrieve binary data.
To create the web service:
Choose File > New Project (Ctrl-Shift-N). The
New Project wizard appears. Select
Java Webfrom the Web category. Click
Next. The Name and Location page opens.
Type FlowerService in the Project Name field. Select the location you want for this project—use the same location for the other projects you create for this end-to-end application. Keep the default settings for the other options and click Next.
The Server and Settings page opens.
Select the application server and Java EE version. This must be the same for all projects in the end-to-end application. Click Finish. The IDE creates a new web application project.
Put the EJB module on the web application project's classpath, so that the web service you are creating has access to the EJB module. First, right-click
the web application's Libraries node and choose Add Project, as
shown below.
Next, browse to the EJB module and select it. You should now see a new
node, for the EJB module, added to the web application's Libraries
node, as below.
Right-click the FlowerService node and choose New > Web Service.
Alternatively, choose New > Other and then select Web Service
under Web Services in the New File wizard. The New Web Service wizard opens.
In the New Web Service wizard, type FlowerService in
Web Service Name and flower.album in Package Name.
Select Create Web Service from Existing Session Bean
and then browse to the EJB module and select it, as below.
Click OK in the Browse Enterprise Bean dialog. You return to the New Web Service wizard. Click Finish. The IDE adds the infrastructure of a web service
to your application, which includes stubs for the methods
obtained from the EJB module, as shown here.
Click the Design toggle button in the top left corner
of the editor. The Web Service Visual Designer is shown, as
below.
You can use the Web Service Visual Designer
to see the structure of your web service in one
glance. In addition, you can add functionality
to your web service by clicking buttons such
as Add Operation. By using the Quality of Service
section, you can very easily enable advanced features, such
as web service security.
Click the Source toggle button to switch back to
the Source view. Rewrite the class so that it looks as follows.
To send comments and suggestions, get support, and keep informed on the latest
developments on the NetBeans IDE Java EE development features, join
the mailing list.