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 |
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 |
|
41 |
|
42 |
try { |
43 |
InitialContext ctx = new InitialContext(); |
44 |
|
45 |
asyncBean = (AsyncEjb) ctx.lookup("ejb/SimpleBeanJNDI"); |
46 |
//asyncBean = (AsyncEjb) namingContext.lookup("java:global/Test3/AsyncBean"); |
47 |
} catch (NamingException ne) { |
48 |
throw new ServletException(ne); |
49 |
} |
50 |
} |
51 |
|
52 |
|
53 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
54 |
response.getWriter().print("Started"); |
55 |
} |
56 |
} |