2 Replies Latest reply on Mar 12, 2012 9:53 AM by Jihed Ben Taher

    Setting http client properties for HttpRouter from java code

    Tomas Zuklys Newbie

      Hi all,

       

      Currently I'm using jbossesb 4.4.

       

      When using xml based configuration I can use the following XML to configure HttpRouter

      -----------------------------------------------

      <action name="httprouter" class="org.jboss.soa.esb.actions.routing.http.HttpRouter">

          <property name="endpointUrl" value="http://localhost:9433/x/y">

              <http-client-property name="file"

                  value="/META-INF/HttpRouter.properties" />

          </property>

          <property name="method" value="POST" /> <!-- Currently only supports GET or POST - easy to add more! -->

          <property name="responseType" value="STRING" /> <!-- Response should be set back on message as STRING or BYTES - default

              STRING -->

          <property name="headers"> <!-- Supports setting of arbitrary request headers -->

              <header name="blah" value="blahval" />

          </property>

      </action>

      -----------------------------------------------

       

      How all this can be done in java code?

       

      -----------------------------------------------

      ConfigTree c = _config.cloneObj();

      c.setAttribute("endpointUrl", "http://localhost:9433/x/y");

      c.setAttribute("method", "POST");

      c.setAttribute("responseType", "STRING");

       

       

      ??????????? How to set http client properties like connection timeout (http.connection.timeout), socket timeout (http.socket.timeout) and etc..  for HttpRouter?

       

      HttpRouter router = new HttpRouter(c);

      Message m = router.process(message);

      -----------------------------------------------

       

      Thanks in advance!

        • 1. Re: Setting http client properties for HttpRouter from java code
          Tomas Zuklys Newbie

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

                      }

                         

                     

                  }

              }

          }

          --------------------------------------------------------------------------------------------------

          • 2. Re: Setting http client properties for HttpRouter from java code
            Jihed Ben Taher Newbie

            Hello, i'm novice at programming on ESB,but  i need to know how can i do to send message from ESB to a Web page. Thanks