zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    sql server 高可用日志传送
    sql server 高可用性技术总结
    sql server 分区(上)
    X86逆向10:学会使用硬件断点
    从零开始学 Web 之 jQuery(三)元素操作,链式编程,动画方法
    PIE SDK打开自定义栅格数据
    PIE SDK打开网络地图数据
    PIE SDK打开长时间序列数据
    Leetcode 75.颜色分类 By Python
    Leetcode 80.删除排序数组中的重复项 II By Python
  • 原文地址:https://www.cnblogs.com/sharpest/p/7868889.html
Copyright © 2011-2022 走看看