Using attachment types with web services
In use case scenarios, we may need to transfer documents, media, and other files with web services. These kinds of elements are defined with Multipurpose Internet Mail Extensions (MIME) types. The JAX-WS specification enables the Message Transmission Optimization Mechanism (MTOM) feature which enables efficient transfer of binary content via SOAP messages. This recipe explains how to use the MIME types with web services.
Getting ready
We will amend the example from the Creating literal and encoded web services recipe in order to complete this recipe.
How to do it…
To show the usage of MIME types in a web service, we will implement an additional method that enables the upload of an eBook to the book
library:
Open the
BookLibrary
interface and add the following code:@WebMethod public void uploadBook(String bookName, DataHandler data);
Open
BookLibraryImpl
and amend the code with the following lines. We first need to decorate the class with the@MTOM
annotation...