Topic
  • 4 replies
  • Latest Post - ‏2014-01-02T15:18:18Z by ted.jump
thotranh
thotranh
81 Posts

Pinned topic dynamic context URI

‏2013-12-31T14:37:05Z |

I have a MPGW and it proxies a lot of different requests .  I have a policy with an XSL that has logic for different request contexts (URI).

For example,

incoming requests to the DataPower's MPGW can be 

http://.../context1/...

http://.../context2/....

In XSL, depending on which context it is , i have to do something different for a certain one

eg.

if  context is "context1" , ....

else if context is "context2" ....

However, I don't want to hard-code "context1" or "context2" . What'd be the best way to dynamically do this without having to hard-code the context names in the XSL ?

Please advise.

Thanks

  • kenhygh
    kenhygh
    1607 Posts

    Re: dynamic context URI

    ‏2013-12-31T18:40:24Z  

    How would you solve something like this in another language? do that. 

    What I've done for this in the past looks something like

    
    
    <xsl:variable name="context">
    

      // figure out what the context is

    </xsl:variable>

    <xsl:variable name="Plugin" select="concat('local:///',$context,'.xsl')"/>

    <xsl:variable name="DidSomethingSpecificWithContext">

      <xsl:copy-of select="dp:transform($Plugin,.)"/>

    </xsl:variable>

     

    so now you're in a situation where for any context, you can have a stylesheet local:///CONTEXT.xsl, which can have a <xsl:match='/'> that can do anything you want it to.

  • ted.jump
    ted.jump
    328 Posts

    Re: dynamic context URI

    ‏2014-01-02T02:33:53Z  

    I've used XML data to describe the mapping from the input to the back-side context, using some elements of the request data as the basis for an XPATH based lookup into the XML.

    This is relatively easily done using the request URI, or data extracted from the request data (in my case I used the namespace-uri and object-name of the first child of the SOAP Envelope/Body element).

    Storing the mapping data in an XML file (either on the appliance or on an HTTP server) makes it easy to enable different routing based upon the input data.

    regards,

    -t

  • thotranh
    thotranh
    81 Posts

    Re: dynamic context URI

    ‏2014-01-02T14:07:43Z  
    • ted.jump
    • ‏2014-01-02T02:33:53Z

    I've used XML data to describe the mapping from the input to the back-side context, using some elements of the request data as the basis for an XPATH based lookup into the XML.

    This is relatively easily done using the request URI, or data extracted from the request data (in my case I used the namespace-uri and object-name of the first child of the SOAP Envelope/Body element).

    Storing the mapping data in an XML file (either on the appliance or on an HTTP server) makes it easy to enable different routing based upon the input data.

    regards,

    -t

    Thank you for the advice.

    In fact, I do have an XML to map the context . HOwever, in order to put in a certain logic for each context  in an XSL , I still need to hard-code  it, and I'm trying to find a way to avoid the hard-coding .

    Eg. for a post-process XSL, i currently have the logic :

    if the context === "context1" --->  put in some extra headers in the HTTP request

    else ---> keep going 

    etc. 

    I wonder if , instead of hard-coding "context1", i can use some feature in the DP configuration to do this ...

    That's all.  Thanks again

  • ted.jump
    ted.jump
    328 Posts

    Re: dynamic context URI

    ‏2014-01-02T15:18:18Z  
    • thotranh
    • ‏2014-01-02T14:07:43Z

    Thank you for the advice.

    In fact, I do have an XML to map the context . HOwever, in order to put in a certain logic for each context  in an XSL , I still need to hard-code  it, and I'm trying to find a way to avoid the hard-coding .

    Eg. for a post-process XSL, i currently have the logic :

    if the context === "context1" --->  put in some extra headers in the HTTP request

    else ---> keep going 

    etc. 

    I wonder if , instead of hard-coding "context1", i can use some feature in the DP configuration to do this ...

    That's all.  Thanks again

    What is is that you are needing to hard-code?

    I originally thought I was going to need to hard code a bunch of stuff, but by building some local variables and using that as part of the xpath to select data from the reference XML I was able to completely do away with the hard coding in the XSL files.

    More details may be helpful, if you can share.

    Updated on 2014-01-02T18:11:46Z at 2014-01-02T18:11:46Z by ted.jump