zoukankan      html  css  js  c++  java
  • java 简单解析wsdl

    static void resolve(String wsdl) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
    
        InputStream in = new ByteArrayInputStream(wsdl.getBytes("utf-8"));
        InputStreamReader isr = new InputStreamReader(in, "utf-8");
    
        InputSource is = new InputSource(isr);
        Document doc = builder.parse(is);
    
        System.out.println("root:" + doc.getFirstChild().getNodeName());
    
        NodeList nodeList = doc.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/", "definitions");
        Node root = nodeList.item(0);
        NamedNodeMap map = root.getAttributes();
        Node targetNs = map.getNamedItem("targetNamespace");
        System.out.println("名称空间:" + targetNs.getNodeValue());
    
        String wsdlNsUri = "http://schemas.xmlsoap.org/wsdl/";
    
        NodeList bindingNodes = doc.getElementsByTagNameNS(wsdlNsUri, "binding");
        Node bindingNode = bindingNodes.item(0);
        String serviceName = bindingNode.getAttributes().getNamedItem("name").getNodeValue();
        System.out.println("服务名:" + serviceName);
    
        NodeList serviceNodes = doc.getElementsByTagNameNS(wsdlNsUri, "service");
        Node serviceNode = serviceNodes.item(0);
        NodeList portNodes = serviceNode.getChildNodes();
        
        String bindingAddress = null;
        Node addressNode = portNodes.item(1).getChildNodes().item(1);
        bindingAddress = addressNode.getAttributes().getNamedItem("location").getNodeValue();
        System.out.println("调用地址:" + bindingAddress);
    
        NodeList portTypeNodes = doc.getElementsByTagNameNS(wsdlNsUri, "portType");
        Node portType = portTypeNodes.item(0);
        NodeList opNodes = portType.getChildNodes();
        for (int i = 0; i < opNodes.getLength(); i++) {
            Node node = opNodes.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE && node.getLocalName().equalsIgnoreCase("operation")) {
                String methodName = node.getAttributes().getNamedItem("name").getNodeValue();
                System.out.println("方法名:" + methodName);
            }
        }
    }
  • 相关阅读:
    docker搭建mongodb
    mongodb的搭建
    Mysql错误:Ignoring query to other database解决方法
    BZOJ4567:[SCOI2016]背单词——题解
    BZOJ4570:[SCOI2016]妖怪——题解
    BZOJ4753:[JSOI2016]最佳团体——题解
    BZOJ1853:[SCOI2010]幸运数字 & BZOJ2393:Cirno的完美算数教室——题解
    LOJ6388:[THUPC2018]赛艇——题解
    BZOJ5217:[Lydsy2017省队十连测]航海舰队——题解
    BZOJ4259:残缺的字符串——题解
  • 原文地址:https://www.cnblogs.com/byxxw/p/5054734.html
Copyright © 2011-2022 走看看