There might be a workaround here, it involves redirects and virtual endpoints:
1. Have some PRE middleware that detects the wsdl parameter:
var helloWorld = new TykJS.TykMiddleware.NewMiddleware({});
log("------------ Initialising PRE middleware ------------");
helloWorld.NewProcessRequest(function(request, session, config) {
log("Running sample PRE PROCESSOR JSVM middleware with iteration")
if (request.Params.hasOwnProperty("wsdl")) {
log("WSDL Detected!")
request.URL = "/reserved/wsdl/getter"
request.AddParams["wsdl"] = "123"
}
log("Done")
return helloWorld.ReturnData(request, {});
});
// Ensure init with a post-declaration log message
log("------------ Sample PRE middleware initialised ------------");
The above will only change our path variable if we detect the wsdl
paramter, we then change the URL (path) of the request, and also - for the sake of it, add the wsdl
param back.
2. Create a virtual endpoint that fetches the WSDL, and modifies the XML in some way to return to the end user:
function getXML (request, session, config) {
log("XML Test running")
var newRequest = {
"Method": "GET",
"Body": "",
"Headers": {},
"Domain": "http://httpbin.org",
"Resource": "/get",
"FormData": {"wsdl": "my-custom-param", "foo":"bar"}
};
var resp = TykMakeHttpRequest(JSON.stringify(newRequest))
log("Got resp")
var cleanResp = JSON.parse(resp)
var responseObject = {
Body: cleanResp.Body,
Code: cleanResp.Code
}
log("Responding")
return TykJsResponse(responseObject, session.meta_data)
}
log("---------> getXML initialised")
(edit: The Form Data does not seem to be working properly, we’ll need to investigate why that is).
The above function just makes a request to /get on httpbin and pushes the response back to the user. But the principle is the same.
So essentially:
- Pre Middleware detects the
?wsdl
querystring, if it detects it, it redirects the request to a reserved virtual path - The virtual path then handles fetching the actual WSDL and transforms it as needed for the end user.