9 |
import javax.jms.Session; |
import javax.jms.Session; |
10 |
import javax.jms.TextMessage; |
import javax.jms.TextMessage; |
11 |
import javax.naming.InitialContext; |
import javax.naming.InitialContext; |
12 |
|
import javax.naming.NamingException; |
13 |
import javax.servlet.ServletException; |
import javax.servlet.ServletException; |
14 |
import javax.servlet.annotation.WebServlet; |
import javax.servlet.annotation.WebServlet; |
15 |
import javax.servlet.http.HttpServlet; |
import javax.servlet.http.HttpServlet; |
29 |
// TODO Auto-generated constructor stub |
// TODO Auto-generated constructor stub |
30 |
} |
} |
31 |
|
|
32 |
/* why doesn't these work ?? |
// why doesn't @Resource work ?? |
33 |
@Resource(mappedName = "jms/helloFactory") |
//@Resource(mappedName = "jms/helloFactory") |
34 |
private static ConnectionFactory connectionFactory; |
private static ConnectionFactory connectionFactory; |
35 |
|
|
36 |
@Resource(mappedName = "jms/hello") |
//@Resource(mappedName = "jms/hello") |
37 |
private static Queue queue; |
private static Queue queue; |
38 |
*/ |
|
39 |
|
|
40 |
|
@Override |
41 |
|
public void init() throws ServletException { |
42 |
|
try { |
43 |
|
InitialContext ic = new InitialContext(); |
44 |
|
connectionFactory = (ConnectionFactory)ic.lookup("jms/helloFactory"); |
45 |
|
queue = (Queue)ic.lookup("jms/hello"); |
46 |
|
} catch(NamingException ne) { |
47 |
|
throw new ServletException(ne); |
48 |
|
} |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
53 |
try { |
try { |
54 |
InitialContext ic = new InitialContext(); |
|
55 |
ConnectionFactory cf = (ConnectionFactory)ic.lookup("jms/helloFactory"); |
Connection connection = connectionFactory.createConnection(); |
|
Connection connection = cf.createConnection(); |
|
|
Queue queue = (Queue)ic.lookup("jms/hello"); |
|
56 |
|
|
57 |
//Connection connection = connectionFactory.createConnection(); |
//Connection connection = connectionFactory.createConnection(); |
58 |
|
|