JAX-WS MTOM示例代码

时间:2009-07-11 12:52:53

标签: axis2 jax-rs mtom

我正在寻找一个简单的,有效的示例MTOM示例代码(服务+客户端),使用JAX-WS RI或基于Axis2。

我搜索了这个词只是为了找到不简单的代码片段和代码!

我想将PDF附件发送到请求的Web服务客户端。

1 个答案:

答案 0 :(得分:0)

看起来我早一点问了问题:) 这是一个使用MTOM的示例jax-ws代码..我自己管理...

听说并读到即使使用axis2 + mtom也存在一些问题..在axis2中,文档也非常糟糕。 性能也值得怀疑(尽管XMLBeans不确定ADB)...参考: http://weblogs.java.net/blog/kohsuke/archive/2007/02/jaxws_ri_21_ben.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
        }


    }
}

服务器端

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));

    }
}