JAX-WS MTOM示例代码 [英] JAX-WS MTOM Sample Code
问题描述
我正在寻找使用JAX-WS RI或基于Axis2的简单,有效的示例MTOM示例代码(服务+客户端).
我用谷歌搜索这个词只是为了找到不能简单起作用的代码片段和代码!
我想将PDF附件发送到请求的Web服务客户端.
看起来我早点问了这个问题:) 这是一个带有MTOM的示例jax-ws代码.
听到并读到即使使用axis2 + mtom也存在一些问题..文档也确实在axis2中不好. 性能也值得怀疑(尽管对于XMLBeans不能肯定ADB)...参考: http://weblogs.java.net/blog/kohsuke/存档/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));
}
}
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.
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));
}
}
这篇关于JAX-WS MTOM示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!