Welcome! Log In Create A New Profile

Advanced

Передача HTTPS POST-запросов на бекэнд

July 23, 2010 11:28AM
Здравствуйте!

Проблема с передачей POST-запроса, принятого по HTTPS, на проксируемый Tomcat.

Схема работы сервера:
впереди стоит nginx, прослушивающий 80 и 443 порты.
Позади стоит Tomcat, слушающий 8081 порт. Томкат настроен только на HTTP.

Nginx раздает статику, а запросы на динамику передает на Tomcat.

Есть урлы HTTPS-постбеков, на который приходят данные от стороннего сервера.
nginx принимает HTTPS, расшифровывает его, и передает данные уже по HTTP на Томкат.
Томкат передает ответ на nginx по HTTP, тот их передает клиенту по HTTPS.

Проблема в том, что после обработки nginx-ом на томкате я получаю какую-то абракадабру в запросе.

В чем может быть дело?

Ниже привожу конфиг nginx, часть кода обработчика томката и логи томката:

nginx.conf:

********************************
server {
listen 443;
server_name localhost;

ssl on;
ssl_certificate /usr/local/nginx/company/company.ca.crt;
ssl_certificate_key /usr/local/nginx/company/company.ca.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:!LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;

location / {
root html;
#Apache/Tomcat we have at 8081 port
proxy_pass http://127.0.0.1:8081/;
proxy_redirect off;
proxy_set_header Connection close;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass_header Content-Type;
proxy_pass_header Content-Disposition;
proxy_pass_header Content-Length;
proxy_read_timeout 300;
proxy_temp_path /var/tmp/nginx;
client_body_temp_path /var/tmp/nginx/proxy_temp;
expires 5s;
access_log /var/log/nginx/https.log main;
}

**********************************

Controller.java:

public ModelAndView postback(HttpServletRequest request, HttpServletResponse response) throws Exception {
log.info("[Controller.postback]");

//
// Show request body for DEBUG purposes
//
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}

log.info("Request body ++++++++++++++++++++++++");
log.info(sb.toString());
log.info("/Request body ++++++++++++++++++++++++");

String action = request.getParameter("action");
String customerNumber = request.getParameter("customerNumber");
String orderNumber = request.getParameter("orderNumber");
String orderSumAmount = request.getParameter("orderSumAmount");

log.info("action="+action);
log.info("customerNumber="+customerNumber);
log.info("orderNumber="+orderNumber);
log.info("orderSumAmount="+orderSumAmount);

.........
}

**********************************

Tomcat log entries:
**********************************
Request body ++++++++++++++++++++++++
invoiceId=12345678&orderSumBankPaycash=1001&paymentType=1&orderNumber=7777&shopId=12103&orderIsPaid=0&shopSumBankPaycash=1001&orderSumAmount=150.00&shopSumAmount=150.00&scid=2827&action=Check&shopSumCurrencyPaycash=643&paymentPayerCode=11111111111111&requestDateTime=2010-07-23T16%3A30%3A06Z&orderSumCurrencyPaycash=643&customerNumber=iryndin&orderCreatedDatetime=2010-07-23T16%3A30%3A06Z&md5=215be52842c0c4d7a93e3a7196ca7209
/Request body ++++++++++++++++++++++++
action=null
customerNumber=null
orderNumber=null
orderSumAmount=null
**********************************

Как видим, в логе выше, если параметры получаются через request.getParameter(), то они получаются равными нулю. При этом в теле POST-запроса все эти параметры присутствуют.

А вот ниже более любопытные логи:

Еще одна запись в логе (прием постбеков от сторонней системы):
***********************************************
Request body ++++++++++++++++++++++++
-----------------------------64243434740Content-Disposition: form-data; name="requestDatetime";Content-Type: text/plain;2010-07-23T18:14:49+04:00-----------------------------64243434740Content-Disposition: form-data; name="md5";Content-Type: text/plain;91E1495CDBE9D007C061D94AEC7CCBBB-----------------------------64243434740Content-Disposition: form-data; name="shopId";Content-Type: text/plain;12103-----------------------------64243434740Content-Disposition: form-data; name="invoiceId";Content-Type: text/plain;1099520089681-----------------------------64243434740Content-Disposition: form-data; name="customerNumber";Content-Type: text/plain;qaqa-----------------------------64243434740Content-Disposition: form-data; name="orderCreatedDatetime";Content-Type: text/plain;2010-07-23T18:14:36+04:00-----------------------------64243434740Content-Disposition: form-data; name="orderSumAmount";Content-Type: text/plain;156.21-----------------------------64243434740Content-Disposition: form-data; name="orderSumCurrencyPaycash";Content-Type: text/plain;10643-----------------------------64243434740Content-Disposition: form-data; name="orderSumBankPaycash";Content-Type: text/plain;1003-----------------------------64243434740Content-Disposition: form-data; name="shopSumAmount";Content-Type: text/plain;148.40-----------------------------64243434740Content-Disposition: form-data; name="shopSumCurrencyPaycash";Content-Type: text/plain;10643-----------------------------64243434740Content-Disposition: form-data; name="shopSumBankPaycash";
/Request body ++++++++++++++++++++++++
***********************************************

Тут добавились, видимо, раскодированные данные формы....
При этом, также как и в предыдущем логе, параметры, получаемые при помощи request.getParameter также равны null.

Как организовать работающую передачу HTTPS POST-запросов на Tomcat ?

Спасибо!!!
Subject Author Posted

Передача HTTPS POST-запросов на бекэнд

iryndin July 23, 2010 11:28AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 320
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready