Web Service Application Passing Binary Data, pt 1: Overview
In this tutorial, you create
an EE6 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. Unlike the case with Java EE5, in EE6 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 (Due to a bug, you cannot use 3.0.1.) 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.
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.
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.
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.