1

在为我的动态客户端从 https URL 加载 WSDL 之前,我需要在HttpConduit上设置适当的配置以避免所有 SSL 错误。根据文档,我们可以对管道进行硬编码,但不确定是否以编程方式进行。Client有没有办法在创建对象之前获取 HttpConduit DynamicClientFactory

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();
4

1 回答 1

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);
于 2017-04-25T20:33:32.193 回答