JAX-WS MTOM 示例代码

发布于 2024-07-27 04:18:50 字数 145 浏览 2 评论 0原文

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

我在谷歌上搜索了这个词,结果发现片段和代码根本不起作用!

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

I'm looking for a simple, working sample MTOM sample code (service + client) either using JAX-WS RI or Axis2-based.

I googled the word only to find snippets and codes that don't simply work!

I want to send PDF attachments to the requesting web service client.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情别恋 2024-08-03 04:18:50

看起来我问这个问题有点早了:)
这是一个带有 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));

    }
}

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_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
        }


    }
}

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

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文