Upload attachment (document) using CXF ( MTOM ) and Tomcat
|Upload attachment (document) using CXF ( MTOM ) and Tomcat|
|Let us now create a resume upload web service using Apache CXF, Spring and Tomcat and consume it. The web service will be used to upload an attachment [resume]. The scenario considered here is a candidate uploading his/her resume and the resume [word document] is retrieved and stored on the server.
We have two Maven projects attached. The first project is the web application deployed on the JEE server with a context cxfupload and the second is the Java client which invokes the web service.
Let us start with the web service interface which is provided below.
The implementation for the above interface is provided by ResumeUploadServiceImpl.java which is partly provided below (the complete source is in the zip attached).
Next comes the CXF configuration file cxf.xml which has the configuration which will be loaded by Spring and used by CXF about the web service. We have mentioned jaxws:properties which enables mtom capability of CXF where in the resume is sent as an attachment giving better performance [by avoiding base 64 encoding].
The web.xml configure the CXF servlet to listen at the desired URL pattern as below.
Client Application consuming the web services:
Client.java populates values for candidate name, file attachment type, and the resume [which is path to a file] and invokes the web service as below.