Клиент CXF - TCP-соединение закрывается между каждым запросом

Я реализую один клиент SOAP, в целом работает нормально, но я заметил одну ловушку, потому что при каждом запросе TCP-соединение закрывается (мной).

Это неоптимально, и еще хуже, когда используется HTTPS, потому что сертификаты обмениваются при каждом запросе.

Создание httpconduit и вызов службы SOAP

public static void test(final String destination) {
        System.setProperty("javax.xml.soap.SAAJMetaFactory", "com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl");

        TLSClientParametersFactory tlsClientParametersFactory = new TLSClientParametersFactory
            .Builder()
            .acceptAllCerts()
            .build();

        JAXRSClientFactoryBean clientFactoryBean = new JAXRSClientFactoryBean();
        clientFactoryBean.setAddress(destination);

        WebClient webClient = clientFactoryBean.createWebClient();
        ClientConfiguration config = WebClient.getConfig(webClient);
        HTTPConduit conduit = config.getHttpConduit();

        HTTPClientPolicy client = conduit.getClient();
        client.setConnection(ConnectionType.KEEP_ALIVE);
        client.setConnectionTimeout(TimeUnit.MINUTES.toMillis(60));

        conduit.setTlsClientParameters(tlsClientParametersFactory.createTlsClient());

        Media media = createFactory(Media.class, conduit, tlsClientParametersFactory, destination);

        // The call of the soap service, with the expectation to have the same TCP connection used.
        List<Profile> profiles = media.getProfiles();
        List<Profile> profiles2 = media.getProfiles();
        List<Profile> profiles3 = media.getProfiles();
        List<Profile> profiles4 = media.getProfiles();
        List<Profile> profiles5 = media.getProfiles();

Создание порта SOAP

private static <T> T createFactory(final Class<T> clazz,
                                   final Conduit conduit,
                                   final TLSClientParametersFactory factory,
                                   final String destination)  {

    Map<String, Object> props = new HashMap<>();
    props.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    props.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
    props.put(WSHandlerConstants.PW_CALLBACK_CLASS, PasswordCallback.class.getName());
    props.put(WSHandlerConstants.USER, "test");
    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(props);

    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setAddress(destination);
    proxyFactory.setServiceClass(clazz);

    SoapBindingConfiguration config = new SoapBindingConfiguration();
    config.setVersion(Soap12.getInstance());
    proxyFactory.setBindingConfig(config);
    proxyFactory.setConduitSelector(new PreexistingConduitSelector(conduit));
    Map<String, Object> properties = proxyFactory.getProperties();
    if (properties == null) {
        properties = Maps.newHashMap();
    }
    properties.put(Client.KEEP_CONDUIT_ALIVE, true);
    proxyFactory.setProperties(properties);
    T t = proxyFactory.create(clazz);
    TLSClientParametersFactory.setSsClientParametersToPort(factory, t);
    return t;
}

Что я сделал не так ??

Примечание. Соединение закрывается при выполнении нового запроса. В противном случае TCP-соединение останется в силе.

Другой ввод Проблема присутствует не со всеми целевыми пунктами назначения. Например, если я использую устройство «Сетевой дверной контроллер AXIS A1001», система работает без повторного создания сокета tcp (разговор tcp окрашен)

Axis A1001 тот же сокет

Но пользуюсь "Сетевой камерой AXIS P5534", розетка пересоздана.

Несколько запросов к сетевой камере

И это мой компьютер (10.110.0.106) закрывает соединение введите здесь описание изображения

Используемая версия:

  • cxf-rt-ws-безопасность версии 3.3.6
  • cxf-rt-rs-клиент версии 3.3.6

person Manticore    schedule 23.04.2020    source источник


Ответы (1)


Наконец-то я нашел проблему, код не неисправной системы. Проблема связана с устройством Axis.

Хитрость заключается в том, что удаленное устройство закрывает поток TCP непосредственно в ответе SOAP (сообщении HTTP), и в этом случае wireshark не отображает [FIN, ACK]. Но если мы посмотрим непосредственно на уровень TCP, мы увидим, что были установлены флаги «TCP FIN»:

TCP FIN – ответ SOAP

person Manticore    schedule 24.04.2020