1 17 package org.apache.servicemix.components.http; 18 19 import javax.jbi.JBIException; 20 import javax.jbi.component.ComponentContext; 21 22 import org.mortbay.jetty.Connector; 23 import org.mortbay.jetty.Server; 24 import org.mortbay.jetty.bio.SocketConnector; 25 import org.mortbay.jetty.handler.ContextHandler; 26 import org.mortbay.jetty.servlet.ServletHandler; 27 import org.mortbay.jetty.servlet.ServletHolder; 28 import org.mortbay.jetty.servlet.ServletMapping; 29 import org.mortbay.thread.BoundedThreadPool; 30 31 public class HttpSoapConnector extends HttpSoapInOutBinding { 32 private Connector listener = new SocketConnector(); 33 34 38 private int maxThreads = 256; 39 40 private Server server; 41 42 private String host; 43 44 private int port; 45 46 52 public HttpSoapConnector(String host, int port, boolean defaultInOut) { 53 this.host = host; 54 this.port = port; 55 this.defaultInOut = defaultInOut; 56 } 57 58 public HttpSoapConnector() { 59 } 60 61 66 public HttpSoapConnector(Connector listener) { 67 this.listener = listener; 68 } 69 70 76 public void init(ComponentContext cc) throws JBIException { 77 super.init(cc); 78 if (listener == null) { 80 listener = new SocketConnector(); 81 } 82 listener.setHost(host); 83 listener.setPort(port); 84 server = new Server(); 85 BoundedThreadPool btp = new BoundedThreadPool(); 86 btp.setMaxThreads(getMaxThreads()); 87 server.setThreadPool(btp); 88 } 89 90 95 public void start() throws JBIException { 96 server.setConnectors(new Connector[] { listener }); 97 ContextHandler context = new ContextHandler(); 98 context.setContextPath("/"); 99 ServletHolder holder = new ServletHolder(); 100 holder.setName("jbiServlet"); 101 holder.setClassName(BindingServlet.class.getName()); 102 ServletHandler handler = new ServletHandler(); 103 handler.setServlets(new ServletHolder[] { holder }); 104 ServletMapping mapping = new ServletMapping(); 105 mapping.setServletName("jbiServlet"); 106 mapping.setPathSpec("/*"); 107 handler.setServletMappings(new ServletMapping[] { mapping }); 108 context.setHandler(handler); 109 server.setHandler(context); 110 context.setAttribute("binding", this); 111 try { 112 server.start(); 113 } 114 catch (Exception e) { 115 throw new JBIException("Start failed: " + e, e); 116 } 117 } 118 119 122 public void stop() throws JBIException { 123 try { 124 if (server != null) { 125 server.stop(); 126 } 127 } catch (Exception e) { 128 throw new JBIException("Stop failed: " + e, e); 129 } 130 } 131 132 135 public void shutDown() throws JBIException { 136 server = null; 137 } 138 139 public int getPort() { 142 return port; 143 } 144 145 public void setPort(int port) { 146 this.port = port; 147 } 148 149 public Server getServer() { 150 return server; 151 } 152 153 public void setServer(Server server) { 154 this.server = server; 155 } 156 157 public String getHost() { 158 return host; 159 } 160 161 public void setHost(String host) { 162 this.host = host; 163 } 164 165 public int getMaxThreads() { 166 return maxThreads; 167 } 168 169 public void setMaxThreads(int maxThreads) { 170 this.maxThreads = maxThreads; 171 } 172 } 173 | Popular Tags |