我正在寻找一个使用 JAX-WS RI 或基于 Axis2 的简单、有效的示例 MTOM 示例代码(服务 + 客户端)。
我用谷歌搜索这个词只是为了找到不能简单工作的片段和代码!
我想将 PDF 附件发送到发出请求的 Web 服务客户端。
看起来我问的问题有点早:) 这是一个带有 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));
}
}