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 }