加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

soap-ws 获取wsdl中所有方法 (二)

发布时间:2020-12-16 21:54:04 所属栏目:安全 来源:网络整理
导读:2. 获取portType节点的所有operation 获取portType节点的operation比较麻烦,soap-ws没有提供直接可以使用的接口。 不过可以参考soap-ws的源码写一个方法。 soap-ws提供了一些example。参考例子: soap-wssoap-examplesquickstartsrctestjavaorgrefic

2. 获取portType节点的所有operation

获取portType节点的operation比较麻烦,soap-ws没有提供直接可以使用的接口。
不过可以参考soap-ws的源码写一个方法。
soap-ws提供了一些example。参考例子:
soap-wssoap-examplesquickstartsrctestjavaorgreficiowsquickstartSoapClientExamplesTest.java
在IntelliJ IDEA中debug,eclipse中看起来不舒服。

这里写图片描述

可以看到在wsdl的私有成员soapFacade中有portType节点,binding节点信息。这些信息最终是定义在messageBuilder的私有变量definition中的,按照这个路径查看源代码。查看SoapMessageBuilder的构造方法。

public SoapMessageBuilder(URL wsdlUrl) throws WSDLException {
        WSDLReader reader = new WSDLReaderImpl();
        reader.setFeature("javax.wsdl.verbose",false);
        this.definition = reader.readWSDL(wsdlUrl.toString());
        this.definitionWrapper = new SchemaDefinitionWrapper(definition,wsdlUrl.toString());
    }

根据上面的代码进行改造。完整的代码如下:

private static List<Operation> getPortTypeOperations(String wsdlUrl) {
        List<Operation> operationList = new ArrayList();
        try {
            WSDLReader reader = new WSDLReaderImpl();
            reader.setFeature("javax.wsdl.verbose",false);
            Definition definition = reader.readWSDL(wsdlUrl.toString());
            Map<String,PortTypeImpl> defMap = definition.getAllPortTypes();
            Collection<PortTypeImpl> collection = defMap.values();
            for (PortTypeImpl portType : collection) {
                operationList.addAll(portType.getOperations());
            }
        } catch (WSDLException e) {
            System.out.println("get wsdl operation fail.");
            e.printStackTrace();
        }
        return operationList;
    }

获取operation的名字

public static List<String> getOperationByUrl(String wsdlUrl) {
        List<String> resultList = new ArrayList<>();
        List<Operation> operationList = getPortTypeOperations(wsdlUrl);
        for (Operation operation : operationList) {
            resultList.add(operation.getName());
        }
        return resultList;
    }

上面的方法也可以获取Binding节点的operation。代码如下

public static List<String> getAllBindingOperation(String wsdlUrl) {
        List<BindingOperation> operationList = new ArrayList();
        List<String> nameList = new ArrayList();
        try {
            WSDLReader reader = new WSDLReaderImpl();
            reader.setFeature("javax.wsdl.verbose",BindingImpl> defMap = definition.getAllBindings();
            Collection<BindingImpl> collection = defMap.values();
            for (BindingImpl binding : collection) {
                operationList.addAll(binding.getBindingOperations());
            }
            for (BindingOperation operation:operationList) {
                nameList.add(operation.getName());
            }
        } catch (WSDLException e) {
            System.out.println("get wsdl operation fail.");
            e.printStackTrace();
        }
        return nameList;
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读