Created
March 31, 2014 00:52
-
-
Save rohgoyal/9882937 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:str="http://exslt.org/strings" xmlns:dp="http://www.datapower.com/extensions" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dpconfig="http://www.datapower.com/param/config" xmlns:dpfunc="http://www.datapower.com/extensions/functions" extension-element-prefixes="dp" exclude-result-prefixes="dp dpconfig dpfunc str"> | |
<!-- | |
############################################################################################ | |
Author : Rohit Goyal | |
Version : 0.1 | |
Description : This XSL is called as very first action when Request Received on HTTPRouter Service. | |
On the basis of URI, it choose manifest file. | |
Note: If for a URI, no manifest file is identified | |
Request will be rejected & HTTP Status code 404 will be returned | |
############################################################################################ | |
--> | |
<xsl:template match="/"> | |
<xsl:message dp:priority="debug">***Executing Router.XSL***</xsl:message> | |
<xsl:variable name="rootURL" select="'local:///HTTPRouter01'"/> | |
<xsl:message dp:priority="debug">rootURL '<xsl:value-of select="$rootURL"/>'</xsl:message> | |
<xsl:variable name="xsltRootURL" select="concat($rootURL,'/','xslt','/')"/> | |
<xsl:message dp:priority="debug">xsltRootURL: '<xsl:value-of select="$xsltRootURL"/>'</xsl:message> | |
<xsl:variable name="configRootURL" select="concat($rootURL,'/','config','/')"/> | |
<xsl:message dp:priority="debug">ConfigRootURL: '<xsl:value-of select="$configRootURL"/>'</xsl:message> | |
<!-- Find the HTTP Method --> | |
<xsl:variable name="method" select="dp:variable('var://service/protocol-method')"/> | |
<xsl:message dp:priority="debug">method '<xsl:value-of select="$method"/>'</xsl:message> | |
<!-- Fetching the service URI --> | |
<xsl:variable name="URI" select="dp:variable('var://service/URI')"/> | |
<xsl:message dp:priority="debug">URI '<xsl:value-of select="$URI"/>'</xsl:message> | |
<xsl:variable name="withoutParamURI"> | |
<xsl:choose> | |
<xsl:when test="contains($URI,'?')"> | |
<xsl:value-of select="substring-before($URI,'?')"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$URI"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:message dp:priority="debug">withoutParamURI '<xsl:value-of select="$withoutParamURI"/>'</xsl:message> | |
<xsl:variable name="uriTokens"> | |
<uriTokens> | |
<xsl:copy-of select="str:tokenize($withoutParamURI,'/')"/> | |
</uriTokens> | |
</xsl:variable> | |
<xsl:message dp:priority="debug">uriTokens '<xsl:copy-of select="$uriTokens"/></xsl:message> | |
<xsl:variable name="manifestFileName"> | |
<xsl:value-of select="$uriTokens/uriTokens/token[1]"/> | |
</xsl:variable> | |
<xsl:message dp:priority="debug">manifestFileName '<xsl:value-of select="$manifestFileName"/>'</xsl:message> | |
<!-- Find the account manifest file on the basis of the URI --> | |
<xsl:variable name="manifestFileLocation" select="concat($configRootURL,$manifestFileName,'.xml')"/> | |
<xsl:message dp:priority="debug">manifestFileLocation '<xsl:value-of select="$manifestFileLocation"/>'</xsl:message> | |
<xsl:choose> | |
<!-- Manifest File not found for Incoming token(1) URI --> | |
<xsl:when test="normalize-space(document($manifestFileLocation))=''"> | |
<dp:set-variable name="'var://service/mpgw/skip-backside'" value="'1'"/> | |
<dp:set-http-response-header name="'x-dp-response-code'" value="'404 Not Found'"/> | |
</xsl:when> | |
<!-- Manifest File found for Incoming token(1) URI --> | |
<xsl:otherwise> | |
<xsl:variable name="manifestFile"> | |
<xsl:copy-of select="document($manifestFileLocation)"/> | |
</xsl:variable> | |
<xsl:message dp:priority="debug">manifestFile '<xsl:copy-of select="$manifestFile"/></xsl:message> | |
<!-- Fetch Routing URL from Manifest File --> | |
<xsl:variable name="routingUrl"> | |
<xsl:value-of select="normalize-space($manifestFile/config/routingUrl/text())"/> | |
</xsl:variable> | |
<xsl:message dp:priority="debug">routingUrl '<xsl:value-of select="$routingUrl"/>'</xsl:message> | |
<!-- Set Routing URL --> | |
<dp:set-variable name="'var://service/routing-url'" value="concat($routingUrl,$URI)"/> | |
<xsl:copy-of select="."/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment