动态设置 Http Conduit 超时

Set Http Conduit timeout dynamically

我遇到一个问题,我需要将某个特定网络服务的超时设置为所有其他服务的默认值以外的值。现在我需要找到一种方法,以某种方式以编程方式覆盖我的服务的 http Conduit 超时。有人可以指导我如何实现这一目标吗? 这是我当前的配置和服务:

<http:conduit name="*.http-conduit">
        <http:client ConnectionTimeout="${httpConduit.connectionTimeout:30000}" ReceiveTimeout="${httpConduit.receiveTimeout:30000}" />
        <http:tlsClientParameters disableCNCheck="${httpConduit.ssl.disableCNCheck:false}">
            <sec:keyManagers keyPassword="${httpConduit.ssl.keyPassword}">
                <sec:keyStore type="${httpConduit.ssl.keyStoreType}" password="${httpConduit.ssl.keyStorePassword}" file="${httpConduit.ssl.keyStoreFile}" />
            </sec:keyManagers>
            <sec:trustManagers>
                <sec:keyStore type="${httpConduit.ssl.trustStoreType}" password="${httpConduit.ssl.trustStorePassword}" file="${httpConduit.ssl.trustStoreFile}" />
            </sec:trustManagers>
            <sec:cipherSuitesFilter>
                <sec:include>.*_EXPORT_.*</sec:include>
                <sec:include>.*_EXPORT1024_.*</sec:include>
                <sec:include>.*_WITH_DES_.*</sec:include>
                <sec:include>.*_WITH_AES_.*</sec:include>
                <sec:include>.*_WITH_NULL_.*</sec:include>
                <sec:exclude>.*_DH_anon_.*</sec:exclude>
            </sec:cipherSuitesFilter>
        </http:tlsClientParameters>
    </http:conduit>



<jaxrs:client id="testProxy" address="${test.endpoint}" threadSafe="true" serviceClass="foo.TestProxy">
        <jaxrs:headers>
            <entry key="Accept-Encoding" value="gzip,deflate" />
            <entry key="Content-Type" value="application/json;charset=UTF-8" />
            <entry key="Content-Length" value="92" />
            <entry key="Connection" value="Keep-Alive" />
        </jaxrs:headers>
        <jaxrs:providers>
            <ref bean="jsonProvider" />
        </jaxrs:providers>
        <jaxrs:features>
            <!-- Enables logging of the 'on-the-wire' request/response -->
            <bean class="org.apache.cxf.feature.LoggingFeature" />
        </jaxrs:features>
    </jaxrs:client>

问题已解决! 我在客户端创建了一个 out 拦截器 bean 和一个 CustomINInterceptor class 来更新值:

        <jaxrs:headers>
            <entry key="Accept-Encoding" value="gzip,deflate" />
            <entry key="Content-Type" value="application/json;charset=UTF-8" />
            <entry key="Content-Length" value="92" />
            <entry key="Connection" value="Keep-Alive" />
        </jaxrs:headers>
        <jaxrs:providers>
            <ref bean="jsonProvider" />
        </jaxrs:providers>
        <jaxrs:features>
            <!-- Enables logging of the 'on-the-wire' request/response -->
            <bean class="org.apache.cxf.feature.LoggingFeature" />
        </jaxrs:features>
       <jaxrs:outInterceptors>
            <ref bean="customInterceptor" />
        </jaxrs:outInterceptors>
    </jaxrs:client>

<bean id="customInterceptor" class="com.bmo.channel.alert.interceptor.CustomInterceptor" ></bean>


public class CustomInterceptor extends  AbstractPhaseInterceptor<Message>{

    
    
    public CustomInterceptor () {
        super(Phase.SETUP);
    }
    @Override
    public void handleMessage(Message message) {
        System.out.println("Inside handle message");
        try {
            final Conduit conduit = message.getExchange().getConduit(message);
            if (conduit instanceof HTTPConduit) {
                final HTTPConduit httpConduit = (HTTPConduit) conduit;
                HTTPClientPolicy policy = httpConduit.getClient();
                policy.setReceiveTimeout(timeout);
                policy.setConnectionTimeout(timeout);
                httpConduit.setClient(policy);
                System.out.println("ConnectionTimeout()  -- " + policy.getConnectionTimeout());
                System.out.println("ReceiveTimeout -- " + policy.getReceiveTimeout());
                System.out.println("HTTPClientPolicy -- " + policy.getHost());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
'''