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
Software Needed for the Tutorial
To follow this tutorial, you need the following software and resources.
|Software or Resource||Version Required|
Java EE download bundle
version 7 or 8
Java EE-compliant web or application server
Pictures used in this tutorial
*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.
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 email@example.com mailing list.