Results 1 to 3 of 3

Thread: how to use URI-VARIABLE for port number

  1. #1
    Join Date
    Nov 2012
    Posts
    2

    Default how to use URI-VARIABLE for port number

    Goal is to provide a variable port number for the following outbound http gateway.

    <int-http:outbound-gateway id="httpOutboundGateway"
    url="http://{myHost}:{myPort}/services/{myPath}?{myQuery}"
    ... >

    <int-http:uri-variable name="myHost" expression="headers['X-CUSTOM-PROVIDER-HOSTNAME']" />
    <int-http:uri-variable name="myPort" expression="headers['X-CUSTOM-PROVIDER-PORT']" />
    <int-http:uri-variable name="myPath" expression="headers['X-CUSTOM-PROVIDER-PATH']" />
    <int-http:uri-variable name="myQuery" expression="headers['X-CUSTOM-PROVIDER-QUERY']" />

    </int-http:outbound-gateway>

    Three of the four URI-VARIABLES work fine - except myPort.

    Supplied port number is always translated as part of the path (ie http://myHost/myPort/..). Digging into SI v3.1.2.RELEASE code, I find the org.springframework.web.util.UriComponentBuilder class responsible for translating my token URI. The class has a regex pattern for port that looks for digits (PORT_PATTERN = (\\d*) ). Fine if a number is supplied, but it doesn't appear to allow for a variable port number in the form of '{token}'.

    Can I do the port replacement in the URI?

    thanks

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,015

    Default

    I assume you mean Spring 3.1.2 not SI 3.1.2.

    Spring 3.1 had to make some changes to solve some other issues and this changed the way uris are built.

    In Spring Integration 2.2, we introduced 'url-expression' as an alternative to using 'url' with uri-variables to avoid these kinds of issues.

    Using uri-expression, you can insert your headers in-line, to build up the full URL.

    Code:
    url-expression="'http//' + headers['X-CUSTOM-PROVIDER-HOSTNAME'] + "':'" + headers['X-CUSTOM-PROVIDER-HOSTNAME'] ... etc
    This is available in Spring Integration 2.2.0, which will be released shortly. 2.2.0.RC3 was released last week; you may find 2.2.0.RELEASE in maven central over the weekend.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Nov 2012
    Posts
    2

    Cool life is good

    thanks Gary - the new version & technique did the job. many thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •