2017-04-23 81 views
1

從https URL爲我的動態客戶端加載WSDL之前,我需要在HttpConduit上設置適當的配置以避免所有SSL錯誤。根據docs,我們可以硬編碼管道,但不確定以編程方式執行。有沒有辦法在DynamicClientFactory上創建Client對象之前,我可以獲得HttpConduit?在CXF動態客戶端上加載WSDL之前訪問HttpConduit

JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); 

//Need to get HttpConduit here before the client is created, how? 
Client client = dcf.createClient(wsdlUri); 

// Can access http conduit only after client is created 
HTTPConduit conduit = (HTTPConduit) client.getConduit(); 
+0

設置'''HttpConduit''時無關緊要當客戶端正在使用時,它將被使用。所以你也可以在創建客戶端之後進行設置。 –

回答

1

一個辦法弄個HttpConduit和自定義HTTP(S)配置是通過HTTPConduitConfigurer。下面的代碼片段顯示瞭如何完成。

Bus bus = CXFBusFactory.getThreadDefaultBus(); 
bus.setExtension(new HTTPConduitConfigurer() { 

    @Override 
    public void configure(String name, String address, HTTPConduit conduit) { 
     //set conduit parameters ... 

     // ex. disable host name verification 
     TLSClientParameters clientParameters = new TLSClientParameters(); 
     clientParameters.setHostnameVerifier(new HostnameVerifier() { 
      @Override 
      public boolean verify(String hostname, SSLSession session) { 
       return true; 
      } 
     }); 
     conduit.setTlsClientParameters(clientParameters); 
    } 
}, HTTPConduitConfigurer.class); 

JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(bus); 
Client client = dcf.createClient(wsdlUri);