1 |
torben |
648 |
/* 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 |
torben |
668 |
import javax.ejb.EJB; |
8 |
torben |
648 |
import javax.ejb.embeddable.EJBContainer; |
9 |
|
|
import javax.naming.Context; |
10 |
torben |
668 |
import javax.naming.InitialContext; |
11 |
torben |
648 |
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 |
torben |
1269 |
@EJB(beanInterface=AsyncEjb.class,name="ejb/SimpleBeanJNDI") |
21 |
torben |
648 |
@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 |
|
|
private AsyncEjb asyncBean; |
28 |
|
|
|
29 |
|
|
|
30 |
|
|
public AsyncEjbServlet() { |
31 |
|
|
|
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
@Override |
38 |
|
|
public void init() throws ServletException { |
39 |
|
|
super.init(); |
40 |
torben |
668 |
|
41 |
|
|
|
42 |
torben |
648 |
try { |
43 |
torben |
668 |
InitialContext ctx = new InitialContext(); |
44 |
|
|
|
45 |
|
|
asyncBean = (AsyncEjb) ctx.lookup("ejb/SimpleBeanJNDI"); |
46 |
|
|
//asyncBean = (AsyncEjb) namingContext.lookup("java:global/Test3/AsyncBean"); |
47 |
torben |
648 |
} catch (NamingException ne) { |
48 |
|
|
throw new ServletException(ne); |
49 |
|
|
} |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
54 |
torben |
668 |
response.getWriter().print("Started"); |
55 |
torben |
648 |
} |
56 |
|
|
} |