CXF MTOM Client

CXF MTOM Client explains step by step details of  creating a MTOM Client in order to upload large attachments in SOAP based services

MTOM is used for encoding binary data in base64Binary and send as binary attachment than keeping it with actual SOAP message. MTOM is approved by WC3 and is a standard. MTOM very useful for transfering binary data such as MS documents, PDF, images etc. MTOM uses XML-binary Optimized Packaging (XOP) packages for transmitting binary data

For publishing a CXF Web MTOM Service, you need to follow CXF File Upload With SOAP MTOM.

This MTOM client is generated after the deployment of above service.

Required Libraries

You need to download following libraries in order to run CXF MTOM Client

  1. JDK 6
  2. Eclipse 3.7
  3. For running this client you need to refer the classes generated on CXF File Upload With SOAP MTOM

CXF MTOM Client

package com.client;

import java.io.File;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.student.FileUploader;
import com.student.UploadService;

public final class Client {

  
public static void main(String args[]) throws Exception {

     
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
      Map<String,Object> props = new HashMap<String, Object>();
      props.put("mtom-enabled", Boolean.TRUE);
      factory.setProperties(props); 
 
      factory.getInInterceptors().add(new LoggingInInterceptor());
      factory.getOutInterceptors
().add(new LoggingOutInterceptor());
      factory.setServiceClass
(UploadService.class);
      factory.setAddress
("http://localhost:8080/CXFUpload/Upload?wsdl");
      UploadService client =
(UploadService) factory.create();

      FileUploader file =
new FileUploader();

      file.setName
("Copy");
      file.setFileType
("txt");

      DataSource source =
new FileDataSource(new File("C:/uploads/Original.txt"));
      file.setDfile
(new DataHandler(source));
      client.uploadFile
(file);
      System.exit
(0);

  
}
}
Output

CXF MTOM Logs

CXF MTOM Output

 






8 Responses to "CXF MTOM Client"
  1. Sony 2013-04-25 08:39:58.0
  1. jasp 2013-04-26 08:39:58.0
  1. admin 2013-04-27 08:39:58.0
  1. admin 2013-04-28 08:39:58.0
  1. chandra shekar 2013-04-29 08:39:58.0
  1. admin 2013-04-30 08:39:58.0
  1. chandra shekar 2013-04-30 18:39:58.0
  1. Danang 2013-04-30 22:39:58.0

Your email address will not be published. Required fields are marked *