1

我有一个 wsdl 存储在一个受 HTTP BasicAuth 保护的地方。我尝试从中读取 wsdl,如下所述[1];但我得到以下错误

“faultCode=OTHER_ERROR:无法解析导入的文档”

完整的错误堆栈在这里[2]。任何人都知道我如何使用 wsdl4j 从安全的地方读取 wsdl?

[1]

           WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
        // switch off the verbose mode
        reader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
        reader.setFeature("javax.wsdl.importDocuments", false);
        wsdlDefinition = reader.readWSDL(baseURI);

[2]

 at java.lang.Thread.run(Thread.java:662)

Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=OTHER_ERROR: Unable to resolve imported document at 'http://10.100.1.35:9763/registry/re
source/_system/governance/apimgt/wsdls/admin--aa1.0.0.wsdl'.: java.io.IOException: Server returned HTTP response code: 401 for URL: http://10.100.1.35
:9763/registry/resource/_system/governance/apimgt/wsdls/admin--aa1.0.0.wsdl
        at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2259)
        at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2207)

        at java.lang.Thread.run(Thread.java:662)
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=OTHER_ERROR: Unable to resolve imported document at 'http://10.100.1.35:9763/registry/re
source/_system/governance/apimgt/wsdls/admin--aa1.0.0.wsdl'.: java.io.IOException: Server returned HTTP response code: 401 for URL: http://10.100.1.35
:9763/registry/resource/_system/governance/apimgt/wsdls/admin--aa1.0.0.wsdl
        at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2259)
        at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2207)
4

1 回答 1

1
    String name = "admin";
    String password = "admin";

    String authString = name + ":" + password;
    System.out.println("auth string: " + authString);
    byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
    //byte[] authEncBytes= BASE64Encoder.encode(authString.getBytes();

    String authStringEnc = new String(authEncBytes);
    System.out.println("Base64 encoded auth string: " + authStringEnc);

    URL url = new URL(webPage);
    URLConnection urlConnection = url.openConnection();
    urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);

在此之后添加您的代码以读取 wsdl。如果对该 wsdl 使用基本身份验证,那么它应该可以工作。

网页是 wsdl 的 url。

于 2013-12-12T04:11:28.490 回答