- 浏览: 143188 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
影非弦:
想请教一下博主,applet可以在不B/S结构的客户端访问吗? ...
Applet签名与打包 -
阿市A:
我和楼主一样~现在也工作三年了~不知楼主现在混的如何?
2009随感 -
无双Rama:
我用HttpClient实现,怎么让AP主动连ACS呢?
TR-069 协议的开发(三)ACS呼叫AP -
zhaotao532:
你好,我现在正在做acs服务端,可在调用cpe的downloa ...
TR069协议 -
yunnick:
总结的真不错,我刚入职,对这些东西稍有些体会~我用的是JSP, ...
Web程序员
前段时间开发ACS,是基于SOAP协议的通信,一次通信过程包含多个soap报文,而且也不想普通的webserivice那样,
soap报文是自动生成的。ACS的通信的报文是硬编码编出来的,虽然能正确运行,但是实在是不雅,最近闲来无事,
想着如何用像webservice那样,用Java对象设置参数后,将对象转换成String格式的SOAP报文,这样以后程序的维护
问题就得到解决了。
然后在google中baidu了一把,找了个例子,然后开始试验了。其实程序并不难,写这个文章,主要是帮助那些直接使用SOAP
协议进行开发的朋友们参考,也给自己留个备注,呵呵。
package com.seahigh.acs.soap; import java.util.ArrayList; import java.util.List; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.soap.MessageFactory; import javax.xml.soap.SOAPBody; import javax.xml.soap.SOAPElement; import javax.xml.soap.SOAPEnvelope; import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPFactory; import javax.xml.soap.SOAPHeader; import javax.xml.soap.SOAPMessage; import javax.xml.soap.SOAPPart; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.InputSource; /** * * @author 汪心利 * Date 2010-3-30下午02:51:30 * (c)CopyRight seahigh 2010 */ public class SoapUtil { public SOAPPart initSoapPart() throws SOAPException { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPHeader soapHeader = soapEnvelope.getHeader(); SOAPElement cwmp = soapEnvelope.addNamespaceDeclaration("cwmp", "urn:dslforum-org:cwmp-1-0"); SOAPElement xsi = soapEnvelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance"); SOAPElement xsd = soapEnvelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema"); SOAPElement enc = soapEnvelope.addNamespaceDeclaration("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/"); SOAPElement id = soapHeader.addChildElement("ID", "cwmp"); id.setTextContent("1"); return soapPart; } public void soap2String(Source source) throws Exception { if (source != null) { Node root = null; if (source instanceof DOMSource) { root = ((DOMSource) source).getNode(); } else if (source instanceof SAXSource) { InputSource inSource = ((SAXSource) source).getInputSource(); DocumentBuilderFactory dbf = DocumentBuilderFactory .newInstance(); dbf.setNamespaceAware(true); Document doc = dbf.newDocumentBuilder().parse(inSource); root = (Node) doc.getDocumentElement(); } Transformer transformer = TransformerFactory.newInstance() .newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(root), new StreamResult( System.out)); } } public Source informResponse(SOAPPart part) throws Exception { SOAPEnvelope soapEnvelope = part.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); SOAPElement informRes = soapBody.addChildElement("InformResponse", "cwmp"); SOAPElement max = SOAPFactory.newInstance().createElement( "MaxEnvelopes", "", ""); max.setTextContent("1"); informRes.addChildElement(max); return part.getContent(); } public Source getParameterValues(SOAPPart part, List list) throws Exception { SOAPEnvelope soapEnvelope = part.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); SOAPElement informRes = soapBody.addChildElement("GetParameterValues", "cwmp"); SOAPFactory soapFactory = SOAPFactory.newInstance(); SOAPElement names = soapFactory.createElement("ParameterNames", "", ""); names.addAttribute(new QName("SOAP-ENC:arrayType"), "xsd:string[" + list.size() + "]"); SOAPElement nameElement = null; for (int i = 0; i < list.size(); i++) { nameElement = soapFactory.createElement("string", "", ""); nameElement.setTextContent((String) list.get(i)); names.addChildElement(nameElement); } informRes.addChildElement(names); return part.getContent(); } public static void main(String[] args) throws Exception { SoapUtil util = new SoapUtil(); SOAPPart part = util.initSoapPart(); Source inform = util.getParameterValues(part, util.getTestnames()); util.soap2String(inform); } public List<String> getTestnames() { List<String> list = new ArrayList<String>(); list.add("InternetGatewayDevice.DeviceInfo.X_CT-COM_CPU"); list.add("InternetGatewayDevice.DeviceInfo.X_CT-COM_WorkTime"); list.add("InternetGatewayDevice.DeviceInfo.SoftwareVersion"); list.add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_ReceiveNoise"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_LAN-TotalBytesReceived"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_LAN-TotalBytesSent"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_WAN-TotalBytesReceived"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_WAN-TotalBytesSent"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_LAN-TotalPacketsReceived"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_LAN-TotalPacketsSent"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_WAN-TotalPacketsReceived"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_WAN-TotalPacketsSent"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.ResponsePass"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.AskPass"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.SuccessPass"); list.add("InternetGatewayDevice.DeviceInfo.X_CT-COM_Temp"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.LAN-PacketsError"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.LAN-TotalBytesReceived"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.LAN-TotalBytesSent"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.WAN-TotalBytesReceived"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.WAN-PacketsError"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.WAN-TotalBytesSent"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.AssociatedDevice.1.X_CT-COM_ReceiveRate"); list .add("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.AssociatedDevice.1.X_CT-COM_SendRate"); list.add("InternetGatewayDevice.DeviceInfo.SerialNumber"); list.add("InternetGatewayDevice.DeviceInfo.ManufacturerOUI"); return list; } }
这就是研究的成果了,看下结果:
对应TR069协议中的RCP Method:GetParameterValues
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Header> <cwmp:ID>1</cwmp:ID> </SOAP-ENV:Header> <SOAP-ENV:Body> <cwmp:GetParameterValues> <ParameterNames SOAP-ENC:arrayType="xsd:string[27]"> <string>InternetGatewayDevice.DeviceInfo.X_CT-COM_CPU</string> <string>InternetGatewayDevice.DeviceInfo.X_CT-COM_WorkTime</string> <string>InternetGatewayDevice.DeviceInfo.SoftwareVersion</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_ReceiveNoise</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_LAN-TotalBytesReceived</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_LAN-TotalBytesSent</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_WAN-TotalBytesReceived</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_WAN-TotalBytesSent</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_LAN-TotalPacketsReceived</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_LAN-TotalPacketsSent</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_WAN-TotalPacketsReceived</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_WAN-TotalPacketsSent</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.ResponsePass</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.AskPass</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.SuccessPass</string> <string>InternetGatewayDevice.DeviceInfo.X_CT-COM_Temp</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.LAN-PacketsError</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.LAN-TotalBytesReceived</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.LAN-TotalBytesSent</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.WAN-TotalBytesReceived</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.WAN-PacketsError</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_CT-COM_Stat.WAN-TotalBytesSent</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.AssociatedDevice.1.X_CT-COM_ReceiveRate</string> <string>InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.AssociatedDevice.1.X_CT-COM_SendRate</string> <string>InternetGatewayDevice.DeviceInfo.SerialNumber</string> <string>InternetGatewayDevice.DeviceInfo.ManufacturerOUI</string> </ParameterNames> </cwmp:GetParameterValues> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
CPE InformResponse
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Header> <cwmp:ID>1</cwmp:ID> </SOAP-ENV:Header> <SOAP-ENV:Body> <cwmp:InformResponse> <MaxEnvelopes>1</MaxEnvelopes> </cwmp:InformResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
发表评论
-
有多少是这样写代码的
2011-11-16 13:03 13getssssssssssssssss -
java复习 String
2010-12-12 08:51 9861 . 栈(stack)与堆(heap)都是Ja ... -
Java堆栈
2010-12-11 19:09 10451 . 栈(stack)与堆(heap)都 ... -
Java基础知识
2010-12-11 15:00 1010> IOC是一种新的设计模式,即IOC模式,系统中通过引 ... -
Java复习
2010-12-11 14:53 948今天复习了一下 ... -
TR069报文(二)
2010-08-05 16:55 4372GetParameterNames: <SOAP-EN ... -
TR069报文(三)
2010-08-05 16:52 10382GetParameterValues: <SOAP-E ... -
Thread(二)
2010-03-29 16:33 0在上一篇中,我们讲到了多线程是如何处理共享资源的,以及保证他们 ... -
JAVA回调函数
2009-07-01 09:30 955本文转载来源:http://kidult.iteye.com/ ... -
JAVA操作符
2009-03-04 13:09 7063JAVA操作符 几乎所有运算符都只能操作“主类型”(Primi ... -
用 Quartz 进行作业调度
2009-02-09 15:52 890用 Quartz 进行作业调度 h ... -
Log4j配置说明
2009-02-09 15:46 1709今天在使用httpclient时候,想不上DigestSc ... -
Connection Reset的解决与DHCP的使用技巧
2008-12-23 10:19 1654说明:在解决问题的时候,参考了以下文章http://blog. ...
相关推荐
JAVA输出soap报文.pdf
JAVA输出soap报文[参考].pdf
用于使用CXF打印SOAP报文,记录WebService日志~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NULL 博文链接:https://softwarexiang120.iteye.com/blog/2065082
本人在网上看了很多都不能很好的解析报文,就算解析也很难使用,我上传的这个里面将可以拼接soap,判断soap是否连接成功,返回接口的信息,再将报文解析,再转成java实体使用
SOAP解析,与一般的xml解析不一样,他中间存在报文,解析到就出错了,也就解析不下去,这里举了一个列子,(网络上找了好久都没找到我想要的列子,最后我自己根据例子做了整理做出来的),把数据组合成集合。...
支持java端 生成soap-ui的自定义报文,功能和soap-ui软件相似
用Java实现基于SOAP的XML文档网络传输及远程过程调用(RPC).
1,利用java调用soap接口获取天气的信息;2,利用java调用soap一个特定的案例,可按自己的要求修改。
通过访问指定端口转发报文,截获报文内容,soap报文,http报文
JAVA 调用SAP SOAP webservice需要注意的一些坑,请务必按步骤一步步来。
axsi2 发送 SOAP报文
Java使用SOAP获取webservice实例解析 具体实例分析说明。
Axis2的OMElement SOAP XML报文节点首字母小写转大写(注意,是节点,不是节点元素的值) java
java代码-使用java解决http请求SOAP webService接口的源代码 ——学习参考资料:仅用于个人学习使用!
.NET 访问JAVA的WEBSERVICE使用SOAP头
用Java实现SOAP的XML文档网络传输及远程过程调用(RPC)
Axis2 SOAP XML报文节点首字母小写转大写(注意,是节点,不是节点元素的值),节点命名空间前缀添加与剔除(JAVA)
java实现的soap
利用DOM4J解析SOAP中的各个元素的值,在SOAP消息的收发中可以有一点借鉴的地方