在Axis2中找不到HttpTransportProperties.Authenticator

时间:2017-07-18 15:12:35

标签: java web-services axis2 axis basic-authentication

使用 Apache Axis 2 从WSDL生成Java代码。该服务受基本身份验证保护。当我尝试创建身份验证对象以设置用户名和密码时,在库中找不到类(HttpTransportProperties.Authenticator)。

如何为 Apache Axis2 生成的客户端代码设置基本身份验证?

以下是设置基本身份验证参数的 旧方式

HttpTransportProperties.Authenticator basicAuth = new HttpTransportProperties.Authenticator();
basicAuth.setUsername("username");
basicAuth.setPassword("password");
basicAuth.setPreemptiveAuthentication(true);

final Options clientOptions = stub._getServiceClient().getOptions();
clientOptions.setProperty(HTTPConstants.AUTHENTICATE, basicAuth);
stub._getServiceClient().setOptions(clientOptions);

2 个答案:

答案 0 :(得分:7)

我有同样的问题!

解决方案:使用HttpTransportPropertiesImpl代替HttpTransportProperties

答案 1 :(得分:1)

    org.apache.axis2.client.OperationClient _operationClient = _serviceClient.createClient(_operations[1].getName());
    _operationClient.getOptions()
            .setAction("http://asdf/checkOutRequest");

    HttpTransportPropertiesImpl.Authenticator basicAuth = new HttpTransportPropertiesImpl.Authenticator();
    basicAuth.setUsername("tomcat");
    basicAuth.setPassword("tomcat");
    basicAuth.setPreemptiveAuthentication(true);

    final Options clientOptions = _operationClient.getOptions();
    clientOptions.setProperty(HTTPConstants.AUTHENTICATE, basicAuth);
    _operationClient.setOptions(clientOptions);

对于任何需要uwesch非常有用的答案的更清晰示例的人。