PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/tomcat-7.0.2/java/org/apache/coyote/http11/Http11AprProtocol.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 749 lines | 465 code | 122 blank | 162 comment | 54 complexity | 94cd561c59614dfde33b90e3b1cb1c42 MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.apache.coyote.http11;
  18. import java.net.InetAddress;
  19. import java.net.URLEncoder;
  20. import java.util.HashMap;
  21. import java.util.Iterator;
  22. import java.util.concurrent.ConcurrentHashMap;
  23. import java.util.concurrent.ConcurrentLinkedQueue;
  24. import java.util.concurrent.Executor;
  25. import java.util.concurrent.atomic.AtomicInteger;
  26. import java.util.concurrent.atomic.AtomicLong;
  27. import javax.management.MBeanRegistration;
  28. import javax.management.MBeanServer;
  29. import javax.management.ObjectName;
  30. import org.apache.coyote.ActionCode;
  31. import org.apache.coyote.Adapter;
  32. import org.apache.coyote.ProtocolHandler;
  33. import org.apache.coyote.RequestGroupInfo;
  34. import org.apache.coyote.RequestInfo;
  35. import org.apache.juli.logging.Log;
  36. import org.apache.juli.logging.LogFactory;
  37. import org.apache.tomcat.util.modeler.Registry;
  38. import org.apache.tomcat.util.net.AprEndpoint;
  39. import org.apache.tomcat.util.net.SocketStatus;
  40. import org.apache.tomcat.util.net.AprEndpoint.Handler;
  41. import org.apache.tomcat.util.res.StringManager;
  42. /**
  43. * Abstract the protocol implementation, including threading, etc.
  44. * Processor is single threaded and specific to stream-based protocols,
  45. * will not fit Jk protocols like JNI.
  46. *
  47. * @author Remy Maucherat
  48. * @author Costin Manolache
  49. */
  50. public class Http11AprProtocol implements ProtocolHandler, MBeanRegistration {
  51. private static final Log log = LogFactory.getLog(Http11AprProtocol.class);
  52. /**
  53. * The string manager for this package.
  54. */
  55. protected static final StringManager sm =
  56. StringManager.getManager(Constants.Package);
  57. public Http11AprProtocol() {
  58. setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);
  59. setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);
  60. //setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);
  61. setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
  62. }
  63. /** Pass config info
  64. */
  65. public void setAttribute( String name, Object value ) {
  66. if( log.isTraceEnabled())
  67. log.trace(sm.getString("http11protocol.setattribute", name, value));
  68. attributes.put(name, value);
  69. }
  70. public Object getAttribute( String key ) {
  71. if( log.isTraceEnabled())
  72. log.trace(sm.getString("http11protocol.getattribute", key));
  73. return attributes.get(key);
  74. }
  75. public Iterator<String> getAttributeNames() {
  76. return attributes.keySet().iterator();
  77. }
  78. /**
  79. * The adapter, used to call the connector.
  80. */
  81. protected Adapter adapter;
  82. public void setAdapter(Adapter adapter) { this.adapter = adapter; }
  83. public Adapter getAdapter() { return adapter; }
  84. /** Start the protocol
  85. */
  86. public void init() throws Exception {
  87. endpoint.setName(getName());
  88. endpoint.setHandler(cHandler);
  89. try {
  90. endpoint.init();
  91. } catch (Exception ex) {
  92. log.error(sm.getString("http11protocol.endpoint.initerror"), ex);
  93. throw ex;
  94. }
  95. if(log.isInfoEnabled())
  96. log.info(sm.getString("http11protocol.init", getName()));
  97. }
  98. ObjectName tpOname;
  99. ObjectName rgOname;
  100. public void start() throws Exception {
  101. if( this.domain != null ) {
  102. try {
  103. tpOname=new ObjectName
  104. (domain + ":" + "type=ThreadPool,name=" + getName());
  105. Registry.getRegistry(null, null)
  106. .registerComponent(endpoint, tpOname, null );
  107. } catch (Exception e) {
  108. log.error("Can't register threadpool" );
  109. }
  110. rgOname=new ObjectName
  111. (domain + ":type=GlobalRequestProcessor,name=" + getName());
  112. Registry.getRegistry(null, null).registerComponent
  113. ( cHandler.global, rgOname, null );
  114. }
  115. try {
  116. endpoint.start();
  117. } catch (Exception ex) {
  118. log.error(sm.getString("http11protocol.endpoint.starterror"), ex);
  119. throw ex;
  120. }
  121. if(log.isInfoEnabled())
  122. log.info(sm.getString("http11protocol.start", getName()));
  123. }
  124. public void pause() throws Exception {
  125. try {
  126. endpoint.pause();
  127. } catch (Exception ex) {
  128. log.error(sm.getString("http11protocol.endpoint.pauseerror"), ex);
  129. throw ex;
  130. }
  131. if(log.isInfoEnabled())
  132. log.info(sm.getString("http11protocol.pause", getName()));
  133. }
  134. public void resume() throws Exception {
  135. try {
  136. endpoint.resume();
  137. } catch (Exception ex) {
  138. log.error(sm.getString("http11protocol.endpoint.resumeerror"), ex);
  139. throw ex;
  140. }
  141. if(log.isInfoEnabled())
  142. log.info(sm.getString("http11protocol.resume", getName()));
  143. }
  144. public void destroy() throws Exception {
  145. if(log.isInfoEnabled())
  146. log.info(sm.getString("http11protocol.stop", getName()));
  147. endpoint.destroy();
  148. cHandler.recycledProcessors.clear();
  149. if( tpOname!=null )
  150. Registry.getRegistry(null, null).unregisterComponent(tpOname);
  151. if( rgOname != null )
  152. Registry.getRegistry(null, null).unregisterComponent(rgOname);
  153. }
  154. public String getName() {
  155. String encodedAddr = "";
  156. if (getAddress() != null) {
  157. encodedAddr = "" + getAddress();
  158. if (encodedAddr.startsWith("/"))
  159. encodedAddr = encodedAddr.substring(1);
  160. encodedAddr = URLEncoder.encode(encodedAddr) + "-";
  161. }
  162. return ("http-" + encodedAddr + endpoint.getPort());
  163. }
  164. protected AprEndpoint endpoint=new AprEndpoint();
  165. protected HashMap<String, Object> attributes = new HashMap<String, Object>();
  166. private Http11ConnectionHandler cHandler = new Http11ConnectionHandler(this);
  167. /**
  168. * Processor cache.
  169. */
  170. protected int processorCache = -1;
  171. public int getProcessorCache() { return this.processorCache; }
  172. public void setProcessorCache(int processorCache) { this.processorCache = processorCache; }
  173. public Executor getExecutor() { return endpoint.getExecutor(); }
  174. public void setExecutor(Executor executor) { endpoint.setExecutor(executor); }
  175. public int getMaxThreads() { return endpoint.getMaxThreads(); }
  176. public void setMaxThreads(int maxThreads) { endpoint.setMaxThreads(maxThreads); }
  177. public int getThreadPriority() { return endpoint.getThreadPriority(); }
  178. public void setThreadPriority(int threadPriority) { endpoint.setThreadPriority(threadPriority); }
  179. public int getBacklog() { return endpoint.getBacklog(); }
  180. public void setBacklog(int backlog) { endpoint.setBacklog(backlog); }
  181. public int getPort() { return endpoint.getPort(); }
  182. public void setPort(int port) { endpoint.setPort(port); }
  183. public InetAddress getAddress() { return endpoint.getAddress(); }
  184. public void setAddress(InetAddress ia) { endpoint.setAddress(ia); }
  185. public boolean getTcpNoDelay() { return endpoint.getTcpNoDelay(); }
  186. public void setTcpNoDelay(boolean tcpNoDelay) { endpoint.setTcpNoDelay(tcpNoDelay); }
  187. public int getSoLinger() { return endpoint.getSoLinger(); }
  188. public void setSoLinger(int soLinger) { endpoint.setSoLinger(soLinger); }
  189. public int getSoTimeout() { return endpoint.getSoTimeout(); }
  190. public void setSoTimeout(int soTimeout) { endpoint.setSoTimeout(soTimeout); }
  191. /**
  192. * The number of seconds Tomcat will wait for a subsequent request
  193. * before closing the connection.
  194. */
  195. public int getKeepAliveTimeout() { return endpoint.getKeepAliveTimeout(); }
  196. public void setKeepAliveTimeout(int timeout) { endpoint.setKeepAliveTimeout(timeout); }
  197. public boolean getUseSendfile() { return endpoint.getUseSendfile(); }
  198. public void setUseSendfile(boolean useSendfile) { endpoint.setUseSendfile(useSendfile); }
  199. public int getPollTime() { return endpoint.getPollTime(); }
  200. public void setPollTime(int pollTime) { endpoint.setPollTime(pollTime); }
  201. public void setPollerSize(int pollerSize) { endpoint.setPollerSize(pollerSize); }
  202. public int getPollerSize() { return endpoint.getPollerSize(); }
  203. public void setPollerThreadCount(int pollerThreadCount) { endpoint.setPollerThreadCount(pollerThreadCount); }
  204. public int getPollerThreadCount() { return endpoint.getPollerThreadCount(); }
  205. public int getSendfileSize() { return endpoint.getSendfileSize(); }
  206. public void setSendfileSize(int sendfileSize) { endpoint.setSendfileSize(sendfileSize); }
  207. public void setSendfileThreadCount(int sendfileThreadCount) { endpoint.setSendfileThreadCount(sendfileThreadCount); }
  208. public int getSendfileThreadCount() { return endpoint.getSendfileThreadCount(); }
  209. public boolean getDeferAccept() { return endpoint.getDeferAccept(); }
  210. public void setDeferAccept(boolean deferAccept) { endpoint.setDeferAccept(deferAccept); }
  211. protected int socketBuffer = 9000;
  212. public int getSocketBuffer() { return socketBuffer; }
  213. public void setSocketBuffer(int socketBuffer) { this.socketBuffer = socketBuffer; }
  214. /**
  215. * Maximum size of the post which will be saved when processing certain
  216. * requests, such as a POST.
  217. */
  218. protected int maxSavePostSize = 4 * 1024;
  219. public int getMaxSavePostSize() { return maxSavePostSize; }
  220. public void setMaxSavePostSize(int valueI) { maxSavePostSize = valueI; }
  221. // HTTP
  222. /**
  223. * Maximum size of the HTTP message header.
  224. */
  225. protected int maxHttpHeaderSize = 8 * 1024;
  226. public int getMaxHttpHeaderSize() { return maxHttpHeaderSize; }
  227. public void setMaxHttpHeaderSize(int valueI) { maxHttpHeaderSize = valueI; }
  228. // HTTP
  229. /**
  230. * If true, the regular socket timeout will be used for the full duration
  231. * of the connection.
  232. */
  233. protected boolean disableUploadTimeout = true;
  234. public boolean getDisableUploadTimeout() { return disableUploadTimeout; }
  235. public void setDisableUploadTimeout(boolean isDisabled) { disableUploadTimeout = isDisabled; }
  236. // HTTP
  237. /**
  238. * Integrated compression support.
  239. */
  240. protected String compression = "off";
  241. public String getCompression() { return compression; }
  242. public void setCompression(String valueS) { compression = valueS; }
  243. // HTTP
  244. protected String noCompressionUserAgents = null;
  245. public String getNoCompressionUserAgents() { return noCompressionUserAgents; }
  246. public void setNoCompressionUserAgents(String valueS) { noCompressionUserAgents = valueS; }
  247. // HTTP
  248. protected String compressableMimeTypes = "text/html,text/xml,text/plain";
  249. public String getCompressableMimeType() { return compressableMimeTypes; }
  250. public void setCompressableMimeType(String valueS) { compressableMimeTypes = valueS; }
  251. // HTTP
  252. protected int compressionMinSize = 2048;
  253. public int getCompressionMinSize() { return compressionMinSize; }
  254. public void setCompressionMinSize(int valueI) { compressionMinSize = valueI; }
  255. // HTTP
  256. /**
  257. * User agents regular expressions which should be restricted to HTTP/1.0 support.
  258. */
  259. protected String restrictedUserAgents = null;
  260. public String getRestrictedUserAgents() { return restrictedUserAgents; }
  261. public void setRestrictedUserAgents(String valueS) { restrictedUserAgents = valueS; }
  262. protected String protocol = null;
  263. public String getProtocol() { return protocol; }
  264. public void setProtocol(String protocol) { setSecure(true); this.protocol = protocol; }
  265. /**
  266. * Maximum number of requests which can be performed over a keepalive
  267. * connection. The default is the same as for Apache HTTP Server.
  268. */
  269. protected int maxKeepAliveRequests = 100;
  270. public int getMaxKeepAliveRequests() { return maxKeepAliveRequests; }
  271. public void setMaxKeepAliveRequests(int mkar) { maxKeepAliveRequests = mkar; }
  272. /**
  273. * Return the Keep-Alive policy for the connection.
  274. */
  275. public boolean getKeepAlive() {
  276. return ((maxKeepAliveRequests != 0) && (maxKeepAliveRequests != 1));
  277. }
  278. /**
  279. * Set the keep-alive policy for this connection.
  280. */
  281. public void setKeepAlive(boolean keepAlive) {
  282. if (!keepAlive) {
  283. setMaxKeepAliveRequests(1);
  284. }
  285. }
  286. /**
  287. * Server header.
  288. */
  289. protected String server;
  290. public void setServer( String server ) { this.server = server; }
  291. public String getServer() { return server; }
  292. /**
  293. * This timeout represents the socket timeout which will be used while
  294. * the adapter execution is in progress, unless disableUploadTimeout
  295. * is set to true. The default is the same as for Apache HTTP Server
  296. * (300 000 milliseconds).
  297. */
  298. protected int timeout = 300000;
  299. public int getTimeout() { return timeout; }
  300. public void setTimeout(int timeout) { this.timeout = timeout; }
  301. /**
  302. * This field indicates if the protocol is secure from the perspective of
  303. * the client (= https is used).
  304. */
  305. protected boolean secure;
  306. public boolean getSecure() { return secure; }
  307. public void setSecure(boolean b) { secure = b; }
  308. // -------------------- SSL related properties --------------------
  309. /**
  310. * SSL engine.
  311. */
  312. public boolean isSSLEnabled() { return endpoint.isSSLEnabled(); }
  313. public void setSSLEnabled(boolean SSLEnabled) { endpoint.setSSLEnabled(SSLEnabled); }
  314. /**
  315. * SSL protocol.
  316. */
  317. public String getSSLProtocol() { return endpoint.getSSLProtocol(); }
  318. public void setSSLProtocol(String SSLProtocol) { endpoint.setSSLProtocol(SSLProtocol); }
  319. /**
  320. * SSL password (if a cert is encrypted, and no password has been provided, a callback
  321. * will ask for a password).
  322. */
  323. public String getSSLPassword() { return endpoint.getSSLPassword(); }
  324. public void setSSLPassword(String SSLPassword) { endpoint.setSSLPassword(SSLPassword); }
  325. /**
  326. * SSL cipher suite.
  327. */
  328. public String getSSLCipherSuite() { return endpoint.getSSLCipherSuite(); }
  329. public void setSSLCipherSuite(String SSLCipherSuite) { endpoint.setSSLCipherSuite(SSLCipherSuite); }
  330. /**
  331. * SSL certificate file.
  332. */
  333. public String getSSLCertificateFile() { return endpoint.getSSLCertificateFile(); }
  334. public void setSSLCertificateFile(String SSLCertificateFile) { endpoint.setSSLCertificateFile(SSLCertificateFile); }
  335. /**
  336. * SSL certificate key file.
  337. */
  338. public String getSSLCertificateKeyFile() { return endpoint.getSSLCertificateKeyFile(); }
  339. public void setSSLCertificateKeyFile(String SSLCertificateKeyFile) { endpoint.setSSLCertificateKeyFile(SSLCertificateKeyFile); }
  340. /**
  341. * SSL certificate chain file.
  342. */
  343. public String getSSLCertificateChainFile() { return endpoint.getSSLCertificateChainFile(); }
  344. public void setSSLCertificateChainFile(String SSLCertificateChainFile) { endpoint.setSSLCertificateChainFile(SSLCertificateChainFile); }
  345. /**
  346. * SSL CA certificate path.
  347. */
  348. public String getSSLCACertificatePath() { return endpoint.getSSLCACertificatePath(); }
  349. public void setSSLCACertificatePath(String SSLCACertificatePath) { endpoint.setSSLCACertificatePath(SSLCACertificatePath); }
  350. /**
  351. * SSL CA certificate file.
  352. */
  353. public String getSSLCACertificateFile() { return endpoint.getSSLCACertificateFile(); }
  354. public void setSSLCACertificateFile(String SSLCACertificateFile) { endpoint.setSSLCACertificateFile(SSLCACertificateFile); }
  355. /**
  356. * SSL CA revocation path.
  357. */
  358. public String getSSLCARevocationPath() { return endpoint.getSSLCARevocationPath(); }
  359. public void setSSLCARevocationPath(String SSLCARevocationPath) { endpoint.setSSLCARevocationPath(SSLCARevocationPath); }
  360. /**
  361. * SSL CA revocation file.
  362. */
  363. public String getSSLCARevocationFile() { return endpoint.getSSLCARevocationFile(); }
  364. public void setSSLCARevocationFile(String SSLCARevocationFile) { endpoint.setSSLCARevocationFile(SSLCARevocationFile); }
  365. /**
  366. * SSL verify client.
  367. */
  368. public String getSSLVerifyClient() { return endpoint.getSSLVerifyClient(); }
  369. public void setSSLVerifyClient(String SSLVerifyClient) { endpoint.setSSLVerifyClient(SSLVerifyClient); }
  370. /**
  371. * SSL verify depth.
  372. */
  373. public int getSSLVerifyDepth() { return endpoint.getSSLVerifyDepth(); }
  374. public void setSSLVerifyDepth(int SSLVerifyDepth) { endpoint.setSSLVerifyDepth(SSLVerifyDepth); }
  375. // -------------------- Connection handler --------------------
  376. static class Http11ConnectionHandler implements Handler {
  377. protected Http11AprProtocol proto;
  378. protected AtomicLong registerCount = new AtomicLong(0);
  379. protected RequestGroupInfo global = new RequestGroupInfo();
  380. protected ConcurrentHashMap<Long, Http11AprProcessor> connections =
  381. new ConcurrentHashMap<Long, Http11AprProcessor>();
  382. protected ConcurrentLinkedQueue<Http11AprProcessor> recycledProcessors =
  383. new ConcurrentLinkedQueue<Http11AprProcessor>() {
  384. protected AtomicInteger size = new AtomicInteger(0);
  385. @Override
  386. public boolean offer(Http11AprProcessor processor) {
  387. boolean offer = (proto.processorCache == -1) ? true : (size.get() < proto.processorCache);
  388. //avoid over growing our cache or add after we have stopped
  389. boolean result = false;
  390. if ( offer ) {
  391. result = super.offer(processor);
  392. if ( result ) {
  393. size.incrementAndGet();
  394. }
  395. }
  396. if (!result) unregister(processor);
  397. return result;
  398. }
  399. @Override
  400. public Http11AprProcessor poll() {
  401. Http11AprProcessor result = super.poll();
  402. if ( result != null ) {
  403. size.decrementAndGet();
  404. }
  405. return result;
  406. }
  407. @Override
  408. public void clear() {
  409. Http11AprProcessor next = poll();
  410. while ( next != null ) {
  411. unregister(next);
  412. next = poll();
  413. }
  414. super.clear();
  415. size.set(0);
  416. }
  417. };
  418. Http11ConnectionHandler(Http11AprProtocol proto) {
  419. this.proto = proto;
  420. }
  421. public SocketState event(long socket, SocketStatus status) {
  422. Http11AprProcessor result = connections.get(Long.valueOf(socket));
  423. SocketState state = SocketState.CLOSED;
  424. if (result != null) {
  425. if (result.comet) {
  426. // Call the appropriate event
  427. try {
  428. state = result.event(status);
  429. } catch (java.net.SocketException e) {
  430. // SocketExceptions are normal
  431. Http11AprProtocol.log.debug(sm.getString(
  432. "http11protocol.proto.socketexception.debug"),
  433. e);
  434. } catch (java.io.IOException e) {
  435. // IOExceptions are normal
  436. Http11AprProtocol.log.debug(sm.getString(
  437. "http11protocol.proto.ioexception.debug"), e);
  438. }
  439. // Future developers: if you discover any other
  440. // rare-but-nonfatal exceptions, catch them here, and log as
  441. // above.
  442. catch (Throwable e) {
  443. // any other exception or error is odd. Here we log it
  444. // with "ERROR" level, so it will show up even on
  445. // less-than-verbose logs.
  446. Http11AprProtocol.log.error(sm.getString(
  447. "http11protocol.proto.error"), e);
  448. } finally {
  449. if (state != SocketState.LONG) {
  450. connections.remove(Long.valueOf(socket));
  451. recycledProcessors.offer(result);
  452. if (state == SocketState.OPEN) {
  453. proto.endpoint.getPoller().add(socket);
  454. }
  455. } else {
  456. proto.endpoint.getCometPoller().add(socket);
  457. }
  458. }
  459. } else if (result.async) {
  460. state = asyncDispatch(socket, status);
  461. }
  462. }
  463. return state;
  464. }
  465. public SocketState process(long socket) {
  466. Http11AprProcessor processor = recycledProcessors.poll();
  467. try {
  468. if (processor == null) {
  469. processor = createProcessor();
  470. }
  471. processor.action(ActionCode.ACTION_START, null);
  472. SocketState state = processor.process(socket);
  473. if (state == SocketState.LONG) {
  474. // Associate the connection with the processor. The next request
  475. // processed by this thread will use either a new or a recycled
  476. // processor.
  477. connections.put(Long.valueOf(socket), processor);
  478. proto.endpoint.getCometPoller().add(socket);
  479. } else {
  480. recycledProcessors.offer(processor);
  481. }
  482. return state;
  483. } catch (java.net.SocketException e) {
  484. // SocketExceptions are normal
  485. Http11AprProtocol.log.debug
  486. (sm.getString
  487. ("http11protocol.proto.socketexception.debug"), e);
  488. } catch (java.io.IOException e) {
  489. // IOExceptions are normal
  490. Http11AprProtocol.log.debug
  491. (sm.getString
  492. ("http11protocol.proto.ioexception.debug"), e);
  493. }
  494. // Future developers: if you discover any other
  495. // rare-but-nonfatal exceptions, catch them here, and log as
  496. // above.
  497. catch (Throwable e) {
  498. // any other exception or error is odd. Here we log it
  499. // with "ERROR" level, so it will show up even on
  500. // less-than-verbose logs.
  501. Http11AprProtocol.log.error
  502. (sm.getString("http11protocol.proto.error"), e);
  503. }
  504. recycledProcessors.offer(processor);
  505. return SocketState.CLOSED;
  506. }
  507. public SocketState asyncDispatch(long socket, SocketStatus status) {
  508. Http11AprProcessor result = connections.get(Long.valueOf(socket));
  509. SocketState state = SocketState.CLOSED;
  510. if (result != null) {
  511. // Call the appropriate event
  512. try {
  513. state = result.asyncDispatch(socket, status);
  514. } catch (java.net.SocketException e) {
  515. // SocketExceptions are normal
  516. Http11AprProtocol.log.debug
  517. (sm.getString
  518. ("http11protocol.proto.socketexception.debug"), e);
  519. } catch (java.io.IOException e) {
  520. // IOExceptions are normal
  521. Http11AprProtocol.log.debug
  522. (sm.getString
  523. ("http11protocol.proto.ioexception.debug"), e);
  524. }
  525. // Future developers: if you discover any other
  526. // rare-but-nonfatal exceptions, catch them here, and log as
  527. // above.
  528. catch (Throwable e) {
  529. // any other exception or error is odd. Here we log it
  530. // with "ERROR" level, so it will show up even on
  531. // less-than-verbose logs.
  532. Http11AprProtocol.log.error
  533. (sm.getString("http11protocol.proto.error"), e);
  534. } finally {
  535. if (state != SocketState.LONG) {
  536. connections.remove(Long.valueOf(socket));
  537. recycledProcessors.offer(result);
  538. if (state == SocketState.OPEN) {
  539. proto.endpoint.getPoller().add(socket);
  540. }
  541. }
  542. }
  543. }
  544. return state;
  545. }
  546. protected Http11AprProcessor createProcessor() {
  547. Http11AprProcessor processor =
  548. new Http11AprProcessor(proto.maxHttpHeaderSize, proto.endpoint);
  549. processor.setAdapter(proto.adapter);
  550. processor.setMaxKeepAliveRequests(proto.maxKeepAliveRequests);
  551. processor.setTimeout(proto.timeout);
  552. processor.setDisableUploadTimeout(proto.disableUploadTimeout);
  553. processor.setCompressionMinSize(proto.compressionMinSize);
  554. processor.setCompression(proto.compression);
  555. processor.setNoCompressionUserAgents(proto.noCompressionUserAgents);
  556. processor.setCompressableMimeTypes(proto.compressableMimeTypes);
  557. processor.setRestrictedUserAgents(proto.restrictedUserAgents);
  558. processor.setSocketBuffer(proto.socketBuffer);
  559. processor.setMaxSavePostSize(proto.maxSavePostSize);
  560. processor.setServer(proto.server);
  561. register(processor);
  562. return processor;
  563. }
  564. protected void register(Http11AprProcessor processor) {
  565. if (proto.getDomain() != null) {
  566. synchronized (this) {
  567. try {
  568. long count = registerCount.incrementAndGet();
  569. RequestInfo rp = processor.getRequest().getRequestProcessor();
  570. rp.setGlobalProcessor(global);
  571. ObjectName rpName = new ObjectName
  572. (proto.getDomain() + ":type=RequestProcessor,worker="
  573. + proto.getName() + ",name=HttpRequest" + count);
  574. if (log.isDebugEnabled()) {
  575. log.debug("Register " + rpName);
  576. }
  577. Registry.getRegistry(null, null).registerComponent(rp, rpName, null);
  578. rp.setRpName(rpName);
  579. } catch (Exception e) {
  580. log.warn("Error registering request");
  581. }
  582. }
  583. }
  584. }
  585. protected void unregister(Http11AprProcessor processor) {
  586. if (proto.getDomain() != null) {
  587. synchronized (this) {
  588. try {
  589. RequestInfo rp = processor.getRequest().getRequestProcessor();
  590. rp.setGlobalProcessor(null);
  591. ObjectName rpName = rp.getRpName();
  592. if (log.isDebugEnabled()) {
  593. log.debug("Unregister " + rpName);
  594. }
  595. Registry.getRegistry(null, null).unregisterComponent(rpName);
  596. rp.setRpName(null);
  597. } catch (Exception e) {
  598. log.warn("Error unregistering request", e);
  599. }
  600. }
  601. }
  602. }
  603. }
  604. // -------------------- Various implementation classes --------------------
  605. protected String domain;
  606. protected ObjectName oname;
  607. protected MBeanServer mserver;
  608. public ObjectName getObjectName() {
  609. return oname;
  610. }
  611. public String getDomain() {
  612. return domain;
  613. }
  614. public ObjectName preRegister(MBeanServer server,
  615. ObjectName name) throws Exception {
  616. oname=name;
  617. mserver=server;
  618. domain=name.getDomain();
  619. return name;
  620. }
  621. public void postRegister(Boolean registrationDone) {
  622. }
  623. public void preDeregister() throws Exception {
  624. }
  625. public void postDeregister() {
  626. }
  627. }