top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Non Blocking API in Tomcat 8.

0 votes
426 views

I have a questions regarding the Non Blocking API introduced in Tomcat 8. I'm looking at the TestNonBlockingAPI test as an example, specifically the NBReadServlet class.

@WebServlet(asyncSupported = true)
public class NBReadServlet extends TesterServlet {
 private static final long serialVersionUID = 1L;
 public volatile TestReadListener listener;
 @Override
 protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
 // step 1 - start async
 AsyncContext actx = req.startAsync();
 actx.setTimeout(Long.MAX_VALUE);
 actx.addListener(new AsyncListener() {
 // removed for brevity 
 });
 // step 2 - notify on read
 ServletInputStream in = req.getInputStream();
 listener = new TestReadListener(actx);
 in.setReadListener(listener);

 listener.onDataAvailable();
 }
}

My question is why does the test call "listener.onDataAvailable()" at the end?

In regards to the "onDataAvailable()" method, Section 3.7 of the spec says…

"The onDataAvailable method is invoked on the ReadListener when data is available to read from the incoming request stream. The container will invoke the method the first time when data is available to read. The container will subsequently invoke the onDataAvailable method if and only if isReady method on ServletInputStream, described below, returns false."

...which leads me to believe that the container should be calling onDataAvailable and not the servlet.

As a side note, my test works if I call "onDataAvailable()" from my test servlet. Otherwise it fails and times out.

posted Aug 7, 2013 by Jai Prakash

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

I think you may have a bug there.

answer Aug 7, 2013 by Satish Mishra
Similar Questions
+1 vote

I'm trying to figure out how to get access to the cookies and headers passed up in the Websocket handshake request on Tomcat 8.

In Tomcat 7 the whole HttpServletRequest was passed into the WebSocketServlet. createWebSocketInbound method so it was easy to grab from the request headers. In Tomcat 8 the querystring and URI are both exposed by the javax.websocket.Session passed to ServerEndPoint.onOpen, but I don't see a mechanism for getting the cookies or headers.

We are integrating Websocket connections into an existing web app and want to use the cookies set by our web app in the Websocket connection process.

+1 vote

I want to access the JNDI Directory context in Tomcat8. I've used DirContextURLStreamHandler class which was in Tomcat 7. But now that has been removed.

Can someone tell me how can I access the JNDI Directory Context in Tomcat 8?

0 votes

I am just trying upgrade tomcat 7 to latest GA 8 for my application, I am seeing quite lots of change in web dav functionality.

The org.apache.naming.resources.ProxyDirContext do not exists do anybody know where I can find the alternative? in the past we got use resource to lookup something but now is not this one, can anybody know any doc?

+1 vote

I'm trying to use the Tomcat8 jsr client functionality in a standalone java client. I'm trying to use the minimal number of jars, so I gabbed websocket-api.jar ONLY. When I call ContainerProvider.getWebSocketContainer(), it returns null. Do I need another jar to resolve this on the client?

+1 vote

I would like to use the Java API for WebSocket (JSR 356) in Tomcat 7. It is currently available in Tomcat 8 and its implementation is in a very good shape. I have performed some stress and scalability testing to verify that.

...