1.java soap api操作和发送soap消息

1.java soap api操作和发送soap消息转自:https://blog.csdn.net/lbinzhang/article/details/847213591。

大家好,欢迎来到IT知识分享网。1.java

转自:https://blog.csdn.net/lbinzhang/article/details/84721359

1。

 1 /** 
 2      * soap请求 
 3      *  
 4      * @return 
 5      * @throws Exception 
 6      */  
 7     public static String invokeMethod(Object data) throws Exception {  
 8         // 创建连接    
 9         SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();  
10         SOAPConnection soapConn = soapConnFactory.createConnection();  
11         // 创建消息对象    
12         MessageFactory messageFactory = MessageFactory.newInstance();  
13         SOAPMessage soapMessage = messageFactory.createMessage();  
14         // 创建soap消息主体  
15         SOAPPart soapPart = soapMessage.getSOAPPart();  
16         SOAPEnvelope soapEnvelope = soapPart.getEnvelope();  
17         SOAPBody body = soapEnvelope.getBody();  
18         // 根据要传给mule的参数,创建消息body内容  
19          SOAPElement bodyElement =body.addChildElement(soapEnvelope.createName("amsPortal", "ns2875","http://tempuri.org"));  
20          bodyElement.addChildElement("secret").addTextNode("true");  
21          bodyElement.addChildElement("command").addTextNode("OracleCli");  
22          SOAPElement argsElement = bodyElement.addChildElement("args");  
23          argsElement.addChildElement("ConnStr").addTextNode("192.168.40.175:1521/orcl");  
24          argsElement.addChildElement("User").addTextNode("mtis");  
25          argsElement.addChildElement("Pass").addTextNode("mtis");  
26          soapMessage.saveChanges();  
27           
28          //     soapMessage = saveSoapChage(data, soapEnvelope, body, soapMessage);  
29          /*  
30          * 实际的消息是使用 call()方法发送的,该方法接收消息本身和目的地作为参数,并返回第二个 SOAPMessage 作为响应。  
31          * call方法的message对象为发送的soap报文,url为mule配置的inbound端口地址。  
32          */    
33         URL url = new URL("http://192.168.200.236/soap/soap_server_pro.php");  
34         // 响应消息  
35         SOAPMessage reply = soapConn.call(soapMessage, url);  
36         // 创建soap消息转换对象  
37         TransformerFactory transformerFactory = TransformerFactory.newInstance();  
38         Transformer transformer = transformerFactory.newTransformer();  
39         // 提取消息内容  
40         Source sourceContent = reply.getSOAPPart().getContent();  
41         //输出流  
42         ByteArrayOutputStream out = new ByteArrayOutputStream();  
43         StreamResult result = new StreamResult(out);  
44         //sourceContent实现此接口的对象包含充当源输入(XML 源或转换指令)所需的信息  
45         //result充当转换结果的持有者,可以为 XML、纯文本、HTML 或某些其他格式的标记  
46         transformer.transform(sourceContent, result);  
47         //返回结果  
48         String xmlData = new String(out.toByteArray());  
49         // xml解析  
50         xmlData = parserXml(data, xmlData);  
51         //输出到控制台  
52         System.out.println(xmlData);  
53         //关闭连接  
54         soapConn.close();  
55         return xmlData;  
56     }  

 

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/33205.html

(0)
上一篇 2023-12-09 17:33
下一篇 2023-12-10 22:33

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信