Before you start
Binary data with SOAP messages is send in Base64 format because SAOP messages are based on plain text, so when binary data is converted into Base64 than its size is increased. And, in case of large attachment this kills the application and brings down the server with memory problems. MTOM (SOAP Message Transmission Optimization Mechanism) which encodes binary data in base64Binary and sends the data as binary attachment rather than keeping it with actual SOAP message MTOM provides an elegant mechanism to transfer binary data such as PDF, Doc, images, and other document types. MTOM uses XML-binary Optimized Packaging (XOP) packages for transmitting binary data. CXF provides support of MTOM with XOP implementation.
This tutorial, the last of a three-part series, explains how to develop a File uploading web service using Apache CXF.
This tutorial series teaches the basic concepts of web services using different SOAP engines like Apache AXIS2, Apache CXF and JAX-WS. This tutorial series also provides a solution for sending large attachment with SOAP messages by using MTOM (SOAP Message Transmission Optimization Mechanism) which encodes binary data in base64Binary and sends the data as binary attachment rather than keeping it with actual SOAP message. This series also shows that by simply making method calls using the SAAJ API, you can read and write SOAP-based XML messages, and you can optionally send and receive such messages over the Internet.
Part 1 starts simply, explaining the basic concepts behind web services and showing you how to develop web service with Axis2 using Different Approach (Code First and Contract First).
Part 2 starts simply by developing a Hello User web Service with JAX-WS and then takes things a step further by showing an example of File Download web service(where client can download file from web service and store in its location)using MTOM with JAX-WS. It also shows how to invoke web service from SAAJ Client.
Part 3 simply shows how to develop a File uploading web service(where client can Upload file/attachment to Web service) using Apache CXF supports for MTOM with XOP implementation.
This tutorial demonstrates how to develop web service that can upload a file from client machine to the server. The client application submits a file location and invokes the web service which receives the file byte by byte and stores in a fixed specified location.
In this tutorial, you will learn how to:
- Build a web service using CXF and deploy it in the tomcat server.
- Learn how to send large binary attachments using the MTOM standard.
This tutorial assumes familiarity with some basic concepts of the Eclipse IDE, including views, editors, panels, and so on, along with basic programming concept in Java™ and web services. For an introduction to Eclipse, Java and Web Services, view the Resources.
- CXF-bin
- Tomcat
- Eclipse(optional)



