我使用CXF 3.1.5,我試圖使它與代理一起使用。如果沒有用戶名和密碼的代理,那麼它的工作原理;如果有代理的用戶名和密碼,那麼它不起作用。這裏是我的代碼:
爲CXF設置ProxyAuthorizationPolicy httpConduit不起作用
//to create my own http conduit
bus.setExtension(new TLSAndProxySupportedHTTPConduitFactory(settings, HTTPConduitFactory.class);
//to get wsdl definition
Definition definition = bus.getExtension(WSDLManager.class).getDefinition(uri);
TLSAndProxySupportedHTTPConduitFactory實現HTTPConduitFactory,並將創建一個TLSAndProxySupportedHTTPConduit延伸URLConnectionHTTPConduit,在TLSAndProxySupportedHTTPConduit,這裏是代理設置相關的代碼:
//HTTPClientPolicy settings works
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setProxyServer(proxy.getHostName());
httpClientPolicy.setProxyServerPort(proxy.getPort());
this.setClient(httpClientPolicy);
if (proxy.getUserName() != null) {
//ProxyAuthorizationPolicy settings doesn't work
this.getProxyAuthorization().setUserName(proxy.getUserName());
this.getProxyAuthorization().setPassword(proxy.getPassword());
}
請記住,如果代理沒有用戶名和密碼,一切正常,如果加載WSDL定義的目標URL開始於https(https需要我),代理不起作用。如果它是以http開頭的,那麼帶有用戶名和密碼的代理運行良好。