blob: 871301a98fe1bf39b75df711c39e27ad60f2f4d6 [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= End-to-End Binary SOAP Attachment 2: Creating the Web Service
:jbake-type: tutorial
:jbake-tags: tutorials
:jbake-status: published
:icons: font
:syntax: true
:source-highlighter: pygments
:toc: left
:toc-title:
:description: End-to-End Binary SOAP Attachment 2: Creating the Web Service - Apache NetBeans
:keywords: Apache NetBeans, Tutorials, End-to-End Binary SOAP Attachment 2: Creating the Web Service
The goal of this lesson is to create a web application that contains a web service. You implement the web service as a stateless session bean.
You can download a complete sample of the web service from the link:https://netbeans.org/projects/samples/downloads/download/Samples%252FWeb%2520Services%252FWeb%2520Service%2520Passing%2520Binary%2520Data%2520--%2520EE6%252FFlowerAlbumService.zip[+NetBeans Samples Catalog+].
*Lessons In This Tutorial*
image::images/netbeans-stamp-80-74-73.png[title="Content on this page applies to the NetBeans IDE 7.2, 7.3, 7.4 and 8.0"]
1. link:./flower_overview.html[+Overview+]
2. => Creating the Web Service
3. link:flower-code-ws.html[+Coding and Testing the Web Service+]
4. link:./flower_wsdl_schema.html[+ Modifying the Schema and WSDL Files to Pass Binary Data+]
5. link:./flower_swing.html[+ Creating the Swing Client+]
[start=1]
1. <<create-web-app,Creating the Web Application>>
2. <<add-ws,Adding the Web Service>>
[[create-web-app]]
== Creating the Web Application
In this section, you create a Java EE web application. To this application, you add the images that the web service will pass as binary data.
*To create the web application:*
1. 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.
2. 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.
3. Select the GlassFish server and Java EE version Java EE 6 Web or Java EE 7 Web.
4. Click Finish. The ``FlowerAlbumService`` project is created and appears in the Projects window.
5. Right-click the Source Packages node and select New > Java Package.
Alternatively, select New > Other and select Java Package in the Java category of the New File wizard.
[start=6]
. Name the package ``org.flower.resources`` . Click Finish.
image::images/new-package.png[]
[start=7]
. Copy the following images into ``org.flower.resources`` :
* link:images/rose.jpg[+rose.jpg+]
* link:images/sunflower.jpg[+sunflower.jpg+]
* link:images/aster.jpg[+aster.jpg+]
* link:images/honeysuckle.jpg[+honeysuckle.jpg+]
The project now has the package ``org.flower.resources`` in the Source Package. No other contents have been added.
image::images/project-w-resources.png[]
[[add-ws]]
== 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:*
1. 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.
2. 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.
image::images/new-service.png[]
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.
image::images/project-w-service-and-resources.png[]
[start=3]
. 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.
image::images/flower-service-empty-design.png[]
[start=4]
. Click Add Operation. The Add Operation wizard opens.
[start=5]
. Name the operation ``getFlower`` . In the Return Type field, type or browse for ``java.awt.Image`` .
[start=6]
. In the Parameters tab, click Add. Name the parameter ``name`` and accept the default ``java.lang.String`` type.
image::images/add-getflower-param.png[]
[start=7]
. Open the Exceptions tab. Add an ``IOException`` .
image::images/io-exception.png[]
[start=8]
. 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.
image::images/flower-service-full-design.png[]
==  
== Next step:
link:./flower-code-ws.html[+Coding and Testing the Web Service+]
link:/about/contact_form.html?to=3&subject=Feedback:%20Flower%20Creating%20WS%20EE6[+Send Feedback on This Tutorial+]
To send comments and suggestions, get support, and keep informed about the latest developments on the NetBeans IDE Java EE development features, link:../../../community/lists/top.html[+join the nbj2ee@netbeans.org mailing list+].