Java 使用cxf客户端发送基本身份验证凭据
我正在使用cxf webservice客户端发送身份验证凭据,它显示: javax.xml.ws.WebServiceException:无法发送消息 原因:org.apache.cxf.transport.http.HTTPException:http响应 “401:未经授权”在与 我的客户是:Java 使用cxf客户端发送基本身份验证凭据,java,eclipse,web-services,cxf,Java,Eclipse,Web Services,Cxf,我正在使用cxf webservice客户端发送身份验证凭据,它显示: javax.xml.ws.WebServiceException:无法发送消息 原因:org.apache.cxf.transport.http.HTTPException:http响应 “401:未经授权”在与 我的客户是: QName SERVICE_NAME = new QName("http://webservice.account.com/", "AccountFacadeService"); URL WSDL_
QName SERVICE_NAME = new QName("http://webservice.account.com/", "AccountFacadeService");
URL WSDL_LOCATION = http://localhost:8080/AccountFacadeService/AccountService?wsdl;
AccountFacadeService stub = new AccountFacadeService(WSDL_LOCATION, SERVICE_NAME);
AccountService port = stub.getAccountServicePort();
((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "user");
((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pass");
还有更多我遗漏的标题吗?好吧,经过几个小时的深入研究,我终于找到了问题的答案
角色
配置正确,并且在glassfish ejb jar.xml中维护该角色
final String username = "user";
final String password = "pass";
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
username,
password.toCharArray());
}
});