moshe
June 30, 2020, 7:12pm
1
I am trying to transform a SOAP XML using the learnwebservices.com demo
I setup a template to transform, and set the input type as XML
[Jun 30 19:04:46] ERROR Body transform failure api_id=da76007a-6533-49ef-96d1-0022584e8092 api_name=HelloEndpointService error=error unmarshalling XML: EOF mw=TransformMiddleware org_id=1 origin=172.17.0.1 path=/HelloEndpointService/HelloEndpointService/SayHello
my template file with no variables to transform at this point:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<SayHello xmlns="http://learnwebservices.com/services/hello">
<HelloRequest>
<Name>Mike</Name>
</HelloRequest>
</SayHello>
</soapenv:Body>
</soapenv:Envelope>
what am I doing wrong here?
moshe
July 9, 2020, 2:03pm
3
Hi,
I have since figured it out, it is a known bug
opened 01:54PM - 18 Sep 19 UTC
closed 02:10PM - 11 Aug 20 UTC
bug
**Branch/Environment/Version**
- Branch/Version: 2.8.4
- Environment: On-prem
…
**Describe the bug**
Tyk fails to run the transform middleware for templates loaded from file.
```
error="failed to apply template to request: template: : \"\" is an incomplete or empty template"
```
The above is logged when a request is made to the endpoint, and the request body is passed to upstream unchanged.
**Reproduction steps**
Steps to reproduce the behavior:
1. Add api...
2. Set up an endpoint with the body transform plugin:
- edit the raw api definition so that `extended_paths.transform` looks somewhat like;
```
"transform": [
{
"template_data": {
"input_type": "json",
"template_mode": "file",
"enable_session": false,
"template_source": "./templates/transform_test.tmpl",
"input": "",
"output": ""
},
"path": "/",
"method": "POST"
}
],
...
```
3. Place the template under the path defined in `template_source`
4. Restart tyk
5. Make request to defined endpoint as in [the docs](https://tyk.io/docs/transform-traffic/request-body/#json)
**Actual behavior**
The request body is passed on to the target url unchanged
**Expected behavior**
The template would be applied to transform the request body
I worked around it by switching to a blob of base64 but it is very inconvenient…
it seems that the master version of tyk includes the PR to fix it, however the current stable version is still broken. I mentioned it in the github bug.
I think it is important for Tyk to be more responsive to community raised issues to be considered to be part of a production product stack.
I like the product alot but it seems that bugs linger for too long, and we are talking of a basic transform functionality
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<SayHello xmlns="http://learnwebservices.com/services/hello">
<HelloRequest>
<Name>{{.name}}</Name>
</HelloRequest>
</SayHello>
</soapenv:Body>
</soapenv:Envelope>
"transform": [
{
"path": "HelloEndpointService/SayHello",
"method": "POST",
"template_data": {
"template_mode": "file",
"template_source": "transform/out-hello.tmpl",
"input_type": "json",
"enable_session": true
}
}
]
curl -s -X POST -H "authorization: 18498873b3c2b4725aaa0dfc7e2741d5" \
-H "Content-Type: application/json" \
-d '{"name": "My Name"}' \
http://localhost:8080/HelloEndpointService/HelloEndpointService/SayHello