tags:

views:

3125

answers:

1

hi All,

I looking for a simple , working sample mtom sample code (service + Client) either using jax-ws RI or Axis 2 based.

I googled the world only to find snippets and codes that dont simply work !

Want to send PDF attachments to the requesting web service client..

Thanks Sam-ant

A: 

looks like i asked the Question a little early :) Here is a sample jax-ws code with MTOM .. i cud manage on my own..

Heard and read that even with axis2 + mtom there are some issues..documentation too is really bad in axis2. Also performance is questionable (although with XMLBeans not sure of ADB)... reference : http://weblogs.java.net/blog/kohsuke/archive/2007/02/jaxws%5Fri%5F21%5Fben.html

package webservice;

import java.io.File;
import javax.activation.DataHandler;
import org.jvnet.staxex.StreamingDataHandler;

/**
 *
 * @author Raghavendra_Samant
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        try { // Call Web Service Operation
            com.xxx.labelgeneration.LabelGeneratorService service = new com.xxx.labelgeneration.LabelGeneratorService();
            com.xxx.labelgeneration.LabelGenerator port = service.getLabelGeneratorPort();
            // TODO initialize WS operation arguments here
            java.lang.String name = "dynamic.pdf";
            // TODO process result here
            byte[] result = port.getFile(name);

            System.out.println("Result = "+result.length);
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }


    }
}

Server side

package com.xxx.LabelGeneration;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.soap.MTOM;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;

/**
 *
 * @author Raghavendra_Samant
 */
@WebService()
@MTOM
public class LabelGenerator {

    /**
     * Web service operation
     */
    @WebMethod(operationName = "getFile")
        public DataHandler  getFile(@WebParam(name = "name") String fileName) {
        //TODO write your implementation code here:

        return new DataHandler(new FileDataSource(fileName));

    }
}