Web Service Application Passing Binary Data, pt 1: Overview

In this tutorial, you create a Java EE web application that contains a web service, which you implement as a stateless session bean. You also add a package with four JPEG files to the web application. The web service has two operations that are accessible by clients, for getting individual images and for getting a set of all 4 images as thumbnails. You add private methods that convert the JPEG files to byte arrays and convert those byte arrays to Image objects. In Java EE you put these private methods directly in the web service, because the web service is also an EJB.

After you create the web service, you deploy it to an instance of the GlassFish server 3.1 or later. You use the NetBeans IDE's built-in web service tester to view sample SOAP request and response messages.

The default JAX-WS service infrastructure cannot inform clients that the binary data needs to be interpreted as JPEG files. Therefore, you generate a copy of the XML Schema and WSDL files and edit the XML schema to tell any client to expect the image/jpeg content type for the return element. You also alter the service code to use the customized WSDL and Schema.

Finally, you create a Java client application that displays the images in an album created from Swing components.

You can download a complete version of service and client applications from the NetBeans Samples Catalog.

Lessons In This Tutorial

Content on this page applies to NetBeans IDE 7.2, 7.3, 7.4 and 8.0
  1. => Overview
  2. Creating the Web Service
  3. Coding and Testing the Web Service
  4. Modifying the Schema and WSDL Files to Pass Binary Data
  5. Creating the Swing Client

Software Needed for the Tutorial

To follow this tutorial, you need the following software and resources.

Software or Resource Version Required
NetBeans IDE Java EE download bundle
Java Development Kit (JDK) version 7 or 8
Java EE-compliant web or application server GlassFish Server Open Source Edition 3.1 or later
Pictures used in this tutorial rose.jpg
sunflower.jpg
aster.jpg
honeysuckle.jpg

Note: the GlassFish server can be installed with the Java EE download bundle of NetBeans IDE. Alternatively, you can visit the the GlassFish server downloads page.

Tip: Optionally, for troubleshooting purposes, you can download the completed sample and inspect the sources.

At the end of this tutorial, you will have a running Java Swing application that consumes JPEG images via a web service, with the result displayed below.

JFrame showing all flower images passed from web service

Next step:

Creating the Web Service


See Also

For background information prior to using this tutorial, see the following resources:

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.

get support for the NetBeans

Support


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo