You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "sanjivkamate (via GitHub)" <gi...@apache.org> on 2023/07/26 14:23:28 UTC
[GitHub] [apisix] sanjivkamate opened a new issue, #9911: bug: Encoded response in body_transformer plugin, not able to identify if I am getting a valid response
sanjivkamate opened a new issue, #9911:
URL: https://github.com/apache/apisix/issues/9911
### Current Behavior
Hi, I am currently integrating SOAP webservice using body-transformer plugin in APASIX 3.4 but getting an encoded response in error.log
**Route definition**
curl http://127.0.0.1:9180/apisix/admin/routes/test_ws -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"methods": ["POST"],
"uri": "/calculator.asmx",
"plugins": {
"proxy-rewrite": {
"host": "dneonline.com",
"use_real_request_uri_unsafe": false,
"headers": {
"set": {
"Accept-Encoding": "gzip, deflate, br",
"Content-Type": "text/xml",
"SOAPAction":"http://tempuri.org/Add"
}
}
},
"response-rewrite": {
"body_base64": false,
"headers": {
"set": {
"Content-Type": "application/json"
}
}
},
"body-transformer": {
"request": {
"template": "<?xml version=\"1.0\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\"><soapenv:Header/><soapenv:Body><tem:Add><tem:intA>{{_escape_xml(add1)}}</tem:intA><tem:intB>{{_escape_xml(add2)}}</tem:intB></tem:Add></soapenv:Body></soapenv:Envelope>"
},
"response": {
"template": "{% if Envelope.Body.Fault == nil then %}{\"currency\":\"{{Envelope.Body.AddResponse.AddResult}}\"}{% else %}{\"message\":{*_escape_json(Envelope.Body.Fault.faultstring[1])*},\"code\":\"{{Envelope.Body.Fault.faultcode}}\"{% if Envelope.Body.Fault.faultactor ~= nil then %}, \"actor\":\"{{Envelope.Body.Fault.faultactor}}\"{% end %}}{% end %}"
}
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"www.dneonline.com:80": 1
}
}
}'
Please note the SOAP web service is hosted over the internet and working fine.

### Expected Behavior
Success response in the form of JSON
### Error Logs
2023/07/26 10:11:31 [error] 1334951#1334951: *523074 [lua] body-transformer.lua:153: transform(): response template rendering: [string "context=... or {}..."]:5: attempt to index global 'Envelope' (a nil value) while sending to client, client: 49.36.105.172, server: _, request: "POST /calculator.asmx HTTP/1.1", upstream: "http://50.62.168.5:80/calculator.asmx", host: "103.13.113.61:9080"
2023/07/26 10:11:31 [error] 1334951#1334951: *523074 [lua] body-transformer.lua:214: phase_func(): failed to transform response body: ????????t5л???C(???9???/??*????????????]?ﹷ?gT??1?/66V?2?:????`0Ǚ???`0
s?3"?Q8,???=??B?Z
݁?q???0??ִ
b/?ӿ??d?z?e?Z
??̓?d?9Nj??^????g?????`~Z?f
.<?=s????9(?0?L ?L6?G:0PF3 while sending to client, client: 49.36.105.172, server: _, request: "POST /calculator.asmx HTTP/1.1", upstream: "http://50.62.168.5:80/calculator.asmx", host: "103.13.113.61:9080"
### Steps to Reproduce
1. Run APISIX using RPM on Linux server
2. Create route via CMD
### Environment
- APISIX version - 3.4.1
- Operating system - Linux finexta.in 5.4.17-2136.312.3.4.el8uek.x86_64 #2 SMP Wed Oct 19 17:42:16 PDT 2022 x86_64 x86_64 x86_64 GNU/Linux
- OpenResty / Nginx version - openresty/1.21.4.1
- etcd version, if relevant - "etcd_version":"3.5.0","version":"3.4.1","id":"b9812f90-578b-46eb-b6a1-99ea13bcbc6b","hostname":"finexta.in","boot_time":1690378304}
- APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues - luarocks: command not found (Not sure if this is relevant)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Revolyssup commented on issue #9911: bug: Encoded response in body_transformer plugin, not able to identify if I am getting a valid response
Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup commented on issue #9911:
URL: https://github.com/apache/apisix/issues/9911#issuecomment-1652965797
> > @sanjivkamate Will you try adding the field `"input_format":"xml"` explicitly in conf? Also while getting response over APISIX, when you dont use body transform plugin, do you get normal xml response?
>
> @Revolyssup Tried with "input_format":"xml" like below, same response in the error log as before "response": { "input_format":"xml", "template": "{% if Envelope.Body.Fault == nil then %}{"currency":"{{Envelope.Body.AddResponse.AddResult}}"}{% else %}{"message":{__escape_json(Envelope.Body.Fault.faultstring[1])_},"code":"{{Envelope.Body.Fault.faultcode}}"{% if Envelope.Body.Fault.faultactor ~= nil then %}, "actor":"{{Envelope.Body.Fault.faultactor}}"{% end %}}{% end %}" }
>
> **Also while getting response over APISIX, when you dont use body transform plugin, do you get normal xml response?** @Revolyssup I am not sure how to try this as the reason I am using body transform plugin is to read my XML response which is SOAP based.
>
> **Also when you just use the request template and not response template, do you get proper xml response?** @Revolyssup No error is being logged in error.log, getting 200 response but response is empty.
>
> Thank you for the response.
The default priority of response-rewrite> body-transform. Please remove the response-rewrite plugin and try again
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] sanjivkamate closed issue #9911: bug: Encoded response in body_transformer plugin, not able to identify if I am getting a valid response
Posted by "sanjivkamate (via GitHub)" <gi...@apache.org>.
sanjivkamate closed issue #9911: bug: Encoded response in body_transformer plugin, not able to identify if I am getting a valid response
URL: https://github.com/apache/apisix/issues/9911
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] sanjivkamate commented on issue #9911: bug: Encoded response in body_transformer plugin, not able to identify if I am getting a valid response
Posted by "sanjivkamate (via GitHub)" <gi...@apache.org>.
sanjivkamate commented on issue #9911:
URL: https://github.com/apache/apisix/issues/9911#issuecomment-1652971159
> > > @sanjivkamate Will you try adding the field `"input_format":"xml"` explicitly in conf? Also while getting response over APISIX, when you dont use body transform plugin, do you get normal xml response?
> >
> >
> > @Revolyssup Tried with "input_format":"xml" like below, same response in the error log as before "response": { "input_format":"xml", "template": "{% if Envelope.Body.Fault == nil then %}{"currency":"{{Envelope.Body.AddResponse.AddResult}}"}{% else %}{"message":{__escape_json(Envelope.Body.Fault.faultstring[1])_},"code":"{{Envelope.Body.Fault.faultcode}}"{% if Envelope.Body.Fault.faultactor ~= nil then %}, "actor":"{{Envelope.Body.Fault.faultactor}}"{% end %}}{% end %}" }
> > **Also while getting response over APISIX, when you dont use body transform plugin, do you get normal xml response?** @Revolyssup I am not sure how to try this as the reason I am using body transform plugin is to read my XML response which is SOAP based.
> > **Also when you just use the request template and not response template, do you get proper xml response?** @Revolyssup No error is being logged in error.log, getting 200 response but response is empty.
> > Thank you for the response.
>
> The default priority of response-rewrite> body-transform where you set the content-type to json. Please remove the response-rewrite plugin and try again
@Revolyssup Please ignore, I changed Accept-Encoding from "Accept-Encoding": "gzip, deflate, br" to"Accept-Encoding": "identity" and it is working fine now. I am getting valid response.
Thank you for spending time in checking and responding.
**The final working config is**
curl http://127.0.0.1:9180/apisix/admin/routes/test_ws -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"methods": ["POST"],
"uri": "/calculator.asmx",
"plugins": {
"proxy-rewrite": {
"host": "dneonline.com",
"use_real_request_uri_unsafe": false,
"headers": {
"set": {
"Accept-Encoding": "identity",
"Content-Type": "text/xml",
"SOAPAction":"http://tempuri.org/Add"
}
}
},
"response-rewrite": {
"body_base64": false,
"headers": {
"set": {
"Content-Type": "application/json"
}
}
},
"body-transformer": {
"request": {
"template": "<?xml version=\"1.0\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\"><soapenv:Header/><soapenv:Body><tem:Add><tem:intA>{{_escape_xml(add1)}}</tem:intA><tem:intB>{{_escape_xml(add2)}}</tem:intB></tem:Add></soapenv:Body></soapenv:Envelope>"
},
"response": {
"input_format":"xml",
"template": "{% if Envelope.Body.Fault == nil then %}{\"currency\":\"{{Envelope.Body.AddResponse.AddResult}}\"}{% else %}{\"message\":{*_escape_json(Envelope.Body.Fault.faultstring[1])*},\"code\":\"{{Envelope.Body.Fault.faultcode}}\"{% if Envelope.Body.Fault.faultactor ~= nil then %}, \"actor\":\"{{Envelope.Body.Fault.faultactor}}\"{% end %}}{% end %}"
}
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"www.dneonline.com:80": 1
}
}
}'
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] sanjivkamate commented on issue #9911: bug: Encoded response in body_transformer plugin, not able to identify if I am getting a valid response
Posted by "sanjivkamate (via GitHub)" <gi...@apache.org>.
sanjivkamate commented on issue #9911:
URL: https://github.com/apache/apisix/issues/9911#issuecomment-1652949907
> @sanjivkamate Will you try adding the field `"input_format":"xml"` explicitly in conf? Also while getting response over APISIX, when you dont use body transform plugin, do you get normal xml response?
@Revolyssup Tried with "input_format":"xml" like below, same response in the error log as before
"response": {
"input_format":"xml",
"template": "{% if Envelope.Body.Fault == nil then %}{\"currency\":\"{{Envelope.Body.AddResponse.AddResult}}\"}{% else %}{\"message\":{*_escape_json(Envelope.Body.Fault.faultstring[1])*},\"code\":\"{{Envelope.Body.Fault.faultcode}}\"{% if Envelope.Body.Fault.faultactor ~= nil then %}, \"actor\":\"{{Envelope.Body.Fault.faultactor}}\"{% end %}}{% end %}"
}
**Also while getting response over APISIX, when you dont use body transform plugin, do you get normal xml response?**
@Revolyssup I am not sure how to try this as the reason I am using body transform plugin is to read my XML response which is SOAP based.
**Also when you just use the request template and not response template, do you get proper xml response?**
@Revolyssup No error is being logged in error.log, getting 200 response but response is empty.
Thank you for the response.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Revolyssup commented on issue #9911: bug: Encoded response in body_transformer plugin, not able to identify if I am getting a valid response
Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup commented on issue #9911:
URL: https://github.com/apache/apisix/issues/9911#issuecomment-1652920695
@sanjivkamate Also when you just use the request template and not response template, do you get proper xml response?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Revolyssup commented on issue #9911: bug: Encoded response in body_transformer plugin, not able to identify if I am getting a valid response
Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup commented on issue #9911:
URL: https://github.com/apache/apisix/issues/9911#issuecomment-1652914590
@sanjivkamate Will you try adding the field `"input_format":"xml"` explicitly in conf?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org