Intercept and Transform a Published Web Service Request using XSLT before Import Mapping

0
Hi,   Is it possible to intercept the incoming request for a published web service so I may apply a transformation using XSLT BEFORE it hits my Import Mapping and gets processed?    My situation is that one of the third parties calling my service will not be conforming to my message structure therefore I need to transform their request which is a SOAP/XML message to match my Import Mapping.     So far I have found a brilliant app “XSLT” (by Shelterbox Trust) and built a microflow that will transform an input string, (which works great with a hard-coded test string sample I provide it) however I dont know how to get hold of the incoming request to use it as the input.   I am thinking I perhaps may need to setup a microflow with some Java code to be initiated at Runtime After Startup?   If this cant be done within Mendix, my only option is to setup another endpoint, external to Mendix, which will transform the request into the correct structure before it reaches my Mendix published service, which I really want to avoid.   Here is a screenshot of the XSLT component in my test microflow, with the Input Source string the parameter I need to obtain:   Any suggestions would be much appreciated.   BTW if it helps, my XSLT transformation is very simple in that it needs to add a <ROOT> element to the incoming message as follows, so my example using the “XSLT” app component mentioned above is as follows:     Source: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <SOAP-ENV:Header> <oas:Security> <oas:Timestamp> <oas:Created>2020-06-28T09:17:48.527Z</oas:Created> <oas:Expires>2020-06-28T09:22:48.527Z</oas:Expires> </oas:Timestamp> <oas:UsernameToken> <oas:Username>test</oas:Username> <oas:Password>test</oas:Password> </oas:UsernameToken> </oas:Security> </SOAP-ENV:Header> </SOAP-ENV:Envelope>   Stylesheet: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"     exclude-result-prefixes="SOAP-ENV oas">     <xsl:output method="xml" indent="yes"/>     <xsl:template match="@*|node()">        <xsl:copy>           <xsl:apply-templates select="@*|node()"/>        </xsl:copy>     </xsl:template>   <!-- special handling for SOAP-ENV:Header -->   <xsl:template match="SOAP-ENV:Header">     <xsl:copy>      <Root>    <xsl:apply-templates select="@*|node()"/>       </Root>     </xsl:copy>   </xsl:template>  </xsl:stylesheet>   Output String: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <SOAP-ENV:Header> <Root> <oas:Security> <oas:Timestamp> <oas:Created>2020-06-28T09:17:48.527Z</oas:Created> <oas:Expires>2020-06-28T09:22:48.527Z</oas:Expires> </oas:Timestamp> <oas:UsernameToken> <oas:Username>test</oas:Username> <oas:Password>test</oas:Password> </oas:UsernameToken> </oas:Security> </Root> </SOAP-ENV:Header> </SOAP-ENV:Envelope>   Thanks Shady Badawy
asked
3 answers
3

Hi again Shady,

I have got around similar issues by implementing a SOAP service using the published REST service in Mendix. This gives you explicit control over the exact request and response. The problem is, of course, that all the great out of the box stuff Mendix give you for SOAP will have to be done manually.

(edit) In fact, your idea of presenting a fronting service may be just the thing, but present a REST interface using the same app that calls the SOAP service internally with the modified request.

answered
0

If the other party cant conform to your PWS, you could provide an operation for them where they can send in the XML as a string variable. You can use the message definition functionality in Mendix to create an Import Mapping, which can then map the XML directly to the entities in your domain model.

answered
0

Hi Shady,

You can get hold of the raw response in the automatic variable $latestHttpResponse/Content that is set by the web service call. I ran it through an XSLT to strip out the SOAP envelope, which then leaves you with just the response payload. You can then transform that into something that can be mapped by Mendix. I also created a modified version of the WSDL from the web service with the problematic structures altered.

answered