我正在使用cxf webservice客户端发送身份验证凭据,并说:
javax.xml.ws.WebServiceException:无法发送消息。
引起:org.apache.cxf.transport.http.HTTPException:HTTP响应 与401沟通时'401:未经授权' http://localhost:8080/AccountFacadeService/AccountService
我的客户是:
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");
我缺少哪些标题?
答案 0 :(得分:3)
好的,经过几个小时的挖掘,我终于找到了问题的答案。
role
,并在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());
}
});