设为首页 加入收藏

TOP

通向架构师的道路(第十二天)之Axis2 Web Service(三)(一)
2018-02-22 14:32:42 】 浏览:765
Tags:通向 架构 师的 道路 十二 Axis2 Web Service

一、SOAPIn Axis2

在前两天的教程中,我们学习到了用Axis2如何进行复杂数据、简单数据进行传输。

正如我在前一天教程中所说,在web service的世界里,一切都是基于SOAP的,因此在今天我们将学习Axis2中的SOAP特性。

今天的课程将用3个例子来完成即:

  1. 客户端与服务端使用SOAP进行通讯
  2. 服务端将Exception以SOAPFault的形式抛给客户端
  3. 使用SWA(Soap With Attachment)来进行附件传送

二、客户端与服务端使用SOAP进行通讯

来看下面这个Web Service:

 

下面是Service端的源码

org.sky.axis2.soap.SoapService

package org.sky.axis2.soap;

 

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 java.util.*;

 

public class SoapService {

 

         public static OMElement requestSoap = null;

 

         public OMElement request(OMElement soapBody) {

                   requestSoap = soapBody;

 

                   Iterator it = requestSoap.getChildElements();

                   OMElement issuerElement = (OMElement) it.next();

                   OMElement serialElement = (OMElement) it.next();

                   OMElement revocationDateElement = (OMElement) it.next();

 

                   String issuer = issuerElement.getText();

                   String serial = serialElement.getText();

                   String revocationDate = revocationDateElement.getText();

                   System.out.println("issuer=====" + issuer);

                   System.out.println("serial=====" + serial);

                   System.out.println("revocationDate=====" + revocationDate);

                   OMFactory soapFactory = OMAbstractFactory.getOMFactory();

                   OMNamespace omNs = soapFactory.createOMNamespace(

                                     "http://soap.axis2.sky.org", "");

                   OMElement soapResponse = soapFactory.createOMElement("SoapResponse",

                                     omNs);

 

                   OMElement soapIssuer = soapFactory.createOMElement("Issuer", omNs);

                   soapIssuer.setText("issuer: " + issuer);

                   soapResponse.addChild(soapIssuer);

 

                   OMElement soapSerial = soapFactory.createOMElement("Serial", omNs);

                   soapSerial.setText("serial: " + serial);

                   soapResponse.addChild(soapSerial);

 

                   OMElement soapRevokeDate = soapFactory.createOMElement("RevokeDate",

                                     omNs);

                   soapRevokeDate.setText("RevocationDate: " + revocationDate);

                   soapResponse.addChild(soapRevokeDate);

                   soapResponse.build();

 

                   return soapResponse;

         }

 

}

来看它的service.xml的描述

<service name="SoapService">

         <description>

                   This is the service for revoking certificate.

         </description>

         <parameter name="ServiceClass" locked="false">

                   org.sky.axis2.soap.SoapService

         </parameter>

         <operation name="request">

                   <messageReceiver

                            class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />

                   <actionMapping>urn:request</actionMapping>

         </operation>

</service>

该Web Service接受一个Soap请求,该请求为如下格式:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.axis2.sky.org">

   <soapenv:Header/>

   <soapenv:Body>

      <soap:request>

           <soap:request>?</soap:request>

      </soap:request>

   </soapenv:Body>

</soapenv:Envelope>

其中

首页 上一页 1 2 3 4 5 6 7 下一页 尾页 1/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Java 开发 .gitignore 文件包含 ... 下一篇Java 非阻塞 IO 和异步 IO

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目