1 |
/* AsyncEjbServlet + Async Ejb - demonstrates how to use async. execution in java EE6 */ |
2 |
|
3 |
package dk.thoerup.asyncsamples; |
4 |
|
5 |
import java.io.IOException; |
6 |
|
7 |
import javax.ejb.EJB; |
8 |
import javax.ejb.embeddable.EJBContainer; |
9 |
import javax.naming.Context; |
10 |
import javax.naming.InitialContext; |
11 |
import javax.naming.NamingException; |
12 |
import javax.servlet.ServletException; |
13 |
import javax.servlet.annotation.WebServlet; |
14 |
import javax.servlet.http.HttpServlet; |
15 |
import javax.servlet.http.HttpServletRequest; |
16 |
import javax.servlet.http.HttpServletResponse; |
17 |
|
18 |
|
19 |
|
20 |
//@EJB(beanInterface=AsyncEjb.class,name="ejb/SimpleBeanJNDI") |
21 |
@WebServlet(name = "AsyncEjbServlet", urlPatterns = { "/AsyncEjbServlet" }) |
22 |
public class AsyncEjbServlet extends HttpServlet { |
23 |
private static final long serialVersionUID = 1L; |
24 |
|
25 |
//private EJBContainer container; |
26 |
//private Context namingContext; |
27 |
|
28 |
@EJB |
29 |
private AsyncEjb asyncBean; |
30 |
|
31 |
|
32 |
public AsyncEjbServlet() { |
33 |
|
34 |
} |
35 |
|
36 |
|
37 |
|
38 |
|
39 |
@Override |
40 |
public void init() throws ServletException { |
41 |
super.init(); |
42 |
|
43 |
/* |
44 |
try { |
45 |
InitialContext ctx = new InitialContext(); |
46 |
|
47 |
asyncBean = (AsyncEjb) ctx.lookup("ejb/SimpleBeanJNDI"); |
48 |
asyncBean = (AsyncEjb) namingContext.lookup("java:global/Test3/AsyncBean"); |
49 |
} catch (NamingException ne) { |
50 |
throw new ServletException(ne); |
51 |
}*/ |
52 |
} |
53 |
|
54 |
|
55 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
56 |
asyncBean.doWork(); |
57 |
response.getWriter().print("Started"); |
58 |
} |
59 |
} |