Topic
  • 10 replies
  • Latest Post - ‏2013-09-16T15:29:45Z by swlinn
samuels
samuels
64 Posts

Pinned topic help for routing based on uri using xslt

‏2013-08-19T22:57:10Z |

i have 3 uri's /ccb, /ssh, /php . 

if the uri is /ccb/* it should go to "dev_pgw:50051" 

if the uri is /ssh/* it should go to "dev_pgw:50052"

if the uri is /php/* it should go to "dev_pgw:50053".........

dev_pgw is an alias for 210.0.10.19. i assigned that ip address to 3 mpgw services with port numbers 50051,50052 and 50053. so if the uri is /ccb/* then it should go to mpgw with port number 50051 ip address 210.0.10.9. 

i need to do this using an xml and xslt

  • swlinn
    swlinn
    1395 Posts

    Re: help for routing based on uri using xslt

    ‏2013-08-20T19:28:53Z  

    If you have an XML file that looks like

    <routes>

        <route uri="/ccb/">http://dev_pgw:50051</route>

        <route uri="/ssh/">http://dev_pgw:50052</route>

        <route uri="/php/">http://dev_pgw:50053</route>

    </routes>

    Then your xsl would do

    <xsl:variable name="routes" select="document('local:///myroutingfile.xml')" />

    <xsl:variable name="route" select="concat($routes/route[starts-with(dp:variable('var://service/URI'), @uri) ]/text(), dp:variable('var://service/URI'))" />

    Hopefully I have all of the parens right, but essentially you get the xml file into a variable and xpath into it, looking for the route element whose uri attribute is what the URI of your request starts with.  You concat the URI to get a full URL.  And to add a best practice, make sure you create a xml manager that has a document cache policy that will cache this document so it isn't reparsed for every request.

    Regards,

    Steve

  • samuels
    samuels
    64 Posts

    Re: help for routing based on uri using xslt

    ‏2013-09-10T17:06:21Z  
    • swlinn
    • ‏2013-08-20T19:28:53Z

    If you have an XML file that looks like

    <routes>

        <route uri="/ccb/">http://dev_pgw:50051</route>

        <route uri="/ssh/">http://dev_pgw:50052</route>

        <route uri="/php/">http://dev_pgw:50053</route>

    </routes>

    Then your xsl would do

    <xsl:variable name="routes" select="document('local:///myroutingfile.xml')" />

    <xsl:variable name="route" select="concat($routes/route[starts-with(dp:variable('var://service/URI'), @uri) ]/text(), dp:variable('var://service/URI'))" />

    Hopefully I have all of the parens right, but essentially you get the xml file into a variable and xpath into it, looking for the route element whose uri attribute is what the URI of your request starts with.  You concat the URI to get a full URL.  And to add a best practice, make sure you create a xml manager that has a document cache policy that will cache this document so it isn't reparsed for every request.

    Regards,

    Steve

    can we use

    <route uri="*">http://dev-pgw:50404</route>  in xml?

    i want all the services should go to that backend

  • Sudarshan Hebbar
    Sudarshan Hebbar
    57 Posts

    Re: help for routing based on uri using xslt

    ‏2013-09-11T03:27:37Z  
    • samuels
    • ‏2013-09-10T17:06:21Z

    can we use

    <route uri="*">http://dev-pgw:50404</route>  in xml?

    i want all the services should go to that backend

    Yes you can have <route uri="*">http://dev-pgw:50404</route>, however, matching all conditions should be applied in your xsl.

  • samuels
    samuels
    64 Posts

    Re: help for routing based on uri using xslt

    ‏2013-09-11T03:32:20Z  

    Yes you can have <route uri="*">http://dev-pgw:50404</route>, however, matching all conditions should be applied in your xsl.

    in xml if we define "*" it is taking it has a string....is there any other to define in xml? if define "*" in xml how to write xpath

     in xslt?

  • Sudarshan Hebbar
    Sudarshan Hebbar
    57 Posts

    Re: help for routing based on uri using xslt

    ‏2013-09-11T03:39:19Z  
    • samuels
    • ‏2013-09-11T03:32:20Z

    in xml if we define "*" it is taking it has a string....is there any other to define in xml? if define "*" in xml how to write xpath

     in xslt?

    Perhaps you can have something like <route uri="default">http://dev-pgw:50404</route>. I hope this would match your requirement.

  • samuels
    samuels
    64 Posts

    Re: help for routing based on uri using xslt

    ‏2013-09-11T03:44:16Z  

    Perhaps you can have something like <route uri="default">http://dev-pgw:50404</route>. I hope this would match your requirement.

    so if we write "default" in place of * in xml ,when we sent any uri it gonna work?

  • Sudarshan Hebbar
    Sudarshan Hebbar
    57 Posts

    Re: help for routing based on uri using xslt

    ‏2013-09-11T03:46:40Z  
    • samuels
    • ‏2013-09-11T03:44:16Z

    so if we write "default" in place of * in xml ,when we sent any uri it gonna work?

    Nope, still there has to be some XSL logic required.

  • David07
    David07
    77 Posts

    Re: help for routing based on uri using xslt

    ‏2013-09-11T12:07:17Z  
    • samuels
    • ‏2013-09-10T17:06:21Z

    can we use

    <route uri="*">http://dev-pgw:50404</route>  in xml?

    i want all the services should go to that backend

    Since you are routing to the same backend for all the requests ,you can use like this

    <routes>

        <route>http://dev_pgw:50404</route>

    </routes>

    <xsl:variable name="routes" select="document('local:///myroutingfile.xml')" />

    <xsl:variable name="route" select="concat($routes/route/text(), dp:variable('var://service/URI'))" />

     

    Regards,

    David.

    Updated on 2013-09-11T12:19:03Z at 2013-09-11T12:19:03Z by David07
  • samuels
    samuels
    64 Posts

    Re: help for routing based on uri using xslt

    ‏2013-09-11T13:32:14Z  
    • David07
    • ‏2013-09-11T12:07:17Z

    Since you are routing to the same backend for all the requests ,you can use like this

    <routes>

        <route>http://dev_pgw:50404</route>

    </routes>

    <xsl:variable name="routes" select="document('local:///myroutingfile.xml')" />

    <xsl:variable name="route" select="concat($routes/route/text(), dp:variable('var://service/URI'))" />

     

    Regards,

    David.

    hi david,

     

    we have three service CRE,PRE,ARE  the url will be  https://hostname/PPR/CRE, https://hostname/PPR/PRE, https://hostname/PPR/ARE and if the url is  https://hostname/PPR/* then backend should be http://ip_address:3020 ...if we define * n xml it is taking as a string. if we get all other service other than CRE,PRE,ARE then it should go to http://ip_address:3020

    our xml is

    <uri name="PPR">

            <service name="PRE">

                  <endpoint>http://ip_address:2020</endpoint>

    </service name>

     

            <service name="CRE">

                  <endpoint>http://ip_address:2022</endpoint>

    </service name>

     

            <service name="ARE">

                  <endpoint>http://ip_address:2023</endpoint>

    </service name>

            <service name="*">

                  <endpoint>http://ip_address:3020</endpoint>

    </service name>

    </uri>

     

  • swlinn
    swlinn
    1395 Posts

    Re: help for routing based on uri using xslt

    ‏2013-09-16T15:29:45Z  
    • samuels
    • ‏2013-09-10T17:06:21Z

    can we use

    <route uri="*">http://dev-pgw:50404</route>  in xml?

    i want all the services should go to that backend

    Sorry for my reply lag as I've been on vacation the past few weeks.  If you're looking for a more dynamic search of your table, in this case, a match all, I would use .* instead of * and treat your uri attribute as a pc regular expression.  Your code could do a regexp:test extension function on the uri attribute to see if the actual URI matches your regular expression.  A .* would match everything, but you could also use in other entries a regular expression to match multiple URIs that would use the same endpoint in one table entry.

    Regards,

    Steve