Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Piotr's mock exam question 67, onError() is not called.

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

package com.nullhaus;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

public class MyListener implements AsyncListener {
public void onComplete(AsyncEvent event) {
System.out.println("#Async listener [onComplete]");
}

public void onError(AsyncEvent event) {
System.out.println("#Async listener [onError]");
}

public void onStartAsync(AsyncEvent event) {
System.out.println("#Async listener [onStartAsync]");
}

public void onTimeout(AsyncEvent event) {
System.out.println("#Async listener [onTimeout]");
}
}


package com.nullhaus;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(urlPatterns = "/foo/*",
name="NullServlet",
asyncSupported=true)
public class NullServlet extends HttpServlet {
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException {

final AsyncContext ac = req.startAsync();

try {
Class lClass = Class.forName("com.nullhaus.MyListener");
AsyncListener al = ac.createListener(lClass);

ac.addListener(al);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

ac.setTimeout(3000);

ac.start(new Thread() {
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ac.complete();
}
});
}
}


According to the answer, onError() will be called.
But when I ran it with Tomcat 8.0, it throws IllegalStateException , but the onError() is not called.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic