简体   繁体   English

Apache Tomcat 升级到 8.5.51 导致 400 错误

[英]Apache Tomcat upgrade to 8.5.51 causes 400 errors

We're having an issue when upgrading Tomcat from 8.5.50 to 8.5.51.将 Tomcat 从 8.5.50 升级到 8.5.51 时遇到问题。 Since moving to this version, requests sent to the http port are failing with a 400 error code(bad request).由于移动到此版本,发送到 http 端口的请求失败并显示 400 错误代码(错误请求)。 The server.xml is configured to redirect the http port to the https port. server.xml 配置为将 http 端口重定向到 https 端口。 This has worked for years and did not start failing until the upgrade.这已经工作了多年,直到升级才开始失败。 Below is the connector config and the java class used to send a test transaction to the server.下面是用于向服务器发送测试事务的连接器配置和 java 类。

I've searched the change log and the only change I can see that might cause this is the Bug fix for bug 63966 – Charset of TLS message is hard coded to ISO-8859-1.我搜索了更改日志,我能看到的唯一更改可能是错误 63966 的错误修复——TLS 消息的字符集被硬编码为 ISO-8859-1。 This bug fix was introduced into 8.5.51.此错误修复已引入 8.5.51。 The reason I believe this might be the reason is when we would send this request to tomcat 8.5.50 the reply Content-Type would look like this:我认为这可能是原因,当我们将此请求发送到 tomcat 8.5.50 时,回复 Content-Type 将如下所示:

Content-Type: text/plain;charset=ISO-8859-1内容类型:text/plain;charset=ISO-8859-1

With tomcat 8.5.51, I get this: Content-Type: text/html;charset=utf-8使用 tomcat 8.5.51,我得到这个: Content-Type: text/html;charset=utf-8

Any ideas why I'm getting the 400 error when upgrading to 8.5.51 and beyond ?有什么想法为什么我在升级到 8.5.51 及更高版本时会收到 400 错误?

Connector config:连接器配置:

<Connector port="5555" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="7777"
                />
 
       <Connector port="7777" protocol="HTTP/1.1" SSLEnabled="true"
           scheme="https" secure="true"             ciphers="TLS_DHE_DSS_WITH_AES_128_GCM_SHA256,TLS_DHE_DSS_WITH_AES_256_GCM_SHA384,TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
           clientAuth="false" sslProtocol="TLS" sslEnabledProtocols="TLSv1.2"
           keyAlias="myKey"
           keystore="NONE"
           keystorePass="password"
           keystoreType="PKCS11"
           keystoreProvider="myprovider"
           enableLookups="false"
           server="server"
           "/>

Java class used to send the test transaction:用于发送测试事务的 Java 类:

package com.testing;
 
import java.io.*;
import java.net.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
 
public class RunTestTran{
 
    public  RunTestTran() {
    }
 
    public static void main(String [] args){
        RunTestTran recordProcessorTest = new RunTestTran();
        recordProcessorTest.runTran("localhost", 5555, "/requestProcessor/rp");
    }
 
        private void runTran(String ip, int port, String appName){
                Socket socket = null;
                PrintWriter out = null;
                BufferedReader in = null;
                String dataToSend = "";
 
                //Create socket connection
                try {
                        socket = new Socket(ip, port);
                        out = new PrintWriter(socket.getOutputStream(), true);
                        in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                } catch  (Exception e) {
                        System.out.println("Exception:" + e.toString() );
                        System.exit(1);
                }
 
                DateFormat dateFormat = new SimpleDateFormat("MMddHHmmsss");
                //get current date time with Date() to create a 11 digit tran id
                Date date = new Date();
                String tranId = dateFormat.format(date);
                String PRIMER_TRAN = "     V " + tranId + "9999999999000000000JANE       DOE         100 Redwood Shores Pkwy             Redwood City       CA94065000000000000000  PRIMER TRAN";
 
 
                try{
                        dataToSend = URLEncoder.encode("inputRecord", "UTF-8") + "=" + URLEncoder.encode(PRIMER_TRAN, "UTF-8");
 
                }catch(Exception e){
                        System.out.println("Exception caught!" + e.toString());
                }
                 // send message
                StringBuffer sb = new StringBuffer();
                sb.append("POST /" + appName + "/wrp HTTP/1.1\r\n");
                // Try connection close-- see if it does close
                sb.append("Connection: close\r\n");
                sb.append("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword\n");
                sb.append("Accept-Language: en-us\n");
                sb.append("Accept-Encoding: gzip, deflate\n");
                sb.append("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\n");
                // Authorization
                sb.append("Authorization: Basic DK34a3RvbWVydGVzddkK7WCx\n");
                sb.append("Host: " + ip + ":" + port + "\n");
                sb.append("Content-Length: " + dataToSend.length() + "\r\n");
                sb.append("Content-Type: application/x-www-form-urlencoded\r\n");
                sb.append("\r\n");
                sb.append(dataToSend);
                 // Send data
                String text = sb.toString();
                out.println(text);
 
                System.out.println("\nText sent " + text.length() + " bytes:");
                System.out.println(text + "\n\n");
 
                try{
                        String gotBack1 = in.readLine();
                        System.out.println("Text received:" + gotBack1 );
                        String gotBack = null;
                        while (  (gotBack = in.readLine()) != null){
                                System.out.println("Text received:" + gotBack );
                                if ( (gotBack.indexOf("TQ!") != -1)){
                                        break;
                                }
                        }
                } catch (Exception e){
                        System.out.println("Read failed! " + e.toString());
                        System.exit(1);
                }
        }
 
 
 
 
}

Fixed it.修复。 Apparently the 8.5.51 tomcat did not like terminating the headers with \\n.显然 8.5.51 tomcat 不喜欢用 \\n 终止标头。 I changed all the header line terminators to \\r\\n and I'm now getting 200 success codes.我将所有标题行终止符更改为 \\r\\n,现在我得到了 200 个成功代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tomcat从7.0.59升级到8.5.51后JSP编译异常 - JSP compilation exception after Tomcat upgrade to 8.5.51 from 7.0.59 TomCat 8.5.51 增加线程堆栈大小 - TomCat 8.5.51 Increase thread stack size Apache tomcat安装导致错误 - Apache tomcat installation causes error 通过 JT400 的 JDBC 在本地 Apache Tomcat 8 安装上工作,但在服务器上运行的 Apache Tomcat 8 上失败 - JDBC via JT400 works on local Apache Tomcat 8 install but fails on Apache Tomcat 8 running on server 从 Tomcat 8.0.39 升级到 8.0.41 导致“扫描失败”错误 - Upgrade from Tomcat 8.0.39 to 8.0.41 results in 'failed to scan' errors 通过apache tomcat服务器启动中的电子邮件发送错误和异常 - sending errors and exceptions through emails in apache tomcat server start Apache + Tomcat - Apache + Tomcat 如何在Linux上升级Tomcat - How to upgrade Tomcat on linux Apache Tomcat重新启动导致使用Java清除会话,并且会话在JSP页面上持续存在 - Apache Tomcat restart causes session clear in Java and session persist on a JSP page 通过Apache和Tomcat 500的WebSocket错误:java.lang.UnsupportedOperationException:该协议不支持HTTP升级 - WebSocket through Apache and Tomcat 500 Error : java.lang.UnsupportedOperationException: HTTP upgrade is not supported by this protocol
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM