1 18 package org.apache.activemq.transport.http; 19 20 import org.apache.activemq.command.BrokerInfo; 21 import org.apache.activemq.transport.TransportServerSupport; 22 import org.apache.activemq.transport.util.TextWireFormat; 23 import org.apache.activemq.transport.xstream.XStreamWireFormat; 24 import org.apache.activemq.util.ServiceStopper; 25 import org.mortbay.jetty.Connector; 26 import org.mortbay.jetty.Server; 27 import org.mortbay.jetty.bio.SocketConnector; 28 import org.mortbay.jetty.handler.ContextHandler; 29 import org.mortbay.jetty.servlet.ServletHandler; 30 import org.mortbay.jetty.servlet.ServletHolder; 31 import org.mortbay.jetty.servlet.ServletMapping; 32 import org.mortbay.jetty.servlet.SessionHandler; 33 34 import java.net.InetSocketAddress ; 35 import java.net.URI ; 36 37 40 public class HttpTransportServer extends TransportServerSupport { 41 private URI bindAddress; 42 private TextWireFormat wireFormat; 43 private Server server; 44 private Connector connector; 45 46 public HttpTransportServer(URI uri) { 47 super(uri); 48 this.bindAddress = uri; 49 } 50 51 public void setBrokerInfo(BrokerInfo brokerInfo) { 52 } 53 54 public TextWireFormat getWireFormat() { 57 if (wireFormat == null) { 58 wireFormat = createWireFormat(); 59 } 60 return wireFormat; 61 } 62 63 public void setWireFormat(TextWireFormat wireFormat) { 64 this.wireFormat = wireFormat; 65 } 66 67 protected TextWireFormat createWireFormat() { 70 return new XStreamWireFormat(); 71 } 72 73 protected void setConnector(Connector connector) { 74 this.connector = connector; 75 } 76 77 protected void doStart() throws Exception { 78 server = new Server(); 79 if (connector==null) 80 connector = new SocketConnector(); 81 connector.setHost(bindAddress.getHost()); 82 connector.setPort(bindAddress.getPort()); 83 connector.setServer(server); 84 server.setConnectors(new Connector[] { connector }); 85 86 ContextHandler context_handler = new ContextHandler(); 87 context_handler.setContextPath("/"); 88 context_handler.setServer(server); 89 server.setHandler(context_handler); 90 91 SessionHandler session_handler = new SessionHandler(); 92 context_handler.setHandler(session_handler); 93 94 ServletHandler servlet_handler = new ServletHandler(); 95 session_handler.setHandler(servlet_handler); 96 97 ServletHolder holder = new ServletHolder(); 98 holder.setName("httpTunnel"); 99 holder.setClassName(HttpTunnelServlet.class.getName()); 100 servlet_handler.setServlets(new ServletHolder[] { holder }); 101 102 ServletMapping mapping = new ServletMapping(); 103 mapping.setServletName("httpTunnel"); 104 mapping.setPathSpec("/*"); 105 servlet_handler.setServletMappings(new ServletMapping[] { mapping }); 106 107 context_handler.setAttribute("acceptListener", getAcceptListener()); 108 context_handler.setAttribute("wireFormat", getWireFormat()); 109 server.start(); 110 } 111 112 protected void doStop(ServiceStopper stopper) throws Exception { 113 Server temp = server; 114 server = null; 115 if (temp != null) { 116 temp.stop(); 117 } 118 } 119 120 public InetSocketAddress getSocketAddress() { 121 return null; 122 } 123 124 } 125 | Popular Tags |