如何在不使用默认Authenticator的情况下使用JAXWS访问受密码保护的WSDL?

Jon*_*son 5 java web-services jax-ws

下面的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;
}
Run Code Online (Sandbox Code Playgroud)

Jon*_*son 1

当然,一种解决方法是将 wsdl 下载到本地文件并使用该文件。不过,如果不必这样做就好了。