I was hoping that https:/domain.com/abc/1.0 would be the bound endpoint for services and https:/domain.com/abc/1.0?wsdl would be the wsdl defining the service. (This is our pre-tyk setup)
The wsdl is generated w/ a binding endpoint to match the host passed in. But with tyk in between the host becomes something like backendapi.domain.com I was hoping to rewrite the xml back the caller.
Right, I think this might not be possible at the moment, matching is done on the path, not on path+params, so this would need to be part of an update down the line.
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.