【发布时间】:2019-05-05 15:07:09
【问题描述】:
我正在尝试重写 SOAP POST 请求 body 和 header,以便 Apache 或 Nginx可以将其代理到驻留在另一台服务器上的应用程序。
请求是这样组成的,这个特别是指“UploadDocument_v4”功能:
POST / HTTP/1.1
Accept-Encoding: gzip, deflate
Content-Type: application/soap+xml;charset=UTF-8;action="http://server.workstepController.Process/UploadDocument_v4"
Host: 192.168.1.2
Content-Length: 245508
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Connection: close
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:com="http://server.workstepController.Process/">
<soap:Header/>
<soap:Body>
<com:UploadDocument_v4>
<!--Optional:-->
<com:workstepId></com:workstepId>
<!--Optional:-->
<com:customizationId></com:customizationId>
<!--Optional:-->
<com:document>OMISSIS</com:document>
<!--Optional:-->
<com:fileName>contract.pdf</com:fileName>
<com:timeToLive>100</com:timeToLive>
<!--Optional:-->
<com:transactionInformation><![CDATA[
<!--Further information for this transaction.-->
<TransactionInformation>
<!--The client id.-->
<ClientId>myClientId</ClientId>
<!--The transaction id.-->
<TransactionId>1234567890</TransactionId>
<!--Specifies if the currentWorkstepInformation should be returned by the method.-->
<ReturnWorkstepInfo>1</ReturnWorkstepInfo>
<!--The product name.-->
<ProductName />
<!--The product version.-->
<ProductVersion />
<!--The product release date in format YYYY-MM-DD.-->
<ProductReleaseDate />
<!--The email of the user.-->
<UserId />
<!--The ip address of the user.-->
<IpAddress />
</TransactionInformation>
]]></com:transactionInformation>
</com:UploadDocument_v4>
</soap:Body>
</soap:Envelope>
我需要做的是重写这个请求,以便它调用相同的函数,但使用 _v2 版本。因此,所有对 _v4 的引用都应在 body AND header 中替换为 _v2。
这有可能吗?到目前为止,我一直在使用 Nginx 和 Apache,但是如果可能的话,我还没有找到相关的模块。
感谢您提供的任何见解。
更新: 正如 Ivan 在 cmets 中建议的那样,我尝试安装 Openresty,并且通过使用基本配置,我能够确定它正在工作。但是,我似乎无法弄清楚如何替换正文和标题。 nginx.conf 文件如下:
worker_processes 1;
error_log logs/error.log
events{
worker_connections 1024;
}
http{
server{
listen 8080;
location / {
--default_type text/html;
rewrite_by_lua_block{
--This is not being substituted
ngx.req.set_header("Content-Type", "[...]/UploadDocument_v2")
};
a = ngx.req.read_body();
a = string.gsub(a,"_v4","_v2");
return 302 http://192.168.1.3:1234;
}
}
}
【问题讨论】:
-
我认为这可以通过openresty 或ngx_http_lua_module 完成。另请参阅this 问题。
-
您好伊万,感谢您的回复。这也适用于请求标头吗?谢谢
-
据我所知,对于请求标头的操作,有 ngx.req.get_headers 和 ngx.req.set_header 方法。
-
您好 Ivan,我已尝试配置这些模块,并且它们似乎已正确安装。但是,我似乎无法执行字符串的简单替换。另外,不幸的是,标头指令不会覆盖任何内容。我会用配置更新问题。
标签: apache http nginx soap lua