You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by harald <su...@rainyday.de> on 2015/09/10 13:07:48 UTC

Howto replace Camel HttpConnectionManager or HeaderFilterStrategy in SMX4.5.3

Hi,
I need to replace the HttpConnectionManager of a Camel context within SMX4.5.3 because the http requests resulting from the Camel route are load-balanced before hitting the backend server. Problem is that the connections are kept open and no load-balancing is done. Only way I see is to either provide a Connection-header which is currently filtered out by the default HeaderFilterStrategy implementation or by enforcing the close of the connection by replacing the HttpConnectionManager. Tried a few other things like http.keepAlive=false as JVM parameter and stuff like this and nothing worked for me. Any further ideas?

So I first tried to replace the HttpConnectionManager and/or HeaderFilterStrategy by the following:

  <bean id="httpz" class="org.apache.camel.component.http.HttpComponent">
    <property name="camelContext" ref=“myTestContext"/>
    <property name="httpConnectionManager" ref="myHttpConnectionManager"/>
    <property name="headerFilterStrategy"  ref="myHeaderFilterStrategy"/>
  </bean>
  <bean id="myHttpConnectionManager" class=“playground.ForcedCloseHttpConnectionManager">
    <argument value="true"/>
    <property name="params" ref="myHttpConnectionManagerParams"/>
  </bean>
  <bean id="myHeaderFilterStrategy" class="playground.HttpHeaderFilterStrategy">
  </bean>
  <bean id="myHttpConnectionManagerParams" class="org.apache.commons.httpclient.params.HttpConnectionManagerParams">
    <property name="defaultMaxConnectionsPerHost" value="5"/>
  </bean>
:
<camelContext id=“myTestContext”>
  :
  <to uri=“httpz:http://127.0.0.1:8080/test/process”/>
  :
</camelContext>

The “playground.ForcedCloseHttpConnectionManager” is a copy of the MultiThreadedHttpConnectionManager class provided by Camel with some log messages added (enabled by the constructor argument ’true’).

The “playground.HttpHeaderFilterStrategy” is a copy of the HttpHeaderFilterStrategy class provided by Camel - again with some log messages added.

The log shows that the beans got initialised. Switching SMX to DEBUG level and executing the route shows that the MultiThreadedHttpConnectionManager is still used to handle the connections.

Thanks for any help,
harald