13.AxisUtil

1.

 1 package com.glodon.gspm.adapter.plugin.common;
 2 
 3 import lombok.SneakyThrows;
 4 import org.apache.axis.client.Call;
 5 import org.apache.axis.client.Service;
 6 import org.apache.axis.message.SOAPBodyElement;
 7 import org.apache.axis.message.SOAPEnvelope;
 8 import org.apache.axis.message.SOAPHeaderElement;
 9 import org.w3c.dom.NodeList;
10 
11 
12 import javax.xml.namespace.QName;
13 import java.net.URL;
14 import java.util.Map;
15 
16 /**
17  * webService工具类
18  * Created by shijl-a on 2017/4/16.
19  */
20  public class AxisUtil {
21 
22     private AxisUtil() {
23         throw new IllegalStateException("Util class.");
24     }
25 
26     private static final int WS_TIMEOUT = 30000;
27 
28     private static final String NS = "http://tempuri.org/";
29 
30     @SneakyThrows
31     public static String invokeGeps(String webServiceUrl, String serviceName, Map<String, ?> args, String userName, String password) {
32 
33         SOAPEnvelope soapEnvelope = new SOAPEnvelope();
34         Service service = new Service();
35         Call call = (Call) service.createCall();
36         call.setTimeout(WS_TIMEOUT);
37         call.setTargetEndpointAddress(new URL(webServiceUrl));
38 
39         QName serviceQName = new QName(NS, serviceName);
40         QName credentialQName = new QName(NS, "ServiceCredential");
41 
42         call.setOperationName(serviceQName);
43         call.setUseSOAPAction(true);
44         call.setSOAPActionURI(NS + serviceName);
45 
46         SOAPHeaderElement header = new SOAPHeaderElement(credentialQName);
47         header.addChildElement("User").setValue(userName);
48         header.addChildElement("Password").setValue(password);
49 
50         soapEnvelope.addHeader(header);
51 
52         SOAPBodyElement bodyElement = new SOAPBodyElement(serviceQName);
53 
54         for (Map.Entry<String, ?> item : args.entrySet()) {
55             bodyElement.addChildElement(item.getKey()).setValue(item.getValue().toString());
56         }
57 
58         soapEnvelope.addBodyElement(bodyElement);
59 
60         SOAPEnvelope result = call.invoke(soapEnvelope);
61         NodeList nodes = result.getElementsByTagName(serviceName + "Result");
62         if (null != nodes && nodes.getLength() > 0 && null != nodes.item(0).getFirstChild()) {
63             return nodes.item(0).getFirstChild().getNodeValue();
64         }
65         return "";
66     }
67 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值