[wildfly-dev] WF 8.0 HTTP Upgrade help needed

Przemyslaw Bielicki pbielicki at gmail.com
Wed Apr 2 04:19:46 EDT 2014


Thanks for tips but actually it does not change anything :)

Still there is only the reader that is non-blocking. If you check my
updated example you will see that in the EchoHandler class I added a writer
task which is the only way I found at the moment to have an asynchronous
(yet BLOCKING) way of sending responses to the (telnet) client.

What I noticed is that Read and Write listeners are kind of mutually
exclusive i.e. when I set a WriteListener and ReadListener, the read part
will be NEVER called. When I set only ReadListener it's OK but then I'm not
able to write ServletOutputStream in a non-blocking way. I checked the
Servlet 3.1 specification, which documents Upgrade part very poorly and
they do not say anything about such limitations. I could try to set the
WriterListener from within ReadListener but subsequent calls to
setWriteListener throw IllegalStateException, which does not follow
strictly the specification:

Section 3.7:
"A subsequent call to setReadListener in the scope of the current request
is illegal and an IllegalStateException MUST be thrown."

Section 5.3 (symmetrical to 3.7 but regarding the write):
says nothing about IllegalStateExceptionin in case of subsequent calls to
setWriteListener

There was a presentation during JavaOne 2013 showing the upgrade mechanism,
but of course Oracle guys did not show the good pieces:
https://www.youtube.com/watch?v=LX8tchFSpnA

In conclusion, I am able to read in a non-blocking manner and write in a
blocking way. Anyone has an example how to use non-blocking read and write
streams?

Cheers,
Przemyslaw




On Fri, Mar 28, 2014 at 9:31 PM, Jim McGuinness <dador92 at gmail.com> wrote:

> So here's what I'm getting (my source code is attached) ...
>
>
> __Telnet__
>
> dador-iMac:~ dador$ telnet 10.0.1.14 8080
>
> Trying 10.0.1.14...
>
> Connected to 10.0.1.14.
>
> Escape character is '^]'.
>
> GET /wildfly-debug/upgrade HTTP/1.1
>
> Connection: upgrade
>
>
> HTTP/1.1 101 Switching Protocols
>
> Connection: Upgrade
>
> X-Powered-By: Undertow 1
>
> Server: Wildfly 8
>
> Content-Length: 0
>
> Date: Fri, 28 Mar 2014 20:22:36 GMT
>
>
> the quick brown fox blah, blah, blah
>
> ^]
>
> telnet> quit
>
> Connection closed.
>
> dador-iMac:~ dador$
>
>
> __console___
>
> 15:22:36,825 INFO  [stdout] (default task-15) servlet doGet() received
> 'upgrade'
>
> 15:22:46,488 INFO  [stdout] (default I/O-3) listener onDataAvailable()
> called
>
> 15:22:46,488 INFO  [stdout] (default I/O-3) listener read 'the quick brown
> fox blah, blah, blah'; successfully offered to queue
>
> 15:22:46,489 INFO  [stdout] (default I/O-3) listener read ''; successfully
> offered to queue
>
> 15:22:56,824 INFO  [stdout] (default I/O-3) listener onDataAvailable()
> called
>
> 15:22:56,824 INFO  [stdout] (default I/O-3) listener onAllDataRead() called
>
> 15:22:56,824 INFO  [stdout] (default I/O-3) here is data queued ...
>
> 15:22:56,825 INFO  [stdout] (default I/O-3) the quick brown fox blah,
> blah, blah
>
> 15:22:56,825 INFO  [stdout] (default I/O-3)
>
> 15:22:56,825 INFO  [stdout] (default I/O-3)
>
> 15:22:56,825 INFO  [stdout] (default I/O-3) now do something
>
>
> So the queue is getting the data as it's being piped in (the blanks in the
> queued data are telnet line feeds). But I have to send a signal to the
> servlet that all of the data has been sent (I simply close the telnet
> connection). Then the listener's onAllDataRead() method gets called.
>
> So maybe this is a configuration issue. By the way, it made a difference
> for me in the telnet session when I specified the Connection as "upgrade"
> versus "Upgrade".
>
> Just a suggestion, but you may also want to take a look at the
> non-blocking I/O if you input stream is a long one.
>
> Good luck,
>
> --Jim.
>
>
> On Fri, Mar 28, 2014 at 3:05 PM, PB <pbielicki at gmail.com> wrote:
>
>> Hi,
>>
>> I dare to say that my code is correct ;) The problem is that it is NEVER
>> called - this condition (even if it's wrong, however it's not) is never
>> checked. When I remove this line:
>>
>> out.setWriteListener(new EchoWriteListener(queue, out));
>>
>> it seems to work. However, I have no writer, so it should be rather
>> called SwallowListener... It's not my goal.
>>
>> Maybe I should initialize WriteListener from the ReadListener after the
>> first read? Or maybe, when I want to send back the response I should do
>> this directly from the read listener? e.g.
>> https://java.net/projects/tyrus/sources/source-code-repository/content/trunk/containers/servlet/src/main/java/org/glassfish/tyrus/servlet/TyrusHttpUpgradeHandler.java
>>
>> Thanks,
>> Przemyslaw
>>
>>
>> On Fri, Mar 28, 2014 at 5:14 PM, Heiko Braun <hbraun at redhat.com> wrote:
>>
>>> At a first glance, I'd say your while{} block never returns. Is
>>> ServletInputStream.isFinished() what you've been looking for, instead of
>>> isReady()
>>>
>>> On 28 Mar 2014, at 16:26, PB <pbielicki at gmail.com> wrote:
>>>
>>> while (in.isReady()) {
>>>
>>>
>>>   --
>>>
>>> http://about.me/hbraun
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>> _______________________________________________
>> wildfly-dev mailing list
>> wildfly-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/wildfly-dev
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/wildfly-dev/attachments/20140402/917a0543/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EchoHandler.java
Type: application/octet-stream
Size: 1477 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/wildfly-dev/attachments/20140402/917a0543/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EchoReadListener.java
Type: application/octet-stream
Size: 1050 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/wildfly-dev/attachments/20140402/917a0543/attachment-0001.obj 


More information about the wildfly-dev mailing list