1 18 package org.apache.activemq.transport.http; 19 20 import org.apache.activemq.broker.BrokerService; 21 import org.apache.activemq.transport.TransportAcceptListener; 22 23 import javax.servlet.ServletException ; 24 25 import java.net.URI ; 26 27 33 public class HttpEmbeddedTunnelServlet extends HttpTunnelServlet { 34 private static final long serialVersionUID = -3705734740251302361L; 35 36 protected BrokerService broker; 37 protected HttpTransportServer transportConnector; 38 39 public synchronized void init() throws ServletException { 40 try { 42 if (broker == null) { 43 broker = createBroker(); 44 45 String url = getConnectorURL(); 47 transportConnector = new HttpTransportServer(new URI (url)); 48 broker.addConnector(transportConnector); 49 50 String brokerURL = getServletContext().getInitParameter("org.apache.activemq.brokerURL"); 51 if (brokerURL != null) { 52 log("Listening for internal communication on: " + brokerURL); 53 } 54 } 55 broker.start(); 56 } 57 catch (Exception e) { 58 throw new ServletException ("Failed to start embedded broker: " + e, e); 59 } 60 TransportAcceptListener listener = transportConnector.getAcceptListener(); 62 getServletContext().setAttribute("transportChannelListener", listener); 63 super.init(); 64 } 65 66 71 protected BrokerService createBroker() throws Exception { 72 BrokerService answer = new BrokerService(); 73 return answer; 74 } 75 76 protected String getConnectorURL() { 77 return "http://localhost/" + getServletContext().getServletContextName(); 78 } 79 } 80 | Popular Tags |