package sample;
?
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;
import org.apache.axiom.om.OMText;
import org.apache.axis2.AxisFault;
?
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
?
import java.util.Iterator;
?
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
?
public class FileTransferServer {
?????? public static final String TMP_PATH = "D:/temp";
?
?????? public OMElement upload(OMElement element) throws Exception {
????????????? OMElement _fileContent = null;//文件内容
????????????? OMElement _fileName = null;//文件名
????????????? OMElement _fileType = null;//文件类型
????????????? System.out.println("The element for upload: " + element);
????????????? for (Iterator _iterator = element.getChildElements(); _iterator
??????????????????????????? .hasNext();) {
???????????????????? OMElement _ele = (OMElement) _iterator.next();
???????????????????? if (_ele.getLocalName().equalsIgnoreCase("fileContent")) {
??????????????????????????? _fileContent = _ele;
???????????????????? }
???????????????????? if (_ele.getLocalName().equalsIgnoreCase("fileName")) {
??????????????????????????? _fileName = _ele;
???????????????????? }
???????????????????? if (_ele.getLocalName().equalsIgnoreCase("fileType")) {
????????????? ????????????? _fileType = _ele;
???????????????????? }
????????????? }
?
????????????? if (_fileContent == null || _fileType == null) {
???????????????????? throw new AxisFault("Either Image or FileName is null");
????????????? }
?
????????????? OMText binaryNode = (OMText) _fileContent.getFirstOMChild();
????????????? String fileName = _fileName.getText();
????????????? String fileType = _fileType.getText();
????????????? String storeDir = TMP_PATH + "/" + "tempTest";
????????????? File dir = new File(storeDir);
????????????? if (!dir.exists()) {
???????????????????? dir.mkdir();
????????????? }
????????????? String filePath = storeDir + "/" + fileName + "." + fileType;
????????????? File uploadFile = new File(filePath);
????????????? if (uploadFile.exists()) {
???????????????????? filePath = storeDir + "/" + fileName + "(1)" + "." + fileType;
???????????????????? uploadFile = new File(filePath);
????????????? }
?
????????????? // Extracting the data and saving
????????????? DataHandler actualDH;
????????????? actualDH = (DataHandler) binaryNode.getDataHandler();
?
????????????? FileOutputStream imageOutStream = new FileOutputStream(uploadFile);
????????????? InputStream is = actualDH.getInputStream();
????????????? imageOutStream.write(IOUtils.getStreamAsByteArray(is));
????????????? // setting response
????????????? OMFactory fac = OMAbstractFactory.getOMFactory();
????????????? OMNamespace ns = fac.createOMNamespace("http://example.org/filedata",
??????????????????????????? "fd");
????????????? OMElement ele = fac.createOMElement("response", ns);
????????????? ele.setText("true");
????????????? return ele;
?????? }
?
?????? public OMElement download(OMElement element) throws Exception {
????????????? System.out.println("The element for download: " + element);
????????????? OMElement _userName = null;
????????????? OMElement _fileName = null;
????????????? OMElement _fileType = null;
????????????? for (Iterator _iterator = element.getChildElements(); _iterator
??????????????????????????? .hasNext();) {
???????????????????? OMElement _ele = (OMElement) _iterator.next();
???????????????????? if (_ele.getLocalName().equalsIgnoreCase("userName")) {
??????????????????????????? _userName = _ele;
???????????????????? }
???????????????????? if (_ele.getLocalName().equalsIgnoreCase("fileName")) {
??????????????????????????? _fileName = _ele;
???????????????????? }
???????????????????? if (_ele.getLocalName().equalsIgnoreCase("fileType")) {
??????????????????????????? _fileType = _ele;
???????????????????? }
????????????? }
????????????? String userName = _userName.getText();
????????????? String fileName = _fileName.getText();
????????????? String fileType = _fileType.getText();
????????????? String filePath = TMP_PATH + "/" + userName + "/" + fileName + "."
??????????????????????????? + fileType;
????????????? System.out.println("The filePath for download: " + filePath);
????????????? FileDataSource dataSource = new FileDataSource(filePath);
????????????? DataHandler expectedDH = new DataHandler(dataSource);
????????????? OMFactory fac = OMAbstractFactory.getOMFactory();
????????????? OMNamespace ns = fac.createOMNamespace("http://example.org/filedata",
??????????????????????????? "fd");
????????????? OMText textData = fac.createOMText(expectedDH, true);
????????????? OMElement ele = fac.createOMElement("response", ns);
????????????? ele.addChild(textData);
????????????? return ele;
?????? }
}
|
相关推荐
axis2-kernel-1.3.jar axis2-kernel-1.3.jar
axis2-idea-plugin-1.7.9
目前axis2最高版本是2.0以上的版本,但是eclipse和myeclipse都不支持,无奈只能使用低版本的插件1.6.3;经实验,可以安装成功; 安装方法:右键解压到当前文件夹,Copy解压的文件到eclipse安装目录dropins下,重启...
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,解压即可使用
axis-imageshtml5-3d-mult-axis-imageshtml5-3d-mult-axis-imageshtml5-3d-mult-axis-images
共四个文件,都是最先版的,希望可以帮助大家。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-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-...
axis2-std-1.0-bin.zip与axis2.war axis2-std-1.0-bin.zip与axis2.war
1、axis2客户端下载地址:http://mirror.esocc.com/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip; 2、下载解压在D:\Work_Program_Files目录;在D:\Work_Program_Files\axis2-1.6.2\bin目录有一个wsdl2...
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-1.5.1-bin.zip axis2-1.5.1-war.zip webservice部署axis所需要是包
绝对可以用,里面配有myeclipse10安装AXIS2插件的步骤,希望大家工作愉快,谢谢,给好评哦
axis2-1.6.0-bin和axis2-1.6.0-war相关资源
axis2-1.7.9-bin.zip axis2最新版本的工具包bin在这里了
axis2-1.6.1