CXF RESTful 客户端 - 如何在没有 Spring 的情况下进行基本的 http 身份验证?
我熟悉使用 Jersey 创建 RESTful Web 服务服务器和客户端,但由于 类加载问题,我正在尝试将 Jersey 客户端转换为 CXF。我相信我想使用以 HTTP 为中心的客户端,但我们不使用 Spring。我们需要使用基本的 HTTP 身份验证。 用户指南有以下示例:
WebClient client = WebClient.create("http:books", "username", "password", "classpath:/config/https.xml");
第一个参数是' t 一个 URI 字符串。这是Spring使用的格式吗?这个方法只能用于使用Spring创建WebClient吗?
显示的另一种进行身份验证的方法是添加标头字符串:
String authorizationHeader = "Basic " + org.apache.cxf.common.util.Base64Utility.encode("user:password".getBytes());
webClient.header("Authorization", authorizationHeader);
我猜测 "user:password"
应该替换为真实值,但希望得到确认。
I am familiar with using Jersey to create RESTful webservice servers and clients, but due to class loading issues, I am trying to convert a Jersey client into CXF. I believe I want to use an HTTP-centric client but we don't use Spring. We need to use basic HTTP authentication. The user guide has this example:
WebClient client = WebClient.create("http:books", "username", "password", "classpath:/config/https.xml");
The first parameter isn't a URI string. Is it a format used by Spring? Can this method only be used to create WebClients using Spring?
The other way of doing authentication shown is to add a header string:
String authorizationHeader = "Basic " + org.apache.cxf.common.util.Base64Utility.encode("user:password".getBytes());
webClient.header("Authorization", authorizationHeader);
I am guessing that "user:password"
should be substituted with the real values, but would appreciate confirmation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个答案来自 CXF 用户邮件列表。
上面引用的第一个示例中有一个拼写错误。它已更新为:
如果未使用 Spring 配置文件(因此 Spring),第四个参数可以为 null。
所以,这对我有用:
This answer came from the CXF users mailing list.
The first example referenced above had a typo in it. It has been updated to:
The fourth argument can be null if a Spring config file is (and therefore Spring) is not being used.
So, this worked for me: