在 Axis2 中找不到 HttpTransportProperties.Authenticator



刚刚使用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);

我遇到了同样的问题!

解决方案:使用HttpTransportPropertiesImpl而不是HttpTransportProperties

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非常有用的答案的人。

相关内容

  • 没有找到相关文章

最新更新