1 package edu.rice.rubis.beans.servlets; 2 3 import java.io.IOException ; 4 5 import javax.jms.Session ; 6 import javax.jms.TextMessage ; 7 import javax.jms.Topic ; 8 import javax.jms.TopicConnection ; 9 import javax.jms.TopicConnectionFactory ; 10 import javax.jms.TopicRequestor ; 11 import javax.jms.TopicSession ; 12 import javax.naming.Context ; 13 import javax.naming.InitialContext ; 14 import javax.servlet.ServletException ; 15 import javax.servlet.http.HttpServlet ; 16 import javax.servlet.http.HttpServletRequest ; 17 import javax.servlet.http.HttpServletResponse ; 18 19 24 public class BrowseRegions extends HttpServlet 25 { 26 27 35 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException , ServletException 36 { 37 ServletPrinter sp = null; 38 String html; 39 sp = new ServletPrinter(response, "BrowseRegions"); 40 sp.printHTMLheader("RUBiS: Available regions"); 41 42 Context initialContext = null; 43 try 44 { 45 initialContext = new InitialContext (); 46 } 47 catch (Exception e) 48 { 49 sp.printHTML("Cannot get initial context for JNDI: " +e+"<br>"); 50 return ; 51 } 52 TopicConnectionFactory topicFactory = null; 53 TopicConnection connection = null; 54 TopicSession session = null; 55 Topic topic = null; 56 try 57 { 58 topicFactory = (TopicConnectionFactory )initialContext.lookup(Config.TopicConnectionFactoryName); 60 connection = topicFactory.createTopicConnection(); 62 topic = (Topic ) initialContext.lookup(Config.PrefixTopicName+"topicBrowseRegions"); 64 session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); } 67 catch (Exception e) 68 { 69 sp.printHTML("Cannot connect to message bean MDB_BrowseRegions : " +e+"<br>"); 70 return ; 71 } 72 try 73 { 74 TopicRequestor requestor = new TopicRequestor (session, topic); 76 TextMessage message = session.createTextMessage(); 78 message.setText("pouet"); 79 message.setJMSCorrelationID("region"); 80 connection.start(); TextMessage reply = (TextMessage )requestor.request(message); 83 connection.stop(); 84 html = reply.getText(); 86 requestor.close(); connection.close(); 89 } 90 catch (Exception e) 91 { 92 sp.printHTML("Error contacting the message bean: " +e+"<br>"); 93 return ; 94 } 95 try 96 { 97 if (html.equals("")) 98 sp.printHTML("<h2>Sorry, but there is no region available at this time. Database table is empty</h2><br>"); 99 else 100 { 101 sp.printHTML("<h2>Currently available regions</h2><br>"); 102 sp.printHTML(html); 103 } 104 } 105 catch (Exception e) 106 { 107 sp.printHTML("Cannot get the list of regions: " +e+"<br>"); 108 return ; 109 } 110 sp.printHTMLfooter(); 111 } 112 113 } 114 | Popular Tags |