package sample;
<o:p> </o:p>
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
<o:p> </o:p>
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
<o:p> </o:p>
import org.apache.axiom.attachments.utils.IOUtils;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;<o:p></o:p>
import org.apache.axiom.om.OMText;<o:p></o:p>
import org.apache.axiom.soap.SOAP11Constants;<o:p></o:p>
import org.apache.axis2.AxisFault;<o:p></o:p>
import org.apache.axis2.Constants;<o:p></o:p>
import org.apache.axis2.addressing.EndpointReference;<o:p></o:p>
import org.apache.axis2.client.Options;<o:p></o:p>
import org.apache.axis2.client.ServiceClient;<o:p></o:p>
<o:p></o:p>
public class FileTransferClient {
private static EndpointReference targetEPR =
new EndpointReference("http://127.0.0.1:8080/axis2/services/FileOperation");
public static boolean upload(String fileName, File file, String fileType) {
try {
OMElement data = buildUploadEnvelope(fileName, file, fileType);
Options options = buildOptions();
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
System.out.println("The data in method upload: "+data);
OMElement ome = sender.sendReceive(data);
System.out.println("Convert the data to element in method upload: "+ome);
String b = ome.getText();
return Boolean.parseBoolean(b);
}
catch(Exception e) {
e.printStackTrace();
}
return false;
}
public static boolean download(String userName, String fileName, String fileType) {
try {
OMElement data = buildDownloadEnvelope(userName, fileName, fileType);
Options options = buildOptions();
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
System.out.println("The data in method download: "+data);
OMElement ome = sender.sendReceive(data);
System.out.println("Convert the data to element in method download: "+ome);
OMText binaryNode = (OMText) ome.getFirstOMChild();
binaryNode.setOptimize(true); //必须加此句,否则会出现ContentID is null的异常!
DataHandler actualDH = (DataHandler) binaryNode.getDataHandler();
FileOutputStream imageOutStream = new FileOutputStream("D:/userTemp/xx.gif");
InputStream is = actualDH.getInputStream();
imageOutStream.write(IOUtils.getStreamAsByteArray(is));
return true;
}
catch(Exception e) {
e.printStackTrace();
}
return false;
}
private static OMElement buildUploadEnvelope(String fileName, File file, String fileType) {
DataHandler expectedDH;
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://example.org/filedata", "fd");<o:p></o:p>
OMElement data = fac.createOMElement("upload", omNs);
OMElement fileContent = fac.createOMElement("fileContent", omNs);
FileDataSource dataSource = new FileDataSource(file);
expectedDH = new DataHandler(dataSource);
OMText textData = fac.createOMText(expectedDH, true);
fileContent.addChild(textData);
OMElement _fileName = fac.createOMElement("fileName", omNs);
_fileName.setText(fileName);
OMElement _fileType = fac.createOMElement("fileType", omNs);
_fileType.setText(fileType);
data.addChild(_fileName);
data.addChild(_fileType);
data.addChild(fileContent);
return data;
}
private static OMElement buildDownloadEnvelope(String userName, String fileName, String fileType) {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://example.org/filedata", "fd");
OMElement data = fac.createOMElement("download", omNs);
OMElement _userName = fac.createOMElement("userName", omNs);
_userName.setText(userName);
OMElement _fileName = fac.createOMElement("fileName", omNs);
_fileName.setText(fileName);
OMElement _fileType=fac.createOMElement("fileType", omNs);
_fileType.setText(fileType);
data.addChild(_userName);
data.addChild(_fileName);
data.addChild(_fileType);
return data;
}
private static Options buildOptions() throws AxisFault {
Options options = new Options();
options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
options.setTo(targetEPR);
// enabling MTOM in the client side
options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
return options;
}
public static void main(String agrs[]) {
String file = "D:/userTemp/ya.gif";
String fn = "testUser";
String ft="gif";
boolean rtv = upload(fn,new File(file),ft);
System.out.println("is upload success: "+rtv);
String un="zj";
String downfn="1";
if(download(un,downfn,ft)){
System.out.println("download success.");
}
else System.out.println("download fail.");
System.out.println("Client main end.");
}
}
|
相关推荐
axis2-kernel-1.3.jar axis2-kernel-1.3.jar
目前axis2最高版本是2.0以上的版本,但是eclipse和myeclipse都不支持,无奈只能使用低版本的插件1.6.3;经实验,可以安装成功; 安装方法:右键解压到当前文件夹,Copy解压的文件到eclipse安装目录dropins下,重启...
axis-imageshtml5-3d-mult-axis-imageshtml5-3d-mult-axis-imageshtml5-3d-mult-axis-images
axis2-idea-plugin-1.7.9
1、axis2相关jar包如下: axiom-api-1.2.10.jar axiom-dom-1.2.10.jar axiom-impl-1.2.10.jar axis2-adb-1.5.4.jar axis2-adb-codegen-1.5.4.jar axis2-codegen-1.5.4.jar axis2-corba-1.5.4.jar axis2-fastinfoset-...
axis2-eclipse-codegen-plugin-1.6.2.zip和axis2-eclipse-service-plugin-1.6.2.zip,解压即可使用
共四个文件,都是最先版的,希望可以帮助大家。axis2-eclipse-service-archiver-wizard和axis2-eclipse-codegen-wizard和axis2-1.6.1-bin和axis2-1.6.1-war
axis2 webservice 服务端jar包: -->axis2-kernel-1.6.1.jar -->axis2-spring-1.6.1.jar -->axis2-transport-http-1.6.1.jar -->XmlSchema-1.4.7.jar -->wsdl4j-1.6.2.jar -->axiom-api-1.2.12.jar -->axiom...
用于axis2开发的一个必不可少的包,开发时需要把包安置在eclipse下
axis2c-bin-1.6.0-linux.tar.gz axis2c-bin-1.6.0-win32.zip axis2c-src-1.6.0.tar.gz axis2c-src-1.6.0.zip 加md5
axis2-1.6.2-war、axis2-1.6.1-war、axis2-1.6.2-bin
axis2-1.5.3-bin.zip axis2-1.5.3-bin.zip axis2-1.5.3-bin.zip axis2-1.5.3-bin.zip
axis2-std-1.0-bin.zip与axis2.war axis2-std-1.0-bin.zip与axis2.war
axis2-java2wsdl-1.5.4.jar axis2-jaxbri-1.5.4.jar axis2-jaxws-1.5.4.jar axis2-jibx-1.5.4.jar axis2-json-1.5.4.jar axis2-kernel-1.5.4.jar axis2-metadata-1.5.4.jar axis2-mtompolicy-1.5.4.jar axis2-saaj-...
绝对可以用,里面配有myeclipse10安装AXIS2插件的步骤,希望大家工作愉快,谢谢,给好评哦
axis2-1.6.2.zip, windows axis2工具,根据 WSDL生成java文件。 1、axis2客户端下载地址:http://mirror.esocc.com/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip; 2、下载解压在D:\Work_Program_...
axis2-1.5.1-bin.zip axis2-1.5.1-war.zip webservice部署axis所需要是包
axis2-1.6.0-bin和axis2-1.6.0-war相关资源
axis2-1.6.1
axis2-bin-And-axis2-war.zip