<div dir="ltr"><div><div><div><div><div><div>I tried - exactly the same results.<br><br></div>Another weird observation is that ServletOutputStream.isReady() is returning true even after the connection is closed (ServletInputStream.isFinished() is correctly returning true).<br>
<br></div>Here's the scenario that works but I can write back the data only once:<br></div>1. In HttpUpgradeHandler I set only the ReadListener<br></div><div>2. I switch the protocol and send some data<br></div>3. ReadListener gets activated i.e. onDataAvailable() is called.<br>
</div><div>4. I process the input data, read as much as possible and put the input into the queue<br></div><div>5. From within ReadListener I set the WriteListener<br></div><div>6. WriteListener.onWritePossible() gets called and I process the data - I clean the queue<br>
</div><div>7. As long as I'm in WriteListener.onWritePossible() (while.out.isReady() is constantly returning true, which is a correct bahavior) the ReadListener is on-hold. I can send as much data as I like but onDataAvailable() is not called<br>
</div><div>8. Only when I leave WriteListener.onWritePossible() method the ReadListener.onDataAvailable() is called again and I can consume the input data again.<br></div><div>9. I can process the input data again i.e. put it into the queue but WriteListener.onWritePossible() is never called again. When I try to reset it I get IllegalStateException<br>
<br></div><div>Either the specification or implementation seem not very mature.... Wildfly behavior is consistent with the one of Tomcat.<br><br></div><div>At the moment I conclude that the non-blocking write is not possible in Servlet 3.1.<br>
<br></div><div>I would appreciate if someone can provide an example that actually works or explain why the weird behavior I observe is correct (is it?)<br><br></div><div>Cheers,<br>Przemyslaw<br></div><div><div></div></div>
</div><div><div><div><div>
<div><br><br></div></div></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 3, 2014 at 6:18 AM, Stuart Douglas <span dir="ltr"><<a href="mailto:stuart.w.douglas@gmail.com" target="_blank">stuart.w.douglas@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Can you try with the latest development build of Wildfly (from <a href="https://ci.jboss.org/hudson/job/WildFly-latest-master/" target="_blank">https://ci.jboss.org/hudson/<u></u>job/WildFly-latest-master/</a>).<br>
<br>
There have been some fixes in this area, so your problem may have already been fixed.<br>
<br>
Stuart<br>
<br>
<br>
PB wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
Hi,<br>
<br>
I'm testing the HTTP Upgrade feature of WF 8.0 and I'm facing some banal<br>
problem. Basically my ReadListener is NEVER called.<br>
Here's the code:<br>
<br>
@WebServlet(urlPatterns = "/upgrade")<br>
public class UpgradeServlet extends HttpServlet {<br>
@Override<br>
protected void doGet(HttpServletRequest req, HttpServletResponse<br>
resp) throws ServletException, IOException {<br>
if ("upgrade".equalsIgnoreCase(<u></u>req.getHeader("Connection"))) {<br>
req.upgrade(EchoHandler.class)<u></u>;<br>
}<br>
}<br>
}<br>
<br>
public class EchoHandler implements HttpUpgradeHandler {<br>
@Override<br>
public void init(WebConnection wc) {<br>
try {<br>
ServletInputStream in = wc.getInputStream();<br>
ServletOutputStream out = wc.getOutputStream();<br>
<br>
BlockingQueue<String> queue = new LinkedBlockingQueue<String>();<br>
in.setReadListener(new EchoReadListener(queue, in));<br>
out.setWriteListener(new EchoWriteListener(queue, out));<br>
} catch (IOException e) {<br>
throw new IllegalStateException(e);<br>
}<br>
}<br>
<br>
public class EchoReadListener implements ReadListener {<br>
@Override<br>
public void onDataAvailable() throws IOException {<br>
while (in.isReady()) {<br>
int length = in.read(buffer);<br>
String input = new String(buffer, 0, length);<br>
if (false == queue.offer(input)) {<br>
System.err.println("'" + input + "' input was ignored");<br>
}<br>
}<br>
}<br>
<br>
I'm connecting to WF using telnet and sending the upgrade request:<br>
GET /example-webapp/upgrade HTTP/1.1<br>
Host: localhost<br>
Connection: upgrade<br>
Upgrade: echo<br>
<br>
and I'm getting correct response:<br>
<br>
HTTP/1.1 101 Switching Protocols<br>
Connection: Upgrade<br>
X-Powered-By: Undertow 1<br>
Server: Wildfly 8<br>
Content-Length: 0<br>
<br>
which means that from now on the protocol between my telnet client and<br>
WF is pure TCP.<br>
So, I start typing some text, hit Enter and.... nothing happens.<br>
onDataAvailable() is NEVER called. More so, this makes WF totally<br>
irresponsive - my whole webapp is dead.<br>
<br>
I believe, I'm doing something wrong - any ideas what exactly? There is<br>
also a slight chance that Upgrade feature in WF is f****d :)<br>
Anyway, WF should not block even in case my upgraded protocol is not<br>
working correctly?<br>
<br>
Many thanks,<br>
Przemyslaw<br>
<br></div></div><div class="">
______________________________<u></u>_________________<br>
wildfly-dev mailing list<br>
<a href="mailto:wildfly-dev@lists.jboss.org" target="_blank">wildfly-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/wildfly-dev" target="_blank">https://lists.jboss.org/<u></u>mailman/listinfo/wildfly-dev</a><br>
</div></blockquote>
</blockquote></div><br></div>