从安全服务检索 WSDL 文件

发布于 2024-09-25 18:36:35 字数 691 浏览 4 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身情人 2024-10-02 18:36:35

BindingProvider.USERNAME_PROPERTY、BindingProvider.PASSWORD_PROPERTY 主要用于服务请求。当您实例化 Service 时,它​​会获取 WSDL 并且服务器返回 401。您可以尝试以下任一解决方案:

  • 在客户端应用程序中使用 java.net.Authenticator 类。
  • 使用目录提供对 WSDL 的本地访问。
  • 配置 web.xml 以允许无需身份验证的 GET 请求。

参考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:

  • Use java.net.Authenticator class in your client application.
  • Provide a local access to the WSDL using catalog.
  • Configure web.xml to allow GET requests without authentication.

Reference java.boot.by

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文