-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Current Behavior
路由配置:
req_template=$(cat <<EOF | awk '{gsub(/"/,"\\\"");};1' | awk '{$1=$1};1' | tr -d '\r\n'
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.springcloudalibaba.demo.ufmk.com/">
<soapenv:Header/>
<soapenv:Body>
<web:calc>
<arg0>
<a>111</a>
<b>222</b>
<operator>add</operator>
</arg0>
</web:calc>
</soapenv:Body>
</soapenv:Envelope>
EOF
)
rsp_template=$(cat <<EOF | awk '{gsub(/"/,"\\\"");};1' | awk '{$1=$1};1' | tr -d '\r\n'
{%
local yaml = require("lyaml")
local body = yaml.load(_body)
local bodyJson = _escape_json(Envelope.Body.calcResponse)
local bodyJsonReturn = _escape_json(Envelope.Body.calcResponse)
ngx.log(ngx.INFO, 'INFO-111111111111111111111111111')
ngx.log(ngx.ERR, 'ERR-22222222222222222222222222222:',bodyJsonReturn)
%}
{{_ctx.var.status}}\r\n
{*body*}\r\n
{*_escape_json(Envelope.Body.calcResponse._attr.ns2)*}\r\n
{*_escape_json(Envelope.Body.calcResponse)*}\r\n
{*bodyJson*}\r\n
{*bodyJsonReturn*}\r\n
{*Envelope.Body.calcResponse*}\r\n
{*Envelope.Body.calcResponse._attr.ns2*}\r\n
Envelope.Body.calcResponse.return
EOF
)
curl http://127.0.0.1:9180/apisix/admin/routes/calcResponse -H 'X-API-KEY: b848941cd4e1003f2f961a7786ecf75f' -X PUT -d '
{
"uri": "/calcResponse",
"name": "calcResponse",
"desc": "路由描述",
"plugins": {
"body-transformer": {
"request": {
"template": "'"$req_template"'"
},
"response": {
"template": "'"$rsp_template"'"
}
},
"proxy-rewrite": {
"headers": {
"set": {
"Content-Type": "text/xml"
}
},
"uri": "/ws/helloWorldDemo",
"use_real_request_uri_unsafe": false
},
"response-rewrite": {
"body_base64": false,
"headers": {
"set": {
"Content-Type": "application/json"
}
}
}
},
"upstream": {
"nodes": [
{
"host": "192.168.137.1",
"port": 18080,
"weight": 1
}
],
"type": "roundrobin",
"hash_on": "vars",
"scheme": "http",
"pass_host": "pass",
"keepalive_pool": {
"idle_timeout": 200,
"requests": 1000,
"size": 500
}
},
"status": 1
}
'
WebService返回值:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:calcResponse xmlns:ns2="http://webservice.springcloudalibaba.demo.ufmk.com/">
<return>
<a>111</a>
<b>222</b>
<operator>add</operator>
</return>
</ns2:calcResponse>
</soap:Body>
</soap:Envelope>
{_escape_json(Envelope.Body.calcResponse._attr.ns2)} 能获取到:http://webservice.springcloudalibaba.demo.ufmk.com/
{_escape_json(Envelope.Body.calcResponse.return)} 获取不到值,异常了
Expected Behavior
预期:
{_escape_json(Envelope.Body.calcResponse._attr.ns2)} 能获取到:http://webservice.springcloudalibaba.demo.ufmk.com/
{_escape_json(Envelope.Body.calcResponse.return)} 能获取到:{"b":"222","a":"111","operator":"add"}
{_escape_json(Envelope.Body.calcResponse.return.a)} 能获取到:111
Error Logs
异常日志:
2024/12/13 16:39:37 [error] 48#48: *16250 [lua] body-transformer.lua:154: transform(): response template compile: /usr/local/apisix//deps/share/lua/5.1/resty/template.lua:389: [string "context=... or {}..."]:18: '' expected near 'return' while sending to client, client: 192.168.137.1, server: _, request: "POST /calcResponse HTTP/1.1", upstream: "http://192.168.137.1:18080/ws/helloWorldDemo", host: "192.168.137.100:9088"
2024/12/13 16:39:37 [error] 48#48: *16250 [lua] body-transformer.lua:228: phase_func(): failed to transform response body: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">soap:Body<ns2:calcResponse xmlns:ns2="http://webservice.springcloudalibaba.demo.ufmk.com/">111222add</ns2:calcResponse></soap:Body></soap:Envelope> while sending to client, client: 192.168.137.1, server: _, request: "POST /calcResponse HTTP/1.1", upstream: "http://192.168.137.1:18080/ws/helloWorldDemo", host: "192.168.137.100:9088"
192.168.137.1 - "<soapenv:Envelope xmlns:soapenv=\x22http://schemas.xmlsoap.org/soap/envelope/\x22 xmlns:web=\x22http://webservice.springcloudalibaba.demo.ufmk.com/\x22>soapenv:Header/soapenv:Bodyweb:calc111222add</web:calc></soapenv:Body></soapenv:Envelope>" -"response_body"- - [2024-12-13T16:39:37+08:00] 192.168.137.100:9088 "POST /calcResponse HTTP/1.1" 200 5 0.002 "-" "PostmanRuntime-ApipostRuntime/1.1.0" 192.168.137.1:18080 200 0.001 "http://192.168.137.100:9088/ws/helloWorldDemo"
Steps to Reproduce
docker images: apache/apisix:3.11.0-debian
Environment
-
APISIX version (run
apisix version):apache/apisix:3.11.0-debian -
Operating system (run
uname -a):Linux master 6.5.0-44-generic doc: add qq group. #44-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 7 15:10:09 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux -
OpenResty / Nginx version (run
openresty -Vornginx -V):
nginx version: openresty/1.25.3.2
built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
built with OpenSSL 3.2.0 23 Nov 2023
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -DAPISIX_RUNTIME_VER=1.2.1 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl3/include' --add-module=../ngx_devel_kit-0.3.3 --add-module=../echo-nginx-module-0.63 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.33 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.09 --add-module=../srcache-nginx-module-0.33 --add-module=../ngx_lua-0.10.26 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.37 --add-module=../array-var-nginx-module-0.06 --add-module=../memc-nginx-module-0.20 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.9 --add-module=../ngx_stream_lua-0.0.14 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -Wl,-rpath,/usr/local/openresty/wasmtime-c-api/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl3/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl3/lib' --add-module=/tmp/tmp.0vt0zLPiwq/openresty-1.25.3.2/../mod_dubbo-1.0.2 --add-module=/tmp/tmp.0vt0zLPiwq/openresty-1.25.3.2/../ngx_multi_upstream_module-1.2.0 --add-module=/tmp/tmp.0vt0zLPiwq/openresty-1.25.3.2/../apisix-nginx-module-1.16.1 --add-module=/tmp/tmp.0vt0zLPiwq/openresty-1.25.3.2/../apisix-nginx-module-1.16.1/src/stream --add-module=/tmp/tmp.0vt0zLPiwq/openresty-1.25.3.2/../apisix-nginx-module-1.16.1/src/meta --add-module=/tmp/tmp.0vt0zLPiwq/openresty-1.25.3.2/../wasm-nginx-module-0.7.0 --add-module=/tmp/tmp.0vt0zLPiwq/openresty-1.25.3.2/../lua-var-nginx-module-v0.5.3 --add-module=/tmp/tmp.0vt0zLPiwq/openresty-1.25.3.2/../lua-resty-events-0.2.0 --with-poll_module --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --with-http_v3_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-stream --without-pcre2 --with-http_ssl_module -
etcd version, if relevant (run
curl http://127.0.0.1:9090/v1/server_info): -
APISIX Dashboard version, if relevant:
-
Plugin runner version, for issues related to plugin runners:
-
LuaRocks version, for installation issues (run
luarocks --version):
Metadata
Metadata
Assignees
Labels
Type
Projects
Status