我面临一个问题,我需要为一个特定的web服务设置超时值,而不是为所有其他服务设置默认值。现在我需要找到一种方法,以某种方式通过编程覆盖我的服务的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和一个CustomINterceptor类来更新这些值:
<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();
}
}
}
'''