Ati*_*ran 6 java eclipse web-services cxf
我正在使用cxf网络服务客户端发送身份验证凭据,并显示:
javax.xml.ws.WebServiceException:无法发送消息。
由以下原因引起:org.apache.cxf.transport.http.HTTPException:与http:// localhost:8080 / AccountFacadeService / AccountService通信时,HTTP响应为“ 401:未经授权”
我的客户是:
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");
Run Code Online (Sandbox Code Playgroud)
我还缺少标题吗?
好吧,经过几个小时的深入研究这个问题,我终于找到了我的问题的答案。
roleglassfish 服务器控制台的安全领域中的配置正确,并且在glassfish-ejb-jar.xmlfinal String username = "user";
final String password = "pass";
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
username,
password.toCharArray());
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1961 次 |
| 最近记录: |