JerseyClient 使用 DefaultHttpClient

发布于 2024-11-26 04:05:33 字数 877 浏览 0 评论 0原文

我需要使用 Jersey Client 访问受 SSL 保护的 JAX-WS Web 服务。我已经通过有限的配置成功地实现了此功能,并且只是让客户端使用默认的 HTTPURLConnection API。

然而,这种方法不适用于我的整体解决方案,因为它不允许我灵活地更改向 WS 发出请求时使用的凭据。我尝试改用 DefaultHTTPClient,然后在初始化时将其传递给 Client 对象。

NTCredentials credentials = new NTCredentials("username", "password",
    computerName, domainName);
DefaultHttpClient httpClienttemp = new DefaultHttpClient();
DefaultHttpClient httpClient = wrapClient(httpClienttemp);
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials );
ClientConfig config = new DefaultClientConfig();

wrapClient 方法创建 X509TrustManager 并重写必要的方法,以便接受所有证书。它还为端口 443 上的 https 访问创建一个 SchemeRegistry 条目。此配置会导致连接被拒绝异常。

奇怪的是,如果我在http的SchemeRegistry中添加一个额外的条目并给它一个端口443,那么请求确实会被发送,但是会抛出一个连接重置异常。

我用来创建 WebResource 对象的 Url 是 https,但是我在标头中声明的 SOAPAction 使用 http。有什么想法我哪里出错了吗?

I need to access a JAX-WS webservice protected by SSL using Jersey Client. I have successfully got this working with limited configuration and just letting the Client use the default HTTPURLConnection API.

This approach wont work however for my overall solution because it does not allow me the flexibility to change the credentials used when making a request to the WS. I'm trying to use DefaultHTTPClient instead and then passing it to the Client object on intialization.

NTCredentials credentials = new NTCredentials("username", "password",
    computerName, domainName);
DefaultHttpClient httpClienttemp = new DefaultHttpClient();
DefaultHttpClient httpClient = wrapClient(httpClienttemp);
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials );
ClientConfig config = new DefaultClientConfig();

The wrapClient method creates an X509TrustManager and overrides the necessary methods so that all certificates are accepted. It also creates a SchemeRegistry entry for https access on port 443. This configuration results in a Connection refused exception.

The strange thing is, if i add an additional entry in the SchemeRegistry for http and give it a port of 443 then the request does get sent however a Connection Reset exception then gets thrown.

The Url i use to create the WebResource object is https however the SOAPAction i declare in the header uses http. Any ideas where im going wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

⊕婉儿 2024-12-03 04:05:33

这是 Jersey 文档中记录的默认 HTTP 客户端 (com.sun.jersey.api.client.Client) 的限制。您必须使用 Apache HTTP 客户端来实现此功能。

看起来有人已经在回答您之前的问题时建议这样做:Jersey Client API - 身份验证

编辑:更正了对默认 Jersey HTTP 客户端的引用以避免混淆。

This is a limitation of the default HTTP Client (com.sun.jersey.api.client.Client) documented in the Jersey docs. You will have to use Apache HTTP Client to achieve this functionality.

Looks like someone already recommended doing this in the answer to your previous question: Jersey Client API - authentication.

EDIT: Corrected reference to the default Jersey HTTP Client to avoid confusion.

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