You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Klemens Muthmann <kl...@tu-dresden.de> on 2016/09/05 12:11:25 UTC

How to write a correct HTTP request to Tomcat 8.5.4 instance?

Hi,

I currently need to implement an HTTP data transmission from an Arduino
with WiFi module to a PC running a Tomcat 8.5.4 instance. The Tomcat is
running under Ubuntu 16.04.

The problem is that, since there are no HTTP libraries on Arduino, I
need to write the correct HTTP request myself and I got stuck. It would
be great if someone on the list with a deeper understanding of the HTTP
protocol would be willing to support me.
The transmitted (possibly erroneous ) request looks like:

========================================
GET /push?VIN=testrun HTTP/1.1
User-Agent: Freematics
Connection: keep-alive
Host:

========================================
The server runs under a local access point IP (10.42.0.1) and receives
that request correctly but throws me an EOFException from the following
code fragment:

     nRead = channel.read(socketBufferHandler.getReadBuffer());
    if (nRead == -1) {
        throw new EOFException();
    }

So it seems to me that an end of file is reached before it is expected.
Can somebody provide me with hints on how to solve that issue and
formulate a correct HTTP request to my Tomcat instance?

The following is th log trace I receive from the server:
========================================
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
o.a.coyote.http11.Http11InputBuffer      : Received [GET
/push?VIN=testrun HTTP/1.1
User-Agent: Freematics
Connection: keep-alive
Host:

]
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
o.a.c.authenticator.AuthenticatorBase    : Security checking request GET
/push
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
org.apache.catalina.realm.RealmBase      :   No applicable constraints
defined
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
o.a.c.authenticator.AuthenticatorBase    :  Not subject to any constraint
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
org.apache.tomcat.util.http.Parameters   : Set encoding to UTF-8
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
org.apache.tomcat.util.http.Parameters   : Decoding query null UTF-8
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
org.apache.tomcat.util.http.Parameters   : Start processing with input
[VIN=testrun]
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
o.s.b.w.f.OrderedRequestContextFilter    : Bound request context to
thread: org.apache.catalina.connector.RequestFacade@75c83bc4
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name
'dispatcherServlet' processing GET request for [/push]
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for
path /push
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method
[public void de.cyface.obd2.controller.Obd2Controller.push()]
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of
singleton bean 'obd2Controller'
2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
o.s.web.servlet.DispatcherServlet        : Last-Modified value for
[/push] is: -1
push
2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to
DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter
completed request handling
2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
o.s.web.servlet.DispatcherServlet        : Successfully completed request
2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
o.s.b.w.f.OrderedRequestContextFilter    : Cleared thread-bound request
context: org.apache.catalina.connector.RequestFacade@75c83bc4
2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
o.apache.coyote.http11.Http11Processor   : Socket:
[org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2940dec1:org.apache.tomcat.util.net.NioChannel@34a92297:java.nio.channels.SocketChannel[connected
local=/10.42.0.1:8080 remote=/10.42.0.72:46701]], Status in:
[OPEN_READ], State out: [OPEN]
2016-09-05 13:32:55.280 DEBUG 13143 --- [nio-8080-exec-2]
o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header

java.io.EOFException: null
    at
org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1222)
~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at
org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1163)
~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at
org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:742)
~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at
org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:404)
~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:994)
~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
[tomcat-embed-core-8.5.4.jar:8.5.4]
    at
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
[tomcat-embed-core-8.5.4.jar:8.5.4]
    at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
[tomcat-embed-core-8.5.4.jar:8.5.4]
    at
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
[tomcat-embed-core-8.5.4.jar:8.5.4]
    at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[na:1.8.0_91]
    at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[na:1.8.0_91]
    at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
[tomcat-embed-core-8.5.4.jar:8.5.4]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
=======================================

Thanks and regards
    Klemens


Re: How to write a correct HTTP request to Tomcat 8.5.4 instance?

Posted by Mark Thomas <ma...@apache.org>.
On 05/09/2016 13:11, Klemens Muthmann wrote:
> Hi,
> 
> I currently need to implement an HTTP data transmission from an Arduino
> with WiFi module to a PC running a Tomcat 8.5.4 instance. The Tomcat is
> running under Ubuntu 16.04.
> 
> The problem is that, since there are no HTTP libraries on Arduino, I
> need to write the correct HTTP request myself and I got stuck. It would
> be great if someone on the list with a deeper understanding of the HTTP
> protocol would be willing to support me.

That looks normal to me.

You use keep-alive.
You send a request.
The connection stays open.
The client closes the connection.
The server sees an EOF.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to write a correct HTTP request to Tomcat 8.5.4 instance?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Terrence,

On 9/6/16 10:00 AM, Terence M. Bandoian wrote:
> On 9/5/2016 8:09 AM, Klemens Muthmann wrote:
>> Am 05.09.2016 um 14:49 schrieb Tim Watts:
>>> On Mon, 2016-09-05 at 14:11 +0200, Klemens Muthmann wrote:
>>>> Hi,
>>>> 
>>>> I currently need to implement an HTTP data transmission from
>>>> an Arduino with WiFi module to a PC running a Tomcat 8.5.4
>>>> instance. The Tomcat is running under Ubuntu 16.04.
>>>> 
>>>> The problem is that, since there are no HTTP libraries on
>>>> Arduino, I need to write the correct HTTP request myself and
>>>> I got stuck. It would be great if someone on the list with a
>>>> deeper understanding of the HTTP protocol would be willing to
>>>> support me. The transmitted (possibly erroneous ) request
>>>> looks like:
>>>> 
>>>> ======================================== GET
>>>> /push?VIN=testrun HTTP/1.1 User-Agent: Freematics Connection:
>>>> keep-alive Host:
>>>> 
>>>> ======================================== The server runs
>>>> under a local access point IP (10.42.0.1) and receives that
>>>> request correctly but throws me an EOFException from the
>>>> following code fragment:
>>>> 
>>>> nRead = channel.read(socketBufferHandler.getReadBuffer()); if
>>>> (nRead == -1) { throw new EOFException(); }
>>>> 
>>>> So it seems to me that an end of file is reached before it is
>>>> expected. Can somebody provide me with hints on how to solve
>>>> that issue and formulate a correct HTTP request to my Tomcat
>>>> instance?
>>>> 
>>>> The following is th log trace I receive from the server: 
>>>> ======================================== 2016-09-05
>>>> 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1] 
>>>> o.a.coyote.http11.Http11InputBuffer      : Received [GET 
>>>> /push?VIN=testrun HTTP/1.1 User-Agent: Freematics Connection:
>>>> keep-alive Host:
>>>> 
>>>> ]
>>> Until a real expert comes along with a better answer let me
>>> just toss this out:  Are the lines in the HTTP request that the
>>> Arduino submits terminated with \r\n (and not just \n)?
>>> Because it looks like the entire request may have been read
>>> when reading the request line.  Then when it goes to read the
>>> headers it gets an EOF.  Not 100% sure of this but it's
>>> possible.
>>> 
>>> 
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1] 
>>>> o.a.c.authenticator.AuthenticatorBase    : Security checking
>>>> request GET /push 2016-09-05 13:32:50.238 DEBUG 13143 ---
>>>> [nio-8080-exec-1] org.apache.catalina.realm.RealmBase      :
>>>> No applicable constraints defined 2016-09-05 13:32:50.238
>>>> DEBUG 13143 --- [nio-8080-exec-1] 
>>>> o.a.c.authenticator.AuthenticatorBase    :  Not subject to
>>>> any constraint 2016-09-05 13:32:50.238 DEBUG 13143 ---
>>>> [nio-8080-exec-1] org.apache.tomcat.util.http.Parameters   :
>>>> Set encoding to UTF-8 2016-09-05 13:32:50.238 DEBUG 13143 ---
>>>> [nio-8080-exec-1] org.apache.tomcat.util.http.Parameters   :
>>>> Decoding query null UTF-8 2016-09-05 13:32:50.238 DEBUG 13143
>>>> --- [nio-8080-exec-1] org.apache.tomcat.util.http.Parameters
>>>> : Start processing with input [VIN=testrun] 2016-09-05
>>>> 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1] 
>>>> o.s.b.w.f.OrderedRequestContextFilter    : Bound request
>>>> context to thread:
>>>> org.apache.catalina.connector.RequestFacade@75c83bc4 
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1] 
>>>> o.s.web.servlet.DispatcherServlet        : DispatcherServlet
>>>> with name 'dispatcherServlet' processing GET request for
>>>> [/push] 2016-09-05 13:32:50.238 DEBUG 13143 ---
>>>> [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping :
>>>> Looking up handler method for path /push 2016-09-05
>>>> 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1] 
>>>> s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler
>>>> method [public void
>>>> de.cyface.obd2.controller.Obd2Controller.push()] 2016-09-05
>>>> 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1] 
>>>> o.s.b.f.s.DefaultListableBeanFactory     : Returning cached
>>>> instance of singleton bean 'obd2Controller' 2016-09-05
>>>> 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1] 
>>>> o.s.web.servlet.DispatcherServlet        : Last-Modified
>>>> value for [/push] is: -1 push 2016-09-05 13:32:50.239 DEBUG
>>>> 13143 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet
>>>> : Null ModelAndView returned to DispatcherServlet with name
>>>> 'dispatcherServlet': assuming HandlerAdapter completed
>>>> request handling 2016-09-05 13:32:50.239 DEBUG 13143 ---
>>>> [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        :
>>>> Successfully completed request 2016-09-05 13:32:50.239 DEBUG
>>>> 13143 --- [nio-8080-exec-1] 
>>>> o.s.b.w.f.OrderedRequestContextFilter    : Cleared
>>>> thread-bound request context:
>>>> org.apache.catalina.connector.RequestFacade@75c83bc4 
>>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1] 
>>>> o.apache.coyote.http11.Http11Processor   : Socket: 
>>>> [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2940dec1:o
rg.apache.tomcat.util.net.NioChannel@34a92297:java.nio.channels.SocketCh
annel[connected
>>>>
>>>>
>>>> 
local=/10.42.0.1:8080 remote=/10.42.0.72:46701]], Status in:
>>>> [OPEN_READ], State out: [OPEN] 2016-09-05 13:32:55.280 DEBUG
>>>> 13143 --- [nio-8080-exec-2] 
>>>> o.apache.coyote.http11.Http11Processor   : Error parsing
>>>> HTTP request header
>>>> 
>>>> java.io.EOFException: null at 
>>>> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuf
fer(NioEndpoint.java:1222)
>>>>
>>>>
>>>> 
~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>> at 
>>>> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEnd
point.java:1163)
>>>>
>>>>
>>>> 
~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>> at 
>>>> org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.j
ava:742)
>>>>
>>>>
>>>> 
~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>> at 
>>>> org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11I
nputBuffer.java:404)
>>>>
>>>>
>>>> 
~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>> at 
>>>> org.apache.coyote.http11.Http11Processor.service(Http11Processor.ja
va:994)
>>>>
>>>>
>>>> 
~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>> at 
>>>> org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorL
ight.java:66)
>>>>
>>>>
>>>> 
[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>> at 
>>>> org.apache.coyote.AbstractProtocol$ConnectionHandler.process(Abstra
ctProtocol.java:785)
>>>>
>>>>
>>>> 
[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>> at 
>>>> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEnd
point.java:1425)
>>>>
>>>>
>>>> 
[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>> at 
>>>> org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorB
ase.java:49)
>>>>
>>>>
>>>> 
[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>> at 
>>>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecuto
r.java:1142)
>>>>
>>>>
>>>> 
[na:1.8.0_91]
>>>> at 
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecut
or.java:617)
>>>>
>>>>
>>>> 
[na:1.8.0_91]
>>>> at 
>>>> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(Task
Thread.java:61)
>>>>
>>>>
>>>> 
[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>> at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91] 
>>>> =======================================
>>>> 
>>>> Thanks and regards Klemens
>>>> 
>>> 
>>> --------------------------------------------------------------------
- -
>>>
>>> 
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>> 
>> Hi,
>> 
>> Thanks for the answer.
>> 
>> The request is formatted on the Arduino like: "GET
>> /push?VIN=testrun HTTP/1.1\r\nUser-Agent:
>> Freematics\r\nConnection: keep-alive\r\nHost: \r\n"
>> 
>> So yes, all lines are terminated with \r\n
>> 
>> Regards Klemens
> 
> 
> Is an additional CRLF expected?  From RFC 2616:
> 
> generic-message = start-line *(message-header CRLF) CRLF [
> message-body ] start-line      = Request-Line | Status-Line

Yup, a valid HTTP/1.1 request must end with CR LF CR LF.

Klemens, try adding *another * CR LF pair to your request to see if
that improves things.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJXzv+NAAoJEBzwKT+lPKRYsrwP/3fRwVuhgQRBw6uMiEKBYs6c
nTbpNfUkSI6jeVlyLfeCdHCMOg5zcxPq3yeIn6ulpNYhsWaM/nURSq4DuHu7HXSt
Rt8Z7yQArbtKfdQUZsjSp3ZPF3FuUBL9d0/G+y+xgKkCsEvaPH3ib3Z1aUAROnmH
ZVB//hqHPcpvgwgyxMAxl8mA29jsZ3D/cLT6N50nRY1y9v09tRTXMBO+Mkw8cxL7
WWkucd+NzkCF4pf5zY64UEMoNuodexa7Qi96dZLcArH4GuSosFZtxaVBnOdqZ2EF
llWVuSdnW5QxaPtI4vEkr96Z9zSfnptYAlnRBK35uprKdivUo3HitWHInGKX42kA
PmLm+hhVABAHPYZ2XCdevP+VkBlIsfv7mNeNW17jY+FFvM+iVCPxgNIh3z6EXHI0
6hGCCz6SxtHJ6dSruWxzC2NwDxVA1OGpDICeoTir5RylRk/h3ZJpWp/w3+aeHQnN
zn1ENZaFITjRmNwNgbLYZk1VCTALerkf3egR3Y8L6WxRjjzOKsm3H1tIBRF9SGmr
/OHJ3s8cXjhlr7+ojlWb4yBad79vR1CQEe5+uynP5nOLbogBHVIfBW8soVUD2IrX
SP8QZRTnqV1l5IXXtwukzmr8WCeP1pRSU6aszjYY+KCGOIH1ZOH22OwFR1qzVxlV
5kby5r2TSZWg2HIxDjBt
=ylEK
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to write a correct HTTP request to Tomcat 8.5.4 instance?

Posted by "Terence M. Bandoian" <te...@tmbsw.com>.
On 9/5/2016 8:09 AM, Klemens Muthmann wrote:
> Am 05.09.2016 um 14:49 schrieb Tim Watts:
>> On Mon, 2016-09-05 at 14:11 +0200, Klemens Muthmann wrote:
>>> Hi,
>>>
>>> I currently need to implement an HTTP data transmission from an Arduino
>>> with WiFi module to a PC running a Tomcat 8.5.4 instance. The Tomcat is
>>> running under Ubuntu 16.04.
>>>
>>> The problem is that, since there are no HTTP libraries on Arduino, I
>>> need to write the correct HTTP request myself and I got stuck. It would
>>> be great if someone on the list with a deeper understanding of the HTTP
>>> protocol would be willing to support me.
>>> The transmitted (possibly erroneous ) request looks like:
>>>
>>> ========================================
>>> GET /push?VIN=testrun HTTP/1.1
>>> User-Agent: Freematics
>>> Connection: keep-alive
>>> Host:
>>>
>>> ========================================
>>> The server runs under a local access point IP (10.42.0.1) and receives
>>> that request correctly but throws me an EOFException from the following
>>> code fragment:
>>>
>>>       nRead = channel.read(socketBufferHandler.getReadBuffer());
>>>      if (nRead == -1) {
>>>          throw new EOFException();
>>>      }
>>>
>>> So it seems to me that an end of file is reached before it is expected.
>>> Can somebody provide me with hints on how to solve that issue and
>>> formulate a correct HTTP request to my Tomcat instance?
>>>
>>> The following is th log trace I receive from the server:
>>> ========================================
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.a.coyote.http11.Http11InputBuffer      : Received [GET
>>> /push?VIN=testrun HTTP/1.1
>>> User-Agent: Freematics
>>> Connection: keep-alive
>>> Host:
>>>
>>> ]
>> Until a real expert comes along with a better answer let me just toss
>> this out:  Are the lines in the HTTP request that the Arduino submits
>> terminated with \r\n (and not just \n)?  Because it looks like the
>> entire request may have been read when reading the request line.  Then
>> when it goes to read the headers it gets an EOF.  Not 100% sure of this
>> but it's possible.
>>
>>
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.a.c.authenticator.AuthenticatorBase    : Security checking request GET
>>> /push
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> org.apache.catalina.realm.RealmBase      :   No applicable constraints
>>> defined
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.a.c.authenticator.AuthenticatorBase    :  Not subject to any constraint
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> org.apache.tomcat.util.http.Parameters   : Set encoding to UTF-8
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> org.apache.tomcat.util.http.Parameters   : Decoding query null UTF-8
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> org.apache.tomcat.util.http.Parameters   : Start processing with input
>>> [VIN=testrun]
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.b.w.f.OrderedRequestContextFilter    : Bound request context to
>>> thread: org.apache.catalina.connector.RequestFacade@75c83bc4
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name
>>> 'dispatcherServlet' processing GET request for [/push]
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for
>>> path /push
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method
>>> [public void de.cyface.obd2.controller.Obd2Controller.push()]
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of
>>> singleton bean 'obd2Controller'
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.web.servlet.DispatcherServlet        : Last-Modified value for
>>> [/push] is: -1
>>> push
>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to
>>> DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter
>>> completed request handling
>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.web.servlet.DispatcherServlet        : Successfully completed request
>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.b.w.f.OrderedRequestContextFilter    : Cleared thread-bound request
>>> context: org.apache.catalina.connector.RequestFacade@75c83bc4
>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.apache.coyote.http11.Http11Processor   : Socket:
>>> [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2940dec1:org.apache.tomcat.util.net.NioChannel@34a92297:java.nio.channels.SocketChannel[connected
>>> local=/10.42.0.1:8080 remote=/10.42.0.72:46701]], Status in:
>>> [OPEN_READ], State out: [OPEN]
>>> 2016-09-05 13:32:55.280 DEBUG 13143 --- [nio-8080-exec-2]
>>> o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
>>>
>>> java.io.EOFException: null
>>>      at
>>> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1222)
>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1163)
>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:742)
>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:404)
>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:994)
>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>>> [na:1.8.0_91]
>>>      at
>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>>> [na:1.8.0_91]
>>>      at
>>> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
>>> =======================================
>>>
>>> Thanks and regards
>>>      Klemens
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> Hi,
>
> Thanks for the answer.
>
> The request is formatted on the Arduino like:
> "GET /push?VIN=testrun HTTP/1.1\r\nUser-Agent: Freematics\r\nConnection:
> keep-alive\r\nHost: \r\n"
>
> So yes, all lines are terminated with \r\n
>
> Regards
>      Klemens


Is an additional CRLF expected?  From RFC 2616:

         generic-message = start-line
                           *(message-header CRLF)
                           CRLF
                           [ message-body ]
         start-line      = Request-Line | Status-Line

-Terence Bandoian


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to write a correct HTTP request to Tomcat 8.5.4 instance?

Posted by Klemens Muthmann <kl...@tu-dresden.de>.

Am 05.09.2016 um 16:16 schrieb André Warnier (tomcat):
> On 05.09.2016 15:09, Klemens Muthmann wrote:
>> Am 05.09.2016 um 14:49 schrieb Tim Watts:
>>> On Mon, 2016-09-05 at 14:11 +0200, Klemens Muthmann wrote:
>>>> Hi,
>>>>
>>>> I currently need to implement an HTTP data transmission from an
>>>> Arduino
>>>> with WiFi module to a PC running a Tomcat 8.5.4 instance. The
>>>> Tomcat is
>>>> running under Ubuntu 16.04.
>>>>
>>>> The problem is that, since there are no HTTP libraries on Arduino, I
>>>> need to write the correct HTTP request myself and I got stuck. It
>>>> would
>>>> be great if someone on the list with a deeper understanding of the
>>>> HTTP
>>>> protocol would be willing to support me.
>>>> The transmitted (possibly erroneous ) request looks like:
>>>>
>>>> ========================================
>>>> GET /push?VIN=testrun HTTP/1.1
>>>> User-Agent: Freematics
>>>> Connection: keep-alive
>>>> Host:
>>>>
>>>> ========================================
>>>> The server runs under a local access point IP (10.42.0.1) and receives
>>>> that request correctly but throws me an EOFException from the
>>>> following
>>>> code fragment:
>>>>
>>>>       nRead = channel.read(socketBufferHandler.getReadBuffer());
>>>>      if (nRead == -1) {
>>>>          throw new EOFException();
>>>>      }
>>>>
>>>> So it seems to me that an end of file is reached before it is
>>>> expected.
>>>> Can somebody provide me with hints on how to solve that issue and
>>>> formulate a correct HTTP request to my Tomcat instance?
>>>>
>>>> The following is th log trace I receive from the server:
>>>> ========================================
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> o.a.coyote.http11.Http11InputBuffer      : Received [GET
>>>> /push?VIN=testrun HTTP/1.1
>>>> User-Agent: Freematics
>>>> Connection: keep-alive
>>>> Host:
>>>>
>>>> ]
>>> Until a real expert comes along with a better answer let me just toss
>>> this out:  Are the lines in the HTTP request that the Arduino submits
>>> terminated with \r\n (and not just \n)?  Because it looks like the
>>> entire request may have been read when reading the request line.  Then
>>> when it goes to read the headers it gets an EOF.  Not 100% sure of this
>>> but it's possible.
>>>
>>>
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> o.a.c.authenticator.AuthenticatorBase    : Security checking
>>>> request GET
>>>> /push
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> org.apache.catalina.realm.RealmBase      :   No applicable constraints
>>>> defined
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> o.a.c.authenticator.AuthenticatorBase    :  Not subject to any
>>>> constraint
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> org.apache.tomcat.util.http.Parameters   : Set encoding to UTF-8
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> org.apache.tomcat.util.http.Parameters   : Decoding query null UTF-8
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> org.apache.tomcat.util.http.Parameters   : Start processing with input
>>>> [VIN=testrun]
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> o.s.b.w.f.OrderedRequestContextFilter    : Bound request context to
>>>> thread: org.apache.catalina.connector.RequestFacade@75c83bc4
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name
>>>> 'dispatcherServlet' processing GET request for [/push]
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler
>>>> method for
>>>> path /push
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method
>>>> [public void de.cyface.obd2.controller.Obd2Controller.push()]
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> o.s.b.f.s.DefaultListableBeanFactory     : Returning cached
>>>> instance of
>>>> singleton bean 'obd2Controller'
>>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>>> o.s.web.servlet.DispatcherServlet        : Last-Modified value for
>>>> [/push] is: -1
>>>> push
>>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>>> o.s.web.servlet.DispatcherServlet        : Null ModelAndView
>>>> returned to
>>>> DispatcherServlet with name 'dispatcherServlet': assuming
>>>> HandlerAdapter
>>>> completed request handling
>>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>>> o.s.web.servlet.DispatcherServlet        : Successfully completed
>>>> request
>>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>>> o.s.b.w.f.OrderedRequestContextFilter    : Cleared thread-bound
>>>> request
>>>> context: org.apache.catalina.connector.RequestFacade@75c83bc4
>>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>>> o.apache.coyote.http11.Http11Processor   : Socket:
>>>> [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2940dec1:org.apache.tomcat.util.net.NioChannel@34a92297:java.nio.channels.SocketChannel[connected
>>>>
>>>> local=/10.42.0.1:8080 remote=/10.42.0.72:46701]], Status in:
>>>> [OPEN_READ], State out: [OPEN]
>>>> 2016-09-05 13:32:55.280 DEBUG 13143 --- [nio-8080-exec-2]
>>>> o.apache.coyote.http11.Http11Processor   : Error parsing HTTP
>>>> request header
>>>>
>>>> java.io.EOFException: null
>>>>      at
>>>> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1222)
>>>>
>>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>>      at
>>>> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1163)
>>>>
>>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>>      at
>>>> org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:742)
>>>>
>>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>>      at
>>>> org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:404)
>>>>
>>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>>      at
>>>> org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:994)
>>>>
>>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>>      at
>>>> org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
>>>>
>>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>>      at
>>>> org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
>>>>
>>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>>      at
>>>> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
>>>>
>>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>>      at
>>>> org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
>>>>
>>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>>      at
>>>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>>>>
>>>> [na:1.8.0_91]
>>>>      at
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>>>>
>>>> [na:1.8.0_91]
>>>>      at
>>>> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
>>>>
>>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>>      at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
>>>> =======================================
>>>>
>>>> Thanks and regards
>>>>      Klemens
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>> Hi,
>>
>> Thanks for the answer.
>>
>> The request is formatted on the Arduino like:
>> "GET /push?VIN=testrun HTTP/1.1\r\nUser-Agent: Freematics\r\nConnection:
>> keep-alive\r\nHost: \r\n"
>>
>> So yes, all lines are terminated with \r\n
>>
> and are you sure that the software that you use on the Arduino really
> replaces "\r\n" by a real CR/LF pair before sending this to the server ?
>
> (If you set up an Access log on Tomcat, you can check this).
> (aside : there is nothing "magical" in the string "\r\n" at the level
> of the HTTP protocol. For HTTP, these are just 4 normal printable
> characters. The possible "\r\n" replacement by a CR/LF pair is a
> function of what you use *on the agent* to interpret that string
> before printing it.)
>
> Also, it seems to me that since you are specifying "HTTP/1.1" as the
> protocol in our request, the "Host:" line should include a host name. 
> If your Tomcat only has a default Host entry, then use whatever you
> feel like (Tomcat will default to that default Host anyway).
> If your Tomcat has several <Host> entries, use the appropriate hostname.
> Like :
> Host: mytomcat.mycompany.com<CR/LF>
>
> You /may/ also want to add a header :
> Content-length: 0<CR/LF>
>
> although in principle that should not be necessary, since a GET
> request normally has no request body.
>
> Maybe try the following, as a confirmation :
> - get an appropriate add-on to a normal browser, which shows the trace
> of the conversation with the server. Examples :
>   - for IE : Fiddler2
>   - for Mozilla : HttpFox, LiveHttpHeaders or similar
> - then activate it,
>
> then issue the same request from the browser to your Tomcat, and look
> at the HTTP conversation in the add-on window.
> To send the same request as above, type this in the browser's URL bar :
> http://mytomcat.mycompany.com//push?VIN=testrun
> (the default request is GET)
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
Hi,

Thanks for the answer. Those tools are quite helpful. I usually use
netcat and wireshark, but that is pretty much the same.

I add a value for "Host:". The software on the Arduino is created by a
C-Compiler and I am quite sure that "\r\n" is replaced by a real CR/LF.

What I found was that changing the value "Connection: keep-alive" to
"Connection: close" silenced the error. So at the moment I assume that I
somehow am not terminating the "keep-alive" connection correctly. If
anyone got anything on this it would be very helpful.

Regards
    Klemens


Re: How to write a correct HTTP request to Tomcat 8.5.4 instance?

Posted by "André Warnier (tomcat)" <aw...@ice-sa.com>.
On 05.09.2016 15:09, Klemens Muthmann wrote:
> Am 05.09.2016 um 14:49 schrieb Tim Watts:
>> On Mon, 2016-09-05 at 14:11 +0200, Klemens Muthmann wrote:
>>> Hi,
>>>
>>> I currently need to implement an HTTP data transmission from an Arduino
>>> with WiFi module to a PC running a Tomcat 8.5.4 instance. The Tomcat is
>>> running under Ubuntu 16.04.
>>>
>>> The problem is that, since there are no HTTP libraries on Arduino, I
>>> need to write the correct HTTP request myself and I got stuck. It would
>>> be great if someone on the list with a deeper understanding of the HTTP
>>> protocol would be willing to support me.
>>> The transmitted (possibly erroneous ) request looks like:
>>>
>>> ========================================
>>> GET /push?VIN=testrun HTTP/1.1
>>> User-Agent: Freematics
>>> Connection: keep-alive
>>> Host:
>>>
>>> ========================================
>>> The server runs under a local access point IP (10.42.0.1) and receives
>>> that request correctly but throws me an EOFException from the following
>>> code fragment:
>>>
>>>       nRead = channel.read(socketBufferHandler.getReadBuffer());
>>>      if (nRead == -1) {
>>>          throw new EOFException();
>>>      }
>>>
>>> So it seems to me that an end of file is reached before it is expected.
>>> Can somebody provide me with hints on how to solve that issue and
>>> formulate a correct HTTP request to my Tomcat instance?
>>>
>>> The following is th log trace I receive from the server:
>>> ========================================
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.a.coyote.http11.Http11InputBuffer      : Received [GET
>>> /push?VIN=testrun HTTP/1.1
>>> User-Agent: Freematics
>>> Connection: keep-alive
>>> Host:
>>>
>>> ]
>> Until a real expert comes along with a better answer let me just toss
>> this out:  Are the lines in the HTTP request that the Arduino submits
>> terminated with \r\n (and not just \n)?  Because it looks like the
>> entire request may have been read when reading the request line.  Then
>> when it goes to read the headers it gets an EOF.  Not 100% sure of this
>> but it's possible.
>>
>>
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.a.c.authenticator.AuthenticatorBase    : Security checking request GET
>>> /push
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> org.apache.catalina.realm.RealmBase      :   No applicable constraints
>>> defined
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.a.c.authenticator.AuthenticatorBase    :  Not subject to any constraint
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> org.apache.tomcat.util.http.Parameters   : Set encoding to UTF-8
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> org.apache.tomcat.util.http.Parameters   : Decoding query null UTF-8
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> org.apache.tomcat.util.http.Parameters   : Start processing with input
>>> [VIN=testrun]
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.b.w.f.OrderedRequestContextFilter    : Bound request context to
>>> thread: org.apache.catalina.connector.RequestFacade@75c83bc4
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name
>>> 'dispatcherServlet' processing GET request for [/push]
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for
>>> path /push
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method
>>> [public void de.cyface.obd2.controller.Obd2Controller.push()]
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of
>>> singleton bean 'obd2Controller'
>>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.web.servlet.DispatcherServlet        : Last-Modified value for
>>> [/push] is: -1
>>> push
>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to
>>> DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter
>>> completed request handling
>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.web.servlet.DispatcherServlet        : Successfully completed request
>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.s.b.w.f.OrderedRequestContextFilter    : Cleared thread-bound request
>>> context: org.apache.catalina.connector.RequestFacade@75c83bc4
>>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>>> o.apache.coyote.http11.Http11Processor   : Socket:
>>> [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2940dec1:org.apache.tomcat.util.net.NioChannel@34a92297:java.nio.channels.SocketChannel[connected
>>> local=/10.42.0.1:8080 remote=/10.42.0.72:46701]], Status in:
>>> [OPEN_READ], State out: [OPEN]
>>> 2016-09-05 13:32:55.280 DEBUG 13143 --- [nio-8080-exec-2]
>>> o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
>>>
>>> java.io.EOFException: null
>>>      at
>>> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1222)
>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1163)
>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:742)
>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:404)
>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:994)
>>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at
>>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>>> [na:1.8.0_91]
>>>      at
>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>>> [na:1.8.0_91]
>>>      at
>>> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
>>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>>      at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
>>> =======================================
>>>
>>> Thanks and regards
>>>      Klemens
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> Hi,
>
> Thanks for the answer.
>
> The request is formatted on the Arduino like:
> "GET /push?VIN=testrun HTTP/1.1\r\nUser-Agent: Freematics\r\nConnection:
> keep-alive\r\nHost: \r\n"
>
> So yes, all lines are terminated with \r\n
>
and are you sure that the software that you use on the Arduino really replaces "\r\n" by a 
real CR/LF pair before sending this to the server ?

(If you set up an Access log on Tomcat, you can check this).
(aside : there is nothing "magical" in the string "\r\n" at the level of the HTTP 
protocol. For HTTP, these are just 4 normal printable characters. The possible "\r\n" 
replacement by a CR/LF pair is a function of what you use *on the agent* to interpret that 
string before printing it.)

Also, it seems to me that since you are specifying "HTTP/1.1" as the protocol in our 
request, the "Host:" line should include a host name.  If your Tomcat only has a default 
Host entry, then use whatever you feel like (Tomcat will default to that default Host anyway).
If your Tomcat has several <Host> entries, use the appropriate hostname.
Like :
Host: mytomcat.mycompany.com<CR/LF>

You /may/ also want to add a header :
Content-length: 0<CR/LF>

although in principle that should not be necessary, since a GET request normally has no 
request body.

Maybe try the following, as a confirmation :
- get an appropriate add-on to a normal browser, which shows the trace of the conversation 
with the server. Examples :
   - for IE : Fiddler2
   - for Mozilla : HttpFox, LiveHttpHeaders or similar
- then activate it,

then issue the same request from the browser to your Tomcat, and look at the HTTP 
conversation in the add-on window.
To send the same request as above, type this in the browser's URL bar :
http://mytomcat.mycompany.com//push?VIN=testrun
(the default request is GET)



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to write a correct HTTP request to Tomcat 8.5.4 instance?

Posted by Klemens Muthmann <kl...@tu-dresden.de>.
Am 05.09.2016 um 14:49 schrieb Tim Watts:
> On Mon, 2016-09-05 at 14:11 +0200, Klemens Muthmann wrote:
>> Hi,
>>
>> I currently need to implement an HTTP data transmission from an Arduino
>> with WiFi module to a PC running a Tomcat 8.5.4 instance. The Tomcat is
>> running under Ubuntu 16.04.
>>
>> The problem is that, since there are no HTTP libraries on Arduino, I
>> need to write the correct HTTP request myself and I got stuck. It would
>> be great if someone on the list with a deeper understanding of the HTTP
>> protocol would be willing to support me.
>> The transmitted (possibly erroneous ) request looks like:
>>
>> ========================================
>> GET /push?VIN=testrun HTTP/1.1
>> User-Agent: Freematics
>> Connection: keep-alive
>> Host:
>>
>> ========================================
>> The server runs under a local access point IP (10.42.0.1) and receives
>> that request correctly but throws me an EOFException from the following
>> code fragment:
>>
>>      nRead = channel.read(socketBufferHandler.getReadBuffer());
>>     if (nRead == -1) {
>>         throw new EOFException();
>>     }
>>
>> So it seems to me that an end of file is reached before it is expected.
>> Can somebody provide me with hints on how to solve that issue and
>> formulate a correct HTTP request to my Tomcat instance?
>>
>> The following is th log trace I receive from the server:
>> ========================================
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> o.a.coyote.http11.Http11InputBuffer      : Received [GET
>> /push?VIN=testrun HTTP/1.1
>> User-Agent: Freematics
>> Connection: keep-alive
>> Host:
>>
>> ]
> Until a real expert comes along with a better answer let me just toss
> this out:  Are the lines in the HTTP request that the Arduino submits
> terminated with \r\n (and not just \n)?  Because it looks like the
> entire request may have been read when reading the request line.  Then
> when it goes to read the headers it gets an EOF.  Not 100% sure of this
> but it's possible.
>
>
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> o.a.c.authenticator.AuthenticatorBase    : Security checking request GET
>> /push
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> org.apache.catalina.realm.RealmBase      :   No applicable constraints
>> defined
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> o.a.c.authenticator.AuthenticatorBase    :  Not subject to any constraint
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> org.apache.tomcat.util.http.Parameters   : Set encoding to UTF-8
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> org.apache.tomcat.util.http.Parameters   : Decoding query null UTF-8
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> org.apache.tomcat.util.http.Parameters   : Start processing with input
>> [VIN=testrun]
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> o.s.b.w.f.OrderedRequestContextFilter    : Bound request context to
>> thread: org.apache.catalina.connector.RequestFacade@75c83bc4
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name
>> 'dispatcherServlet' processing GET request for [/push]
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for
>> path /push
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method
>> [public void de.cyface.obd2.controller.Obd2Controller.push()]
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of
>> singleton bean 'obd2Controller'
>> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
>> o.s.web.servlet.DispatcherServlet        : Last-Modified value for
>> [/push] is: -1
>> push
>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>> o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to
>> DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter
>> completed request handling
>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>> o.s.web.servlet.DispatcherServlet        : Successfully completed request
>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>> o.s.b.w.f.OrderedRequestContextFilter    : Cleared thread-bound request
>> context: org.apache.catalina.connector.RequestFacade@75c83bc4
>> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
>> o.apache.coyote.http11.Http11Processor   : Socket:
>> [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2940dec1:org.apache.tomcat.util.net.NioChannel@34a92297:java.nio.channels.SocketChannel[connected
>> local=/10.42.0.1:8080 remote=/10.42.0.72:46701]], Status in:
>> [OPEN_READ], State out: [OPEN]
>> 2016-09-05 13:32:55.280 DEBUG 13143 --- [nio-8080-exec-2]
>> o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
>>
>> java.io.EOFException: null
>>     at
>> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1222)
>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>     at
>> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1163)
>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>     at
>> org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:742)
>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>     at
>> org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:404)
>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>     at
>> org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:994)
>> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>>     at
>> org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>     at
>> org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>     at
>> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>     at
>> org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>     at
>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>> [na:1.8.0_91]
>>     at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>> [na:1.8.0_91]
>>     at
>> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
>> [tomcat-embed-core-8.5.4.jar:8.5.4]
>>     at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
>> =======================================
>>
>> Thanks and regards
>>     Klemens
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
Hi,

Thanks for the answer.

The request is formatted on the Arduino like:
"GET /push?VIN=testrun HTTP/1.1\r\nUser-Agent: Freematics\r\nConnection:
keep-alive\r\nHost: \r\n"

So yes, all lines are terminated with \r\n

Regards
    Klemens


Re: How to write a correct HTTP request to Tomcat 8.5.4 instance?

Posted by Tim Watts <ti...@cliftonfarm.org>.
On Mon, 2016-09-05 at 14:11 +0200, Klemens Muthmann wrote:
> Hi,
> 
> I currently need to implement an HTTP data transmission from an Arduino
> with WiFi module to a PC running a Tomcat 8.5.4 instance. The Tomcat is
> running under Ubuntu 16.04.
> 
> The problem is that, since there are no HTTP libraries on Arduino, I
> need to write the correct HTTP request myself and I got stuck. It would
> be great if someone on the list with a deeper understanding of the HTTP
> protocol would be willing to support me.
> The transmitted (possibly erroneous ) request looks like:
> 
> ========================================
> GET /push?VIN=testrun HTTP/1.1
> User-Agent: Freematics
> Connection: keep-alive
> Host:
> 
> ========================================
> The server runs under a local access point IP (10.42.0.1) and receives
> that request correctly but throws me an EOFException from the following
> code fragment:
> 
>      nRead = channel.read(socketBufferHandler.getReadBuffer());
>     if (nRead == -1) {
>         throw new EOFException();
>     }
> 
> So it seems to me that an end of file is reached before it is expected.
> Can somebody provide me with hints on how to solve that issue and
> formulate a correct HTTP request to my Tomcat instance?
> 
> The following is th log trace I receive from the server:
> ========================================
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> o.a.coyote.http11.Http11InputBuffer      : Received [GET
> /push?VIN=testrun HTTP/1.1
> User-Agent: Freematics
> Connection: keep-alive
> Host:
> 
> ]

Until a real expert comes along with a better answer let me just toss
this out:  Are the lines in the HTTP request that the Arduino submits
terminated with \r\n (and not just \n)?  Because it looks like the
entire request may have been read when reading the request line.  Then
when it goes to read the headers it gets an EOF.  Not 100% sure of this
but it's possible.


> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> o.a.c.authenticator.AuthenticatorBase    : Security checking request GET
> /push
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> org.apache.catalina.realm.RealmBase      :   No applicable constraints
> defined
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> o.a.c.authenticator.AuthenticatorBase    :  Not subject to any constraint
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> org.apache.tomcat.util.http.Parameters   : Set encoding to UTF-8
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> org.apache.tomcat.util.http.Parameters   : Decoding query null UTF-8
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> org.apache.tomcat.util.http.Parameters   : Start processing with input
> [VIN=testrun]
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> o.s.b.w.f.OrderedRequestContextFilter    : Bound request context to
> thread: org.apache.catalina.connector.RequestFacade@75c83bc4
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name
> 'dispatcherServlet' processing GET request for [/push]
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for
> path /push
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method
> [public void de.cyface.obd2.controller.Obd2Controller.push()]
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of
> singleton bean 'obd2Controller'
> 2016-09-05 13:32:50.238 DEBUG 13143 --- [nio-8080-exec-1]
> o.s.web.servlet.DispatcherServlet        : Last-Modified value for
> [/push] is: -1
> push
> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
> o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to
> DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter
> completed request handling
> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
> o.s.web.servlet.DispatcherServlet        : Successfully completed request
> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
> o.s.b.w.f.OrderedRequestContextFilter    : Cleared thread-bound request
> context: org.apache.catalina.connector.RequestFacade@75c83bc4
> 2016-09-05 13:32:50.239 DEBUG 13143 --- [nio-8080-exec-1]
> o.apache.coyote.http11.Http11Processor   : Socket:
> [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2940dec1:org.apache.tomcat.util.net.NioChannel@34a92297:java.nio.channels.SocketChannel[connected
> local=/10.42.0.1:8080 remote=/10.42.0.72:46701]], Status in:
> [OPEN_READ], State out: [OPEN]
> 2016-09-05 13:32:55.280 DEBUG 13143 --- [nio-8080-exec-2]
> o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
> 
> java.io.EOFException: null
>     at
> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1222)
> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>     at
> org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1163)
> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>     at
> org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:742)
> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>     at
> org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:404)
> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>     at
> org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:994)
> ~[tomcat-embed-core-8.5.4.jar:8.5.4]
>     at
> org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
> [tomcat-embed-core-8.5.4.jar:8.5.4]
>     at
> org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
> [tomcat-embed-core-8.5.4.jar:8.5.4]
>     at
> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
> [tomcat-embed-core-8.5.4.jar:8.5.4]
>     at
> org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
> [tomcat-embed-core-8.5.4.jar:8.5.4]
>     at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> [na:1.8.0_91]
>     at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> [na:1.8.0_91]
>     at
> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> [tomcat-embed-core-8.5.4.jar:8.5.4]
>     at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
> =======================================
> 
> Thanks and regards
>     Klemens
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org