使用 Java 从 URL 读取 XSD

目标:我想读取 WSDL 并打印 WSDL、复杂类型和复杂类型定义中的服务。


工作过:我使用 WSDL4J 来读取 WSDL 并成功打印服务及其参数(复杂类型)。现在我想阅读 XSD 中可用的复杂类型定义。我无法读取 XSD 。有什么办法吗?


我得到 XSModel 为空


import java.util.ArrayList;

import java.util.Collection;

import java.util.List;

import java.util.Map;


import javax.wsdl.BindingOperation;

import javax.wsdl.Definition;

import javax.wsdl.WSDLException;

import javax.wsdl.xml.WSDLReader;

import org.w3c.dom.bootstrap.DOMImplementationRegistry;


import com.ibm.wsdl.BindingImpl;

import com.ibm.wsdl.xml.WSDLReaderImpl;

import com.sun.org.apache.xerces.internal.impl.xs.XSImplementationImpl;

import com.sun.org.apache.xerces.internal.xs.XSLoader;

import com.sun.org.apache.xerces.internal.xs.XSModel;


public class WSDLDetails {


    public static void main(String[] args) {

        try {

            String wsdlURL = "https://abc.xyz.com/webservice/MessagingSevice?WSDL";

            String xsdURL = "https://abc.xyz.com/webservice/MessagingSevice?xsd=1";

            java.lang.System.setProperty("https.protocols", "TLSv1.2");

            getAllBindingOperation(wsdlURL);

            readXSD(xsdURL);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }


    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", false);

            Definition definition = reader.readWSDL(wsdlUrl.toString());

            Map<String, BindingImpl> defMap = definition.getAllBindings();

            Collection<BindingImpl> collection = defMap.values();

            for (BindingImpl binding : collection) {

                operationList.addAll(binding.getBindingOperations());

            }


开满天机
浏览 190回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java