下面的wsdlLocation是受密码保护的,但是偏执狂让我对为应用程序设置默认的Authenticator感到不舒服。如何在不使用默认身份验证器的情况下设置身份验证?
protected Orders getOrdersPort(String wsdlLocation, String namespaceURI) {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username", "password".toCharArray());
}
});
OrdersService service = new OrdersService(createUrlThrowRuntimeException(wsdlLocation), new QName(namespaceURI,
"OrdersService"));
Orders ordersPort = service.getOrdersSoap12();
setConnectionTimeout(ordersPort);
return ordersPort;
}
答案 0 :(得分:1)
当然,一种解决方法是将wsdl下载到本地文件并使用该文件。不过不会这么做会很好。