Class AvailablePortFinderPropertiesFunction

  • All Implemented Interfaces:
    org.apache.camel.spi.PropertiesFunction

    public class AvailablePortFinderPropertiesFunction
    extends Object
    implements org.apache.camel.spi.PropertiesFunction
    A PropertiesFunction that reserves network ports and place them in a cache for reuse.

    The first time the function is invoked for a given name, an unused network port is determined and cached in an hash map with the given name as key so each time this function is invoked for the same name, the previously discovered port will be returned.

    This is useful for testing purpose where you can write a route like:

     
     from("undertow:http://0.0.0.0:{{available-port:server-port}}")
         .to("mock:result");
     
     
    And then you can invoke with ProducerTemplate like:
     
     template.sendBody("undertow:http://0.0.0.0:{{available-port:server-port}}", "the body");
     
     
    Doing so avoid the need to compute the port and pass it to the various method or store it as a global variable in the test class.
    See Also:
    AvailablePortFinder
    • Constructor Detail

      • AvailablePortFinderPropertiesFunction

        public AvailablePortFinderPropertiesFunction()
    • Method Detail

      • getName

        public String getName()
        Specified by:
        getName in interface org.apache.camel.spi.PropertiesFunction
      • apply

        public String apply​(String remainder)
        Specified by:
        apply in interface org.apache.camel.spi.PropertiesFunction