2

I have configured timeouts for the HTTP Outbound Gateway providing a reference to a ClientHttpRequestFactory bean using the request-factory attribute:

<int-http:outbound-gateway request-channel="channelGetByCustomer"
    request-factory="requestFactoryGetByCustomer"
    reply-channel="jsonToObjectChannel" url="${getbycustomer.endpoint.url}"
    http-method="GET" expected-response-type="com.mbracero.integration.dto.Item[]">

    <int-http:uri-variable name="customerid" expression="payload.customerid"/>

</int-http:outbound-gateway>

<beans:bean id="requestFactoryGetByCustomer" class="org.springframework.http.client.SimpleClientHttpRequestFactory">
    <beans:property name="connectTimeout" value="${getbycustomer.timeout}"/>
    <beans:property name="readTimeout" value="${getbycustomer.timeout}"/>
</beans:bean>

But I want to load these attributes dynamically from DDBB (or programmatically) and not from Spring initial boot.

How can I do this?

mbracero
  • 77
  • 5

1 Answers1

2

Programmatically you can do that just from any your service injecting that requestFactoryGetByCustomer bean and using its setters:

@Autowired
private SimpleClientHttpRequestFactory requestFactoryGetByCustomer;

....

this.requestFactoryGetByCustomer.setConnectTimeout(30_000);

To read those options from the DB and populate them to the bean definition using Spring Container features (e.g. Property Placeholder like in your current case) you should take a look to the Commons Configuration framework and populate Properties object from the DB SELECT.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • But how can I set that to Outbound-gateway? Currently my gateway is in XML, have I change this to Java? – mbracero Aug 03 '15 at 18:55
  • No, it doesn't matter. Your service to set properties and `` will just share the same object and changes from the first one will impact the last one. Your XML configuration remains as is. – Artem Bilan Aug 03 '15 at 18:56
  • The `@Gateway` isn't related to the question at all. Please, don't mix concerns. You asked about `connectTimeout` for the `SimpleClientHttpRequestFactory` I've answered. I don't understand how `@Gateway` may relate: that option is a part of the factory for HTTP request, not your messaging process. – Artem Bilan Aug 03 '15 at 18:59
  • Yes, I thought it could setear through the gateway, and, as usual, is not possible – mbracero Aug 03 '15 at 19:07