我有一個設置託管我的REST服務器的Tomcat服務器重定向從HTTP(端口9080)到HTTPS(端口9443)的調用。澤西jax.rs客戶端2.5遵循重定向
我使用球衣2.5實現,無法管理配置客戶端遵循重定向。
我發現了這個問題(Jersey client doesn't follow redirects),但它提供給運動衫1.X系列和API已更改。
我試着用下面的測試代碼,以使其適用於2.5:
SSLContextProvider ssl = new TrustAllSSLContextImpl(); // just trust all certs
Response response = ClientBuilder.newBuilder()
.sslContext(ssl.getContext()).newClient()
.register(LoggingFilter.class)
.target("http://testhost.domain.org:9080/rest.webapp/api/v1/hello/")
.property(ClientProperties.FOLLOW_REDIRECTS, Boolean.TRUE)
.request().get();
Assertions.assertThat(response.getStatus()).isNotEqualTo(302);
從而未能爲客戶似乎並不遵循重定向。以下是日誌過濾器提供:
Feb 14, 2014 12:23:45 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 1 * Sending client request on thread main
1 > GET http://testhost.domain.org:9080/rest.webapp/api/v1/hello/
Feb 14, 2014 12:23:45 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 1 * Client response received on thread main
1 < 302
1 < Cache-Control: private
1 < Content-Length: 0
1 < Date: Fri, 14 Feb 2014 11:38:59 GMT
1 < Expires: Thu, 01 Jan 1970 01:00:00 CET
1 < Location: https://testhost.domain.org:9443/rest.webapp/api/v1/hello/
1 < Server: Apache-Coyote/1.1
從球衣DOC我瞭解,所有需要做的是給ClientProperties.FOLLOW_REDIRECTS屬性添加到客戶端,但是這顯然不是成爲case.I還發現消息表明可能需要客戶端過濾器來遵循重定向,但沒有找到任何示例或準則。
所以,如果有人有一些jax.rs和重定向的經驗可以指向我的方向/文檔/示例代碼,我真的很感激。
我找到了答案在這裏http://stackoverflow.com/questions/1884230/urlconnection-doesnt-follow-redirect:有從HTTP重定向到https不適合工作安全原因。 –