<div dir="ltr"><div><div><div><div>Hi,<br><br></div>I'm testing the HTTP Upgrade feature of WF 8.0 and I'm facing some banal problem. Basically my ReadListener is NEVER called.<br></div>Here's the code:<br><br>
<span style="font-family:courier new,monospace">@WebServlet(urlPatterns = "/upgrade")<br>public class UpgradeServlet extends HttpServlet {<br> @Override<br> protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {<br>
if ("upgrade".equalsIgnoreCase(req.getHeader("Connection"))) {<br> req.upgrade(EchoHandler.class);<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> }</span><br><br></div>I'm connecting to WF using telnet and sending the upgrade request:<br>
<span style="font-family:courier new,monospace">GET /example-webapp/upgrade HTTP/1.1<br>Host: localhost<br>Connection: upgrade<br>Upgrade: echo</span><br><br></div>and I'm getting correct response:<br><div><div><br><span style="font-family:courier new,monospace">HTTP/1.1 101 Switching Protocols<br>
Connection: Upgrade<br>X-Powered-By: Undertow 1<br>Server: Wildfly 8<br>Content-Length: 0<br></span><br></div><div>which means that from now on the protocol between my telnet client and WF is pure TCP.<br></div><div>So, I start typing some text, hit Enter and.... nothing happens. onDataAvailable() is NEVER called. More so, this makes WF totally irresponsive - my whole webapp is dead.<br>
<br></div><div>I believe, I'm doing something wrong - any ideas what exactly? There is 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 working correctly?<br>
<br></div><div>Many thanks,<br>Przemyslaw<br></div></div></div>