Tomcat 7.0.43 "INFO: Error parsing HTTP request header"
Asked Answered
R

10

57

I use Tomcat 7.0.43 with a websocket application. My app works fine in Tomcat 7.0.42 but with 43 I get the following output when I try to access my server on websockets:

Sep 16, 2013 3:08:34 AM org.apache.coyote.http11.AbstractHttp11Processor process
INFO: Error parsing HTTP request header
 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

My browser console shows the following:

WebSocket connection to 'ws://www.testapp.com/socket/notification/848df2e62fcf93e1b3?X-Atmosphere-tracking-i…Date=0&Content-Type=application/json;%20charset=UTF-8&X-atmo-protocol=true' failed: Unrecognized frame opcode: 5 

Here is the access log for that request:

"GET /socket/notification/848df2e62fcf93e1b3?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.0.2-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=0&Content-Type=application/json;%20charset=UTF-8&X-atmo-protocol=true HTTP/1.1"

What has changed in Tomcat 7.0.43? What do I have to change?

Railroader answered 16/9, 2013 at 1:15 Comment(8)
Can you show the HTTP headers you are sending?Tubing
@SotiriosDelimanolis see my access log. Does this help you?Railroader
maybe this answer can help you: #12583838Escapade
@fatman Why should Tomcat 7.0.43 not support the websocket I use with Tomcat 7.0.42? It does not make any sense?Railroader
you are getting failed: Unrecognized frame opcode: 5 so obviously the problem is in that area. I'm not familiar with the protocol but just thought it might give you a pointer (maybe you set a version header?).Escapade
@fatman but why does this change from version 42 to 43?Railroader
@confile did you manage to find any solution? I am facing same issueBillings
@SorryBoss no not yet. If you find a solution please post it. I know that in Tomcat 7.0.43 the specification for web sockets have changed.Railroader
S
37

If you have this listener:

    <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/>

on your server.xml, remove it and try. You can not use a keystore if you are using the APR connector

Seclusive answered 22/11, 2013 at 12:14 Comment(0)
F
25

Check, if you are not accidentally requesting HTTPS protocol instead of HTTP.

I have overlooked that I was requesting https://localhost:... instead of http://localhost:... and it resulted to this weird message..

Frodeen answered 4/11, 2019 at 15:50 Comment(2)
Great. Thanks, this was my problem.Tutto
My problem too; especially when I looked at localhost_access_log and everything after the IP address and date was hex data!Cauldron
C
22

If there are too many cookies cached, it breaks the server (the size of a request header is too big!). Clearing the cookies can fix this issue as well.

Covarrubias answered 14/5, 2015 at 19:3 Comment(3)
i had the problem with httpclient, i used method.addHeader instead of method.setHeaderMaimaia
i just have one header attached and that is content type and still i am getting the same error . can u advice ?Violence
@Violence then probably your issue is not from the size of request headerCovarrubias
T
22

For me, the problem was passing in a larger than normally expected HTTP header. I resolved it by setting maxHttpHeaderSize="1048576" attribute on the Connector node in server.xml.

Tontine answered 16/10, 2015 at 21:12 Comment(0)
R
12

I had a similar issue, I was sending a POST request (using RESTClient plugin for Firefox) with data in the request body and was receiving the same message.

In my case this happened because I was trying to use HTTPS protocol in a local tomcat instance where HTTPS was not configured.

Rode answered 18/6, 2015 at 9:1 Comment(2)
yup, same thing in my case it was typo someone tried localhost:8080Stevens
Even in my case this is the issue, one of the developer hitting from postman with https.Whitford
A
5

My problem occurs when I try to open https. I don't use SSL.

It's Tomcat bug.

Today 12/02/2017 newest official version from Debian repositories is Tomcat 8.0.14

Solution is to download from official site and install newest package of Tomcat 8, 8.5, 9 or upgrade to newest version(8.5.x) from jessie-backports

Debian 8

Add to /etc/apt/sources.list

deb http://ftp.debian.org/debian jessie-backports main

Then update and install Tomcat from jessie-backports

sudo apt-get update && sudo apt-get -t jessie-backports install tomcat8
Alethiaaletta answered 12/2, 2017 at 17:42 Comment(1)
bug report for debian and tomcat 8.0.14 environment: bugs.debian.org/cgi-bin/bugreport.cgi?bug=851304Northwestwards
A
3

I tried all of the above, nothing worked for me. Then I changed tomcat port numbers both HTTP/1.1 and Tomcat admin port and it got solved.

I see other solutions above worked for the people but it is worth to try this one if any of the above doesn't work.

Thanks everyone!

Accolade answered 12/2, 2016 at 10:23 Comment(0)
S
2

In our case it turned out that the error happened because we have a custom filter in our application which does HttpServletResponse sendRedirect() to other url.

For some reason, the redirection is not closing the keep-alive status of the connection, hence the timeout exception.

We checked with Tomcat Docs and when we disabled the maxKeepAliveRequests by setting it's value to 1 and the error stopped showing up.

For now we do not have the actual solution to the error.

Savoirfaire answered 29/7, 2016 at 8:57 Comment(0)
B
2

I had this issue when working on a Java Project in Debian 10 with Tomcat as the application server.

The issue was that the application already had https defined as it's default protocol while I was using http to call the application in the browser. So when I try running the application I get this error in my log file:

org.apache.coyote.http11.AbstractHttp11Processor process
INFO: Error parsing HTTP request header
 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

I however tried using the https protocol in the browser but it didn't connect throwing the error:

Here's how I solved it:

You need a certificate to setup the https protocol for the application. I first had to create a keystore file for the application, more like a self-signed certificate for the https protocol:

sudo keytool -genkey -keyalg RSA -alias tomcat -keystore /usr/share/tomcat.keystore

Note: You need to have Java installed on the server to be able to do this. Java can be installed using sudo apt install default-jdk.

Next, I added a https Tomcat server connector for the application in the Tomcat server configuration file (/opt/tomcat/conf/server.xml):

sudo nano /opt/tomcat/conf/server.xml

Add the following to the configuration of the application. Notice that the keystore file location and password are specified. Also a port for the https protocol is defined, which is different from the port for the http protocol:

<Connector protocol="org.apache.coyote.http11.Http11Protocol"
           port="8443" maxThreads="200" scheme="https"
           secure="true" SSLEnabled="true"
           keystoreFile="/usr/share/tomcat.keystore"
           keystorePass="my-password"
           clientAuth="false" sslProtocol="TLS"
           URIEncoding="UTF-8"
           compression="force"
           compressableMimeType="text/html,text/xml,text/plain,text/javascript,text/css"/>

So the full server configuration for the application looked liked this in the Tomcat server configuration file (/opt/tomcat/conf/server.xml):

<Service name="my-application">
  <Connector protocol="org.apache.coyote.http11.Http11Protocol"
             port="8443" maxThreads="200" scheme="https"
             secure="true" SSLEnabled="true"
             keystoreFile="/usr/share/tomcat.keystore"
             keystorePass="my-password"
             clientAuth="false" sslProtocol="TLS"
             URIEncoding="UTF-8"
             compression="force"
             compressableMimeType="text/html,text/xml,text/plain,text/javascript,text/css"/>

  <Connector port="8009" protocol="HTTP/1.1"
             connectionTimeout="20000"
             redirectPort="8443" />

  <Engine name="my-application" defaultHost="localhost">
     <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>
    </Realm>

    <Host name="localhost"  appBase="webapps"
          unpackWARs="true" autoDeploy="true">

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
             prefix="localhost_access_log" suffix=".txt"
             pattern="%h %l %u %t &quot;%r&quot; %s %b" />

    </Host>
  </Engine>
</Service>

This time when I tried accessing the application from the browser using:

https://my-server-ip-address:https-port

In my case it was:

https:35.123.45.6:8443

it worked fine. Although, I had to accept a warning which added a security exception for the website since the certificate used is a self-signed one.

That's all.

I hope this helps

Bioplasm answered 6/10, 2020 at 10:46 Comment(0)
R
1

If you don't want to upgrade your tomcat, Add this line in your catalina.properties

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}

It works for me http://www.zhoulujun.cn/zhoulujun/html/java/tomcat/2018_0508_8109.html

Retrenchment answered 8/5, 2018 at 2:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.