Closed NahidAfzali closed 1 year ago
I also want to mention that there is no more sample for the template, and that's not good for your product. This plugin is really important and should have more samples and documents.
Essentially, this isn't a bug, is it?
I also want to mention that there is no more sample for the template, and that's not good for your product. This plugin is really important and should have more samples and documents.
@NahidAfzali Hi, it seems that your response is not a valid XML text.
Could you paste your route configuration and error log in the markdown code block so that I could verify them?
@NahidAfzali hi can you provider the step for reproduce ?
if I not get your reply I will close this issue after one week.
Current Behavior
Hi, I'm using the body transformer plugin to change my soap API. I have tried lots of ways for changing the template, but every time I've got errors and even my API didn't invoke. Please help how can I change the template to achieve a successful response. Thank you in advance, here is my data:
{ "uri": "/VIPC/InquiryNationalCode2", "name": "InquiryNationalCode2", "plugins": { "body-transformer": { "request": { "template": "<?xml version=\"1.0\"?>\n<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n\n <ns0:InquiryNationalCode xmlns:ns0=\"http://tempuri.org\">\n \n {{_escape_xml(RequestNumber)}}</ns0:RequestNumber>\n {{_escape_xml(sessionId)}}</ns0:sessionId>\n {{_escape_xml(mac)}}</ns0:mac>\n {{_escape_xml(Ip)}}</ns0:Ip>\n {{_escape_xml(NationalId)}}</ns0:NationalId>\n {{_escape_xml(BirthDate)}}</ns0:BirthDate>\n </ns0:inquiryNationalCodeRequest>\n </ns0:InquiryNationalCode>\n </soap-env:Body>\n</soap-env:Envelope>"
},
"response": {
"template": "{% if Envelope.Body.Fault == nil then %}\n{\"Result\":\"{{Envelope.Body.InquiryNationalCodeResponse.InquiryNationalCodeResult.Result}}\"}\n{% else %}{\"message\":{_escape_json(Envelope.Body.Fault.faultstring[1])},\n\"code\":\"{{Envelope.Body.Fault.faultcode}}\"\n{% if Envelope.Body.Fault.faultactor ~= nil then %},\n \"actor\":\"{{Envelope.Body.Fault.faultactor}}\"\n {% end %}}{% end %}"
}
},
"proxy-rewrite": {
"uri": "/service.asmx?op=InquiryNationalCode",
"use_real_request_uri_unsafe": false
},
"response-rewrite": {
"body_base64": false,
"headers": {
"set": {
"Content-Type": "application/json"
}
}
}
},
"upstream_id": "455796621209240261",
"labels": {
"API_VERSION": "V1"
},
"status": 1
}
Expected Behavior
Success response
Error Logs
2023/04/15 15:30:03 [warn] 50#50: 17998910 [lua] plugin.lua:929: encrypt_conf(): failed to get schema for plugin: body-transformer, client: 10.0.84.150, server: , request: "PUT /apisix/admin/routes/test_2 HTTP/1.1", host: "10.0.84.150:9180" 2023/04/15 15:30:03 [warn] 50#50: 17998910 [lua] plugin.lua:929: encrypt_conf(): failed to get schema for plugin: proxy-rewrite, client: 10.0.84.150, server: , request: "PUT /apisix/admin/routes/test_2 HTTP/1.1", host: "10.0.84.150:9180" 10.0.84.150 - - [15/Apr/2023:15:30:03 +0000] 10.0.84.150:9180 "PUT /apisix/admin/routes/test2 HTTP/1.1" 201 1665 0.016 "-" "curl/7.29.0" - - - "http://10.0.84.150:9180" 2023/04/15 15:30:09 [error] 50#50: *17999135 [lua] body-transformer.lua:145: transform(): response template rendering: [string "context=... or {}..."]:5: attempt to index global 'Envelope' (a nil value) while sending to client, client: 10.0.204.72, server: , request: "POST /VIPC/InquiryNationalCode2 HTTP/1.1", upstream: "http://10.0.85.53:80/service.asmx?op=InquiryNationalCode", host: "10.0.84.150:9080" 2023/04/15 15:30:09 [error] 50#50: 17999135 [lua] body-transformer.lua:202: phasefunc(): failed to transform response body: <?xml version="1.0" encoding="utf-8"?>soap:Client Unable to handle request without a valid action parameter. Please supply a valid soap action. </soap:Fault></soap:Body></soap:Envelope> while sending to client, client: 10.0.204.72, server: , request: "POST /VIPC/InquiryNationalCode2 HTTP/1.1", upstream: "http://10.0.85.53:80/service.asmx?op=InquiryNationalCode", host: "10.0.84.150:9080"
10.0.204.72 - - [15/Apr/2023:15:30:09 +0000] 10.0.84.150:9080 "POST /VIPC/InquiryNationalCode2 HTTP/1.1" 500 5 0.011 "-" "PostmanRuntime/7.31.0" 10.0.85.53:80 500 0.011 "http://10.0.84.150:9080/service.asmx?op=InquiryNationalCode"
2023/04/15 15:35:34 [warn] 50#50: 18012295 [lua] plugin.lua:929: encrypt_conf(): failed to get schema for plugin: body-transformer, client: 10.0.84.150, server: , request: "PUT /apisix/admin/routes/test_2 HTTP/1.1", host: "10.0.84.150:9180"
2023/04/15 15:35:34 [warn] 50#50: 18012295 [lua] plugin.lua:929: encrypt_conf(): failed to get schema for plugin: proxy-rewrite, client: 10.0.84.150, server: , request: "PUT /apisix/admin/routes/test_2 HTTP/1.1", host: "10.0.84.150:9180"
10.0.84.150 - - [15/Apr/2023:15:35:34 +0000] 10.0.84.150:9180 "PUT /apisix/admin/routes/test_2 HTTP/1.1" 201 1665 0.017 "-" "curl/7.29.0" - - - "http://10.0.84.150:9180"
2023/04/15 15:35:45 [error] 50#50: 18012722 [lua] body-transformer.lua:145: transform(): response template rendering: [string "context=... or {}..."]:5: attempt to index global 'Envelope' (a nil value) while sending to client, client: 10.0.204.72, server: _, request: "POST /VIPC/InquiryNationalCode2 HTTP/1.1", upstream: "http://10.0.85.53:80/service.asmx?op=InquiryNationalCode", host: "10.0.84.150:9080"
2023/04/15 15:35:45 [error] 50#50: *18012722 [lua] body-transformer.lua:202: phasefunc(): failed to transform response body: <?xml version="1.0" encoding="utf-8"?>soap:Client Unable to handle request without a valid action parameter. Please supply a valid soap action. </soap:Fault></soap:Body></soap:Envelope> while sending to client, client: 10.0.204.72, server: , request: "POST /VIPC/InquiryNationalCode2 HTTP/1.1", upstream: "http://10.0.85.53:80/service.asmx?op=InquiryNationalCode", host: "10.0.84.150:9080"
10.0.204.72 - - [15/Apr/2023:15:35:45 +0000] 10.0.84.150:9080 "POST /VIPC/InquiryNationalCode2 HTTP/1.1" 500 5 0.005 "-" "PostmanRuntime/7.31.0" 10.0.85.53:80 500 0.005 "http://10.0.84.150:9080/service.asmx?op=InquiryNationalCode"
Steps to Reproduce
Run APISIX via Docker image
Environment
apisix version
):uname -a
):openresty -V
ornginx -V
):curl http://127.0.0.1:9090/v1/server_info
):luarocks --version
):