[jboss-dev-forums] [JBoss ESB Development] - Re: Setting http client properties for HttpRouter from java code

tomas tomas do-not-reply at jboss.com
Mon Jan 2 06:58:31 EST 2012


tomas tomas [http://community.jboss.org/people/tomis] created the discussion

"Re: Setting http client properties for HttpRouter from java code"

To view the discussion, visit: http://community.jboss.org/message/644120#644120

--------------------------------------------------------------
I have found the solution. 

For those who will face this problem the solution is the following:

In java set the property "http-client-property" 
--------------------------------------------------------------------------------------------------
ConfigTree httpProps = new ConfigTree("http-client-property", c);
httpProps.setAttribute("name", "file");
String file = "{path to your http configuration file}/http.properties";
httpProps.setAttribute("value", file);
--------------------------------------------------------------------------------------------------

Then in your http.properties file add additional http configurator and http properties you want to set:
--------------------------------------------------------------------------------------------------
# Configurators
configurators=HttpProtocol, net.test.esb.configurators.HttpClientConfigurator

#timeout of creation connection
http.connection.timeout=10000
#timeout waiting of data
http.socket.timeout=10000
--------------------------------------------------------------------------------------------------

And finally write your custom configurator:
--------------------------------------------------------------------------------------------------
public class HttpClientConfigurator extends Configurator{
    private static Log LOG = LogFactory.getLog(HttpClientConfigurator.class);

    @Override
    public void configure(HttpClient httpclient, Properties properties)    throws ConfigurationException {
        if (properties != null){

            HttpConnectionManagerParams params = httpclient.getHttpConnectionManager().getParams();

            try {
                int timeout = Integer.valueOf(properties.getProperty(HttpConnectionParams.CONNECTION_TIMEOUT, "60000"));
                int stimeout = Integer.valueOf(properties.getProperty(HttpConnectionParams.SO_TIMEOUT, "60000"));

                if (timeout > 0){
                    params.setConnectionTimeout(timeout);
                }
                if (stimeout > 0){
                    params.setSoTimeout(stimeout);
                }

            } catch (Exception e) {
                LOG.error("configure", e);
            }


        }
    }
}
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/644120#644120]

Start a new discussion in JBoss ESB Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2032]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20120102/eea6d307/attachment.html 


More information about the jboss-dev-forums mailing list