简体   繁体   English

动态设置 Http 导管超时

[英]Set Http Conduit timeout dynamically

I am facing an issue where I need to set timeout for one particular webservice to a value other than the default value for all other services.我面临一个问题,我需要将一个特定 Web 服务的超时设置为所有其他服务的默认值以外的值。 Now I need to find a way where I can somehow programmatically override the http Conduit timeout for my service.现在我需要找到一种方法,我可以以某种方式以编程方式覆盖我的服务的 http 管道超时。 Can someone please guide me how to achieve this?有人可以指导我如何实现这一目标吗? This is my current configuration and service:这是我当前的配置和服务:

<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>

Issue resolved: I created an out interceptor bean in the client and a CustomINterceptor class to update the values:已解决的问题:我在客户端创建了一个输出拦截器 bean 和一个 CustomINterceptor 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();
        }
    }
}
'''

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM