Java Axis2甚至可以使用基本身份验证

Java Axis2甚至可以使用基本身份验证,java,web-services,axis2,Java,Web Services,Axis2,有可能吗?文件中没有明确说明。我尝试了各种不同的机制来实现身份验证,但我不断地遇到“401:Unauthorized”错误。以下是我的位置: stub = new EngineStub(); HttpClient client = new HttpClient(); client.getParams().setAuthenticationPreemptive(true); stub._getServiceClient().getServiceContext().

有可能吗?文件中没有明确说明。我尝试了各种不同的机制来实现身份验证,但我不断地遇到“401:Unauthorized”错误。以下是我的位置:

    stub = new EngineStub();

    HttpClient client = new HttpClient();
    client.getParams().setAuthenticationPreemptive(true);
    stub._getServiceClient().getServiceContext().getConfigurationContext().setProperty(HTTPConstants.CACHED_HTTP_CLIENT, client);

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
    List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.BASIC);
    auth.setAuthSchemes(authpref);
    auth.setUsername(username); 
    auth.setPassword(password);
    auth.setPreemptiveAuthentication(true);
    stub._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth);
stub=newenginestub();
HttpClient=新的HttpClient();
client.getParams().setAuthenticationPreemptive(true);
存根._getServiceClient().getServiceContext().getConfigurationContext().setProperty(HTTPConstants.CACHED_HTTP_客户端,客户端);
HttpTransportProperties.Authenticator auth=新的HttpTransportProperties.Authenticator();
List authpref=new ArrayList();
authpref.add(AuthPolicy.BASIC);
auth.setAuthSchemes(authpref);
auth.setUsername(用户名);
auth.setPassword(密码);
auth.setPreemptiveAuthentication(true);
stub.\u getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE,auth);

axis2使用基本身份验证是什么意思?如果您的后端服务是使用基本身份验证来保护的,那么您所要做的就是从客户端设置基本身份验证头并发送请求。您的客户端代码看起来是正确的;不确定身份验证策略;不要这样尝试

 auth.setUsername(USER_NAME);
    auth.setPassword(PASSWORD);
    auth.setPreemptiveAuthentication(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
    option.setManageSession(true);

请看一看:还可以分享如何为这些web服务配置安全性的详细信息。关于这方面的文档是无用的。整个事情都被打破了。几年后我得到了回答,但仍然没有回答。(几年后再次编辑。)