In this section, you create an EE6 web application. To this application, you add the images that the web service will pass as binary data.
To create the web application:
Choose File > New Project (Ctrl-Shift-N on Linux and Windows, ⌘-Shift-N on MacOS). The
New Project wizard appears. Select
Web Application from the Java Web category and click Next. The Name and Location page opens.
Type FlowerAlbumService in the Project Name field. Select the location you want for this project. Keep the default settings for the other options and click Next.
The Server and Settings page opens.
Select the GlassFish server 3.1 and Java EE version EE6 Web.
Important: The GlassFish Server Open Source Edition must be Version 3.1 b27 or later. The customized schema
file you create in Modifying the Schema and WSDL Files does not work in GlassFish server 3.0.1. Check the version of your the GlassFish server server in the Services window.
Click Finish. The FlowerAlbumService project is created and appears in the Projects window.
Right-click the Source Packages node and select New > Java Package. The New Java Package wizard opens.
Name the package org.flower.resources.
Click Finish.
Copy the
following images into org.flower.resources:
The project now has the package org.flower.resources in the Source Package. No other contents have been added.
Adding the Web Service
In this section you create a web service in the web application. You create the service as a stateless session bean. You add the following web operations to the service:
An operation that takes the name of a flower and gets its associated Image.
An operation that gets thumbnails of all the flower images and return them as a List.
To add the web service:
In the Projects window, right-click the FlowerAlbumService project 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 org.flower.service in Package Name.
Select Create Web Service from Scratch. Select Implement Service as Stateless Session Bean.
Click Finish.
The web service appears in the project's nodes in the Projects window. The Source Packages directory includes the service package and the resources package.
Open FlowerService.java in the editor. Switch to the Design view. A form appears in which you can add operations and quality of service elements to the web service.
Click Add Operation. The Add Operation wizard opens.
Name the operation getFlower. In the Return Type field, type or browse for java.awt.Image.
In the Parameters tab, click Add. Name the parameter name
and accept the default java.lang.String type.
Open the Exceptions tab. Add an IOException.
Click OK and close the wizard. Then click Add Operation again, and add an operation with the following properties:
Name: getThumbnails
Return type: java.util.List
Exception: IOException
The Design view now shows the getFlower and getThumbnails operations. Switch to the List View of both operations and you see all their parameters.
To send comments and suggestions, get support, and keep informed about the latest
developments on the NetBeans IDE Java EE development features, join
the mailing list.