从安全服务检索 WSDL 文件
我有一个使用 JAX-WS 开发的 Web 服务。我已使用 Tomcat 中配置的 BASIC 身份验证来保护 Web 服务的安全。
当我尝试使用 Java 客户端访问 Web 服务时,我首先需要创建端口,然后指定凭据,如下所示:
CustomerServiceClient customerServiceClient = new CustomerServiceBottomUpService(); //1
CustomerService customer = customerServiceClient.getCustomerServicePort(); //2
Map<String, Object> context = ((BindingProvider) customer).getRequestContext(); //3
context.put(BindingProvider.USERNAME_PROPERTY, "kermit"); //4
context.put(BindingProvider.PASSWORD_PROPERTY, "thefrog"); //5
我遇到的问题是,在第 1 行之后,出现授权错误 (HTTP 401)因为我显然还没有向服务器提供凭据。
我正在从服务器 WSDL 创建客户端工件,因此在创建服务时会出现身份验证问题,并且不希望我的客户端在本地存储 WSDL,因为这对他们来说很烦人。我该如何解决这个问题?
I have a Web Service developed with JAX-WS. I have secured the web service with BASIC authentication configured in Tomcat.
When I try to access the web service using a Java client, I first need to create the port, and then specify the credentials, as follows:
CustomerServiceClient customerServiceClient = new CustomerServiceBottomUpService(); //1
CustomerService customer = customerServiceClient.getCustomerServicePort(); //2
Map<String, Object> context = ((BindingProvider) customer).getRequestContext(); //3
context.put(BindingProvider.USERNAME_PROPERTY, "kermit"); //4
context.put(BindingProvider.PASSWORD_PROPERTY, "thefrog"); //5
The problem I have is that, after line 1, I get an Authorization error (HTTP 401) as I obviously haven't provided the server with the credentials yet.
I am creating the client artifacts from a server WSDL, hence the authentication problem when creating the service, and don't want my clients to store the WSDL locally as it's just annoying for them. How can I get around this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
BindingProvider.USERNAME_PROPERTY、BindingProvider.PASSWORD_PROPERTY 主要用于服务请求。当您实例化 Service 时,它会获取 WSDL 并且服务器返回 401。您可以尝试以下任一解决方案:
参考java.boot.by
BindingProvider.USERNAME_PROPERTY, BindingProvider.PASSWORD_PROPERTY are used primarily for service requests. When you instantiate Service, it fetches WSDL and the server is returning 401. You could try any one of the following solutions:
Reference java.boot.by