我有一个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)
答案 0 :(得分: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的网址。