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);
            }
        }
    }
  • 相关阅读:
    C语言编程题目(5)单字符的位处理 数据加密
    C语言编程题目(4)文件高级应用与字符串高级操作
    C语言编程题目(3)文件类型操作
    C语言编程题目(2)基本数据类型操作
    个人总结
    第十六周进度条
    十五周进度条
    《人月神话》阅读笔记03
    《人月神话》阅读笔记02
    第十四周进度条
  • 原文地址:https://www.cnblogs.com/byxxw/p/5054734.html
Copyright © 2011-2022 走看看