Web Services以及Axis2技术(文件传送的具体实现)

简介: import org.apache.axiom.attachments.utils.IOUtils; import org.apache.axiom.om.OMAbstractFactory; import org.
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.FileOutputStream;
import java.io.*;
import java.util.Iterator;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
public class interopService {
public static final String TMP_PATH = "c:/tmp";
public OMElement upload(OMElement element) throws Exception {
    OMElement _fileContent = null;
    OMElement _mailboxnum = null;
    OMElement _greetingType = null;
    OMElement _fileType = null;
    System.out.println(element);
    for (Iterator _iterator = element.getChildElements(); _iterator.hasNext();) {
      OMElement _ele = (OMElement) _iterator.next();
      if (_ele.getLocalName().equalsIgnoreCase("fileContent")) {
        _fileContent = _ele;
      }
      if (_ele.getLocalName().equalsIgnoreCase("mailboxnum")) {
        _mailboxnum = _ele;
      }
      if (_ele.getLocalName().equalsIgnoreCase("greetingType")) {
        _greetingType = _ele;
      }
      if (_ele.getLocalName().equalsIgnoreCase("fileType")) {
        _fileType = _ele;
      }
    }
    if (_fileContent == null || _mailboxnum == null || _greetingType== null || _fileType==null) {
      throw new AxisFault("Either Image or FileName is null");
    }
    OMText binaryNode = (OMText) _fileContent.getFirstOMChild();
    String mboxNum = _mailboxnum.getText();
    String greetingType = _greetingType.getText();
    String fileType = _fileType.getText();
    String greetingstoreDir = TMP_PATH+"/"+mboxNum;
    File dir = new File(greetingstoreDir);
    if(!dir.exists()) {
      dir.mkdir();
    }
    String filePath = greetingstoreDir+"/"+greetingType+"."+fileType;
    File greetingFile = new File(filePath);
    if(greetingFile.exists()) {
      greetingFile.delete();
       greetingFile = new File(filePath);
    }
   
    // Extracting the data and saving
    DataHandler actualDH;
    actualDH = (DataHandler) binaryNode.getDataHandler();
    
    FileOutputStream imageOutStream = new FileOutputStream(greetingFile);
    InputStream is = actualDH.getInputStream();
    imageOutStream.write(IOUtils.getStreamAsByteArray(is));
    // setting response
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace ns = fac.createOMNamespace("http://example.org/mtom/data", "x");
    OMElement ele = fac.createOMElement("response", ns);
    ele.setText("true");
   
    return ele;
}
public OMElement download(OMElement element) throws Exception {
    System.out.println(element);
    OMElement _mailboxnum = null;
    OMElement _greetingType = null;
    OMElement _fileType = null;
    for (Iterator _iterator = element.getChildElements(); _iterator.hasNext();) {
      OMElement _ele = (OMElement) _iterator.next();
      if (_ele.getLocalName().equalsIgnoreCase("mailboxnum")) {
        _mailboxnum = _ele;
      }
      if (_ele.getLocalName().equalsIgnoreCase("greetingType")) {
        _greetingType = _ele;
      }
      if (_ele.getLocalName().equalsIgnoreCase("fileType")) {
        _fileType = _ele;
      }
    }
    String mboxNum = _mailboxnum.getText();
    String greetingType = _greetingType.getText();
    String fileType = _fileType.getText();
    String filePath = TMP_PATH+"/"+mboxNum+"/"+greetingType+"."+fileType;
    FileDataSource dataSource = new FileDataSource(filePath);
    DataHandler expectedDH = new DataHandler(dataSource);
   
    OMFactory fac = OMAbstractFactory.getOMFactory();
   
    OMNamespace ns = fac.createOMNamespace("http://example.org/mtom/data", "x");
    OMText textData = fac.createOMText(expectedDH, true);
    OMElement ele = fac.createOMElement("response", ns);
    ele.addChild(textData);
    return ele;
}
}
Services.xml配置文件:
name="MTOMService">
   
        This is a sample Web Service with two operations,echo and ping.
   
    name="ServiceClass"locked="false">sample.mtom.interop.service.interopService
    name="upload">
        urn:upload
        class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
   
      name="download">
        urn:download
        class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
   

目录
相关文章
|
3月前
|
安全 Java API
Java Web 在线商城项目最新技术实操指南帮助开发者高效完成商城项目开发
本项目基于Spring Boot 3.2与Vue 3构建现代化在线商城,涵盖技术选型、核心功能实现、安全控制与容器化部署,助开发者掌握最新Java Web全栈开发实践。
412 1
|
6月前
|
缓存 前端开发 应用服务中间件
Web端实时通信技术SSE在携程机票业务中的实践应用
本文介绍了携程机票前端基于Server-Sent Events(SSE)实现服务端推送的企业级全链路通用技术解决方案。文章深入探讨了 SSE 技术在应用过程中包括方案对比、技术选型、链路层优化以及实际效果等多维度的技术细节,为类似使用场景提供普适性参考和借鉴。该方案设计目标是实现通用性,适用于各种网络架构和业务场景。
200 1
|
7月前
|
缓存 前端开发 应用服务中间件
Web端实时通信技术SSE在携程机票业务中的实践应用
本文介绍了携程机票前端基于Server-Sent Events(SSE)实现服务端推送的企业级全链路通用技术解决方案。文章深入探讨了 SSE 技术在应用过程中包括方案对比、技术选型、链路层优化以及实际效果等多维度的技术细节,为类似使用场景提供普适性参考和借鉴。
286 7
|
9月前
|
XML JSON API
Understanding RESTful API and Web Services: Key Differences and Use Cases
在现代软件开发中,RESTful API和Web服务均用于实现系统间通信,但各有特点。RESTful API遵循REST原则,主要使用HTTP/HTTPS协议,数据格式多为JSON或XML,适用于无状态通信;而Web服务包括SOAP和REST,常用于基于网络的API,采用标准化方法如WSDL或OpenAPI。理解两者区别有助于选择适合应用需求的解决方案,构建高效、可扩展的应用程序。
|
人工智能 安全 物联网
区块链技术的未来展望:去中心化金融(DeFi)与Web 3.0的融合
区块链技术的未来展望:去中心化金融(DeFi)与Web 3.0的融合
|
前端开发 JavaScript 搜索推荐
HTML与CSS在Web组件化中的核心作用及前端技术趋势
本文探讨了HTML与CSS在Web组件化中的核心作用及前端技术趋势。从结构定义、语义化到样式封装与布局控制,两者不仅提升了代码复用率和可维护性,还通过响应式设计、动态样式等技术增强了用户体验。面对兼容性、代码复杂度等挑战,文章提出了相应的解决策略,强调了持续创新的重要性,旨在构建高效、灵活的Web应用。
281 6
|
XML 前端开发 JavaScript
PHP与Ajax在Web开发中的交互技术。PHP作为服务器端脚本语言,处理数据和业务逻辑
本文深入探讨了PHP与Ajax在Web开发中的交互技术。PHP作为服务器端脚本语言,处理数据和业务逻辑;Ajax则通过异步请求实现页面无刷新更新。文中详细介绍了两者的工作原理、数据传输格式选择、具体实现方法及实际应用案例,如实时数据更新、表单验证与提交、动态加载内容等。同时,针对跨域问题、数据安全与性能优化提出了建议。总结指出,PHP与Ajax的结合能显著提升Web应用的效率和用户体验。
308 3
|
SQL 负载均衡 安全
安全至上:Web应用防火墙技术深度剖析与实战
【10月更文挑战第29天】在数字化时代,Web应用防火墙(WAF)成为保护Web应用免受攻击的关键技术。本文深入解析WAF的工作原理和核心组件,如Envoy和Coraza,并提供实战指南,涵盖动态加载规则、集成威胁情报、高可用性配置等内容,帮助开发者和安全专家构建更安全的Web环境。
413 1
|
负载均衡 监控 算法
论负载均衡技术在Web系统中的应用
【11月更文挑战第4天】在当今高并发的互联网环境中,负载均衡技术已经成为提升Web系统性能不可或缺的一环。通过有效地将请求分发到多个服务器上,负载均衡不仅能够提高系统的响应速度和处理能力,还能增强系统的可扩展性和稳定性。本文将结合我参与的一个实际软件项目,从项目概述、负载均衡算法原理以及实际应用三个方面,深入探讨负载均衡技术在Web系统中的应用。
387 2
|
缓存 安全 前端开发
构建高效Web应用的五大关键技术
【10月更文挑战第42天】在数字化浪潮中,Web应用已成为企业与用户互动的重要桥梁。本文将深入探讨提升Web应用性能和用户体验的五项核心技术,包括前端优化、后端架构设计、数据库管理、安全性增强以及API开发的最佳实践。通过这些技术的应用,开发者可以构建出更快、更稳定且更安全的Web应用,满足现代网络环境的需求。

热门文章

最新文章