gpt4 book ai didi

java - 如何使用 wsld4j 读取安全的 wsdl

转载 作者:太空宇宙 更新时间:2023-11-04 07:11:59 26 4
gpt4 key购买 nike

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

"faultCode=OTHER_ERROR: Unable to resolve imported document"

完整的错误堆栈在这里[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)

最佳答案

    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。

关于java - 如何使用 wsld4j 读取安全的 wsdl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20513872/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com