【问题标题】:JAX-WS MTOM Sample CodeJAX-WS MTOM 示例代码
【发布时间】:2010-11-09 23:07:33
【问题描述】:

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

我用谷歌搜索了这个词,只是为了找到无法简单工作的 sn-ps 和代码!

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

【问题讨论】:

    标签: axis2 jax-rs mtom


    【解决方案1】:

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

    听说过,即使使用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));
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-04-21
      • 2011-11-04
      • 2016-11-07
      • 1970-01-01
      • 2011-02-06
      • 1970-01-01
      • 2011-05-15
      • 1970-01-01
      • 2016-06-18
      相关资源
      最近更新 更多