没有合适的资源?快使用搜索试试~ 我知道了~
通向架构师的道路(第十二天)之Axis2 Web Service(三).docx
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 6 浏览量
2023-10-27
10:00:35
上传
评论
收藏 34KB DOCX 举报
温馨提示
试读
19页
通向架构师的道路(第十二天)之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>
其中<soap:request></soap:request>中间的内容,应该如下所示:
<Request xmlns="http://10.225.104.122">
<Issuer>1234567890</Issuer>
<Serial>11111111</Serial>
<RevokeDate>2007-01-01</RevokeDate>
</ Response >
我们假设它是一个购买图书的定单,服务端收到这个请求后会返回一个定单信息给调用它的
客户端,服务端将返回如下内容(此处不做任何业务处理,只是很简单的传值回客户端)。
剩余18页未读,继续阅读
资源评论
小小哭包
- 粉丝: 1899
- 资源: 3854
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功