001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.coyote.http11;
019:
020: import java.net.InetAddress;
021: import java.net.URLEncoder;
022: import java.util.HashMap;
023: import java.util.Iterator;
024: import java.util.concurrent.ConcurrentHashMap;
025: import java.util.concurrent.ConcurrentLinkedQueue;
026: import java.util.concurrent.Executor;
027: import java.util.concurrent.atomic.AtomicInteger;
028: import java.util.concurrent.atomic.AtomicLong;
029:
030: import javax.management.MBeanRegistration;
031: import javax.management.MBeanServer;
032: import javax.management.ObjectName;
033:
034: import org.apache.coyote.ActionCode;
035: import org.apache.coyote.ActionHook;
036: import org.apache.coyote.Adapter;
037: import org.apache.coyote.ProtocolHandler;
038: import org.apache.coyote.RequestGroupInfo;
039: import org.apache.coyote.RequestInfo;
040: import org.apache.tomcat.util.modeler.Registry;
041: import org.apache.tomcat.util.net.AprEndpoint;
042: import org.apache.tomcat.util.net.SocketStatus;
043: import org.apache.tomcat.util.net.AprEndpoint.Handler;
044: import org.apache.tomcat.util.res.StringManager;
045:
046: /**
047: * Abstract the protocol implementation, including threading, etc.
048: * Processor is single threaded and specific to stream-based protocols,
049: * will not fit Jk protocols like JNI.
050: *
051: * @author Remy Maucherat
052: * @author Costin Manolache
053: */
054: public class Http11AprProtocol implements ProtocolHandler,
055: MBeanRegistration {
056:
057: protected static org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory
058: .getLog(Http11AprProtocol.class);
059:
060: /**
061: * The string manager for this package.
062: */
063: protected static StringManager sm = StringManager
064: .getManager(Constants.Package);
065:
066: public Http11AprProtocol() {
067: setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);
068: setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);
069: //setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);
070: setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
071: }
072:
073: /** Pass config info
074: */
075: public void setAttribute(String name, Object value) {
076: if (log.isTraceEnabled())
077: log.trace(sm.getString("http11protocol.setattribute", name,
078: value));
079:
080: attributes.put(name, value);
081: }
082:
083: public Object getAttribute(String key) {
084: if (log.isTraceEnabled())
085: log.trace(sm.getString("http11protocol.getattribute", key));
086: return attributes.get(key);
087: }
088:
089: public Iterator getAttributeNames() {
090: return attributes.keySet().iterator();
091: }
092:
093: /**
094: * Set a property.
095: */
096: public void setProperty(String name, String value) {
097: setAttribute(name, value);
098: }
099:
100: /**
101: * Get a property
102: */
103: public String getProperty(String name) {
104: return (String) getAttribute(name);
105: }
106:
107: /**
108: * The adapter, used to call the connector.
109: */
110: protected Adapter adapter;
111:
112: public void setAdapter(Adapter adapter) {
113: this .adapter = adapter;
114: }
115:
116: public Adapter getAdapter() {
117: return adapter;
118: }
119:
120: /** Start the protocol
121: */
122: public void init() throws Exception {
123: endpoint.setName(getName());
124: endpoint.setHandler(cHandler);
125:
126: try {
127: endpoint.init();
128: } catch (Exception ex) {
129: log.error(
130: sm.getString("http11protocol.endpoint.initerror"),
131: ex);
132: throw ex;
133: }
134: if (log.isInfoEnabled())
135: log.info(sm.getString("http11protocol.init", getName()));
136:
137: }
138:
139: ObjectName tpOname;
140: ObjectName rgOname;
141:
142: public void start() throws Exception {
143: if (this .domain != null) {
144: try {
145: tpOname = new ObjectName(domain + ":"
146: + "type=ThreadPool,name=" + getName());
147: Registry.getRegistry(null, null).registerComponent(
148: endpoint, tpOname, null);
149: } catch (Exception e) {
150: log.error("Can't register threadpool");
151: }
152: rgOname = new ObjectName(domain
153: + ":type=GlobalRequestProcessor,name=" + getName());
154: Registry.getRegistry(null, null).registerComponent(
155: cHandler.global, rgOname, null);
156: }
157:
158: try {
159: endpoint.start();
160: } catch (Exception ex) {
161: log.error(sm
162: .getString("http11protocol.endpoint.starterror"),
163: ex);
164: throw ex;
165: }
166: if (log.isInfoEnabled())
167: log.info(sm.getString("http11protocol.start", getName()));
168: }
169:
170: public void pause() throws Exception {
171: try {
172: endpoint.pause();
173: } catch (Exception ex) {
174: log.error(sm
175: .getString("http11protocol.endpoint.pauseerror"),
176: ex);
177: throw ex;
178: }
179: if (log.isInfoEnabled())
180: log.info(sm.getString("http11protocol.pause", getName()));
181: }
182:
183: public void resume() throws Exception {
184: try {
185: endpoint.resume();
186: } catch (Exception ex) {
187: log.error(sm
188: .getString("http11protocol.endpoint.resumeerror"),
189: ex);
190: throw ex;
191: }
192: if (log.isInfoEnabled())
193: log.info(sm.getString("http11protocol.resume", getName()));
194: }
195:
196: public void destroy() throws Exception {
197: if (log.isInfoEnabled())
198: log.info(sm.getString("http11protocol.stop", getName()));
199: endpoint.destroy();
200: if (tpOname != null)
201: Registry.getRegistry(null, null).unregisterComponent(
202: tpOname);
203: if (rgOname != null)
204: Registry.getRegistry(null, null).unregisterComponent(
205: rgOname);
206: }
207:
208: public String getName() {
209: String encodedAddr = "";
210: if (getAddress() != null) {
211: encodedAddr = "" + getAddress();
212: if (encodedAddr.startsWith("/"))
213: encodedAddr = encodedAddr.substring(1);
214: encodedAddr = URLEncoder.encode(encodedAddr) + "-";
215: }
216: return ("http-" + encodedAddr + endpoint.getPort());
217: }
218:
219: protected AprEndpoint endpoint = new AprEndpoint();
220:
221: protected HashMap<String, Object> attributes = new HashMap<String, Object>();
222:
223: private Http11ConnectionHandler cHandler = new Http11ConnectionHandler(
224: this );
225:
226: /**
227: * Processor cache.
228: */
229: protected int processorCache = -1;
230:
231: public int getProcessorCache() {
232: return this .processorCache;
233: }
234:
235: public void setProcessorCache(int processorCache) {
236: this .processorCache = processorCache;
237: }
238:
239: public Executor getExecutor() {
240: return endpoint.getExecutor();
241: }
242:
243: public void setExecutor(Executor executor) {
244: endpoint.setExecutor(executor);
245: }
246:
247: public int getMaxThreads() {
248: return endpoint.getMaxThreads();
249: }
250:
251: public void setMaxThreads(int maxThreads) {
252: endpoint.setMaxThreads(maxThreads);
253: }
254:
255: public int getThreadPriority() {
256: return endpoint.getThreadPriority();
257: }
258:
259: public void setThreadPriority(int threadPriority) {
260: endpoint.setThreadPriority(threadPriority);
261: }
262:
263: public int getBacklog() {
264: return endpoint.getBacklog();
265: }
266:
267: public void setBacklog(int backlog) {
268: endpoint.setBacklog(backlog);
269: }
270:
271: public int getPort() {
272: return endpoint.getPort();
273: }
274:
275: public void setPort(int port) {
276: endpoint.setPort(port);
277: }
278:
279: public InetAddress getAddress() {
280: return endpoint.getAddress();
281: }
282:
283: public void setAddress(InetAddress ia) {
284: endpoint.setAddress(ia);
285: }
286:
287: public boolean getTcpNoDelay() {
288: return endpoint.getTcpNoDelay();
289: }
290:
291: public void setTcpNoDelay(boolean tcpNoDelay) {
292: endpoint.setTcpNoDelay(tcpNoDelay);
293: }
294:
295: public int getSoLinger() {
296: return endpoint.getSoLinger();
297: }
298:
299: public void setSoLinger(int soLinger) {
300: endpoint.setSoLinger(soLinger);
301: }
302:
303: public int getSoTimeout() {
304: return endpoint.getSoTimeout();
305: }
306:
307: public void setSoTimeout(int soTimeout) {
308: endpoint.setSoTimeout(soTimeout);
309: }
310:
311: /**
312: * The number of seconds Tomcat will wait for a subsequent request
313: * before closing the connection.
314: */
315: public int getKeepAliveTimeout() {
316: return endpoint.getKeepAliveTimeout();
317: }
318:
319: public void setKeepAliveTimeout(int timeout) {
320: endpoint.setKeepAliveTimeout(timeout);
321: }
322:
323: public boolean getUseSendfile() {
324: return endpoint.getUseSendfile();
325: }
326:
327: public void setUseSendfile(boolean useSendfile) {
328: endpoint.setUseSendfile(useSendfile);
329: }
330:
331: public int getPollTime() {
332: return endpoint.getPollTime();
333: }
334:
335: public void setPollTime(int pollTime) {
336: endpoint.setPollTime(pollTime);
337: }
338:
339: public void setPollerSize(int pollerSize) {
340: endpoint.setPollerSize(pollerSize);
341: }
342:
343: public int getPollerSize() {
344: return endpoint.getPollerSize();
345: }
346:
347: public int getSendfileSize() {
348: return endpoint.getSendfileSize();
349: }
350:
351: public void setSendfileSize(int sendfileSize) {
352: endpoint.setSendfileSize(sendfileSize);
353: }
354:
355: protected int socketBuffer = 9000;
356:
357: public int getSocketBuffer() {
358: return socketBuffer;
359: }
360:
361: public void setSocketBuffer(int socketBuffer) {
362: this .socketBuffer = socketBuffer;
363: }
364:
365: /**
366: * Maximum size of the post which will be saved when processing certain
367: * requests, such as a POST.
368: */
369: protected int maxSavePostSize = 4 * 1024;
370:
371: public int getMaxSavePostSize() {
372: return maxSavePostSize;
373: }
374:
375: public void setMaxSavePostSize(int valueI) {
376: maxSavePostSize = valueI;
377: }
378:
379: // HTTP
380: /**
381: * Maximum size of the HTTP message header.
382: */
383: protected int maxHttpHeaderSize = 8 * 1024;
384:
385: public int getMaxHttpHeaderSize() {
386: return maxHttpHeaderSize;
387: }
388:
389: public void setMaxHttpHeaderSize(int valueI) {
390: maxHttpHeaderSize = valueI;
391: }
392:
393: // HTTP
394: /**
395: * If true, the regular socket timeout will be used for the full duration
396: * of the connection.
397: */
398: protected boolean disableUploadTimeout = true;
399:
400: public boolean getDisableUploadTimeout() {
401: return disableUploadTimeout;
402: }
403:
404: public void setDisableUploadTimeout(boolean isDisabled) {
405: disableUploadTimeout = isDisabled;
406: }
407:
408: // HTTP
409: /**
410: * Integrated compression support.
411: */
412: protected String compression = "off";
413:
414: public String getCompression() {
415: return compression;
416: }
417:
418: public void setCompression(String valueS) {
419: compression = valueS;
420: }
421:
422: // HTTP
423: protected String noCompressionUserAgents = null;
424:
425: public String getNoCompressionUserAgents() {
426: return noCompressionUserAgents;
427: }
428:
429: public void setNoCompressionUserAgents(String valueS) {
430: noCompressionUserAgents = valueS;
431: }
432:
433: // HTTP
434: protected String compressableMimeTypes = "text/html,text/xml,text/plain";
435:
436: public String getCompressableMimeType() {
437: return compressableMimeTypes;
438: }
439:
440: public void setCompressableMimeType(String valueS) {
441: compressableMimeTypes = valueS;
442: }
443:
444: // HTTP
445: protected int compressionMinSize = 2048;
446:
447: public int getCompressionMinSize() {
448: return compressionMinSize;
449: }
450:
451: public void setCompressionMinSize(int valueI) {
452: compressionMinSize = valueI;
453: }
454:
455: // HTTP
456: /**
457: * User agents regular expressions which should be restricted to HTTP/1.0 support.
458: */
459: protected String restrictedUserAgents = null;
460:
461: public String getRestrictedUserAgents() {
462: return restrictedUserAgents;
463: }
464:
465: public void setRestrictedUserAgents(String valueS) {
466: restrictedUserAgents = valueS;
467: }
468:
469: public String getProtocol() {
470: return getProperty("protocol");
471: }
472:
473: public void setProtocol(String k) {
474: setSecure(true);
475: setAttribute("protocol", k);
476: }
477:
478: /**
479: * Maximum number of requests which can be performed over a keepalive
480: * connection. The default is the same as for Apache HTTP Server.
481: */
482: protected int maxKeepAliveRequests = 100;
483:
484: public int getMaxKeepAliveRequests() {
485: return maxKeepAliveRequests;
486: }
487:
488: public void setMaxKeepAliveRequests(int mkar) {
489: maxKeepAliveRequests = mkar;
490: }
491:
492: /**
493: * Return the Keep-Alive policy for the connection.
494: */
495: public boolean getKeepAlive() {
496: return ((maxKeepAliveRequests != 0) && (maxKeepAliveRequests != 1));
497: }
498:
499: /**
500: * Set the keep-alive policy for this connection.
501: */
502: public void setKeepAlive(boolean keepAlive) {
503: if (!keepAlive) {
504: setMaxKeepAliveRequests(1);
505: }
506: }
507:
508: /**
509: * Server header.
510: */
511: protected String server;
512:
513: public void setServer(String server) {
514: this .server = server;
515: }
516:
517: public String getServer() {
518: return server;
519: }
520:
521: /**
522: * This timeout represents the socket timeout which will be used while
523: * the adapter execution is in progress, unless disableUploadTimeout
524: * is set to true. The default is the same as for Apache HTTP Server
525: * (300 000 milliseconds).
526: */
527: protected int timeout = 300000;
528:
529: public int getTimeout() {
530: return timeout;
531: }
532:
533: public void setTimeout(int timeout) {
534: this .timeout = timeout;
535: }
536:
537: /**
538: * This field indicates if the protocol is secure from the perspective of
539: * the client (= https is used).
540: */
541: protected boolean secure;
542:
543: public boolean getSecure() {
544: return secure;
545: }
546:
547: public void setSecure(boolean b) {
548: secure = b;
549: }
550:
551: // -------------------- SSL related properties --------------------
552:
553: /**
554: * SSL engine.
555: */
556: public boolean isSSLEnabled() {
557: return endpoint.isSSLEnabled();
558: }
559:
560: public void setSSLEnabled(boolean SSLEnabled) {
561: endpoint.setSSLEnabled(SSLEnabled);
562: }
563:
564: /**
565: * SSL protocol.
566: */
567: public String getSSLProtocol() {
568: return endpoint.getSSLProtocol();
569: }
570:
571: public void setSSLProtocol(String SSLProtocol) {
572: endpoint.setSSLProtocol(SSLProtocol);
573: }
574:
575: /**
576: * SSL password (if a cert is encrypted, and no password has been provided, a callback
577: * will ask for a password).
578: */
579: public String getSSLPassword() {
580: return endpoint.getSSLPassword();
581: }
582:
583: public void setSSLPassword(String SSLPassword) {
584: endpoint.setSSLPassword(SSLPassword);
585: }
586:
587: /**
588: * SSL cipher suite.
589: */
590: public String getSSLCipherSuite() {
591: return endpoint.getSSLCipherSuite();
592: }
593:
594: public void setSSLCipherSuite(String SSLCipherSuite) {
595: endpoint.setSSLCipherSuite(SSLCipherSuite);
596: }
597:
598: /**
599: * SSL certificate file.
600: */
601: public String getSSLCertificateFile() {
602: return endpoint.getSSLCertificateFile();
603: }
604:
605: public void setSSLCertificateFile(String SSLCertificateFile) {
606: endpoint.setSSLCertificateFile(SSLCertificateFile);
607: }
608:
609: /**
610: * SSL certificate key file.
611: */
612: public String getSSLCertificateKeyFile() {
613: return endpoint.getSSLCertificateKeyFile();
614: }
615:
616: public void setSSLCertificateKeyFile(String SSLCertificateKeyFile) {
617: endpoint.setSSLCertificateKeyFile(SSLCertificateKeyFile);
618: }
619:
620: /**
621: * SSL certificate chain file.
622: */
623: public String getSSLCertificateChainFile() {
624: return endpoint.getSSLCertificateChainFile();
625: }
626:
627: public void setSSLCertificateChainFile(
628: String SSLCertificateChainFile) {
629: endpoint.setSSLCertificateChainFile(SSLCertificateChainFile);
630: }
631:
632: /**
633: * SSL CA certificate path.
634: */
635: public String getSSLCACertificatePath() {
636: return endpoint.getSSLCACertificatePath();
637: }
638:
639: public void setSSLCACertificatePath(String SSLCACertificatePath) {
640: endpoint.setSSLCACertificatePath(SSLCACertificatePath);
641: }
642:
643: /**
644: * SSL CA certificate file.
645: */
646: public String getSSLCACertificateFile() {
647: return endpoint.getSSLCACertificateFile();
648: }
649:
650: public void setSSLCACertificateFile(String SSLCACertificateFile) {
651: endpoint.setSSLCACertificateFile(SSLCACertificateFile);
652: }
653:
654: /**
655: * SSL CA revocation path.
656: */
657: public String getSSLCARevocationPath() {
658: return endpoint.getSSLCARevocationPath();
659: }
660:
661: public void setSSLCARevocationPath(String SSLCARevocationPath) {
662: endpoint.setSSLCARevocationPath(SSLCARevocationPath);
663: }
664:
665: /**
666: * SSL CA revocation file.
667: */
668: public String getSSLCARevocationFile() {
669: return endpoint.getSSLCARevocationFile();
670: }
671:
672: public void setSSLCARevocationFile(String SSLCARevocationFile) {
673: endpoint.setSSLCARevocationFile(SSLCARevocationFile);
674: }
675:
676: /**
677: * SSL verify client.
678: */
679: public String getSSLVerifyClient() {
680: return endpoint.getSSLVerifyClient();
681: }
682:
683: public void setSSLVerifyClient(String SSLVerifyClient) {
684: endpoint.setSSLVerifyClient(SSLVerifyClient);
685: }
686:
687: /**
688: * SSL verify depth.
689: */
690: public int getSSLVerifyDepth() {
691: return endpoint.getSSLVerifyDepth();
692: }
693:
694: public void setSSLVerifyDepth(int SSLVerifyDepth) {
695: endpoint.setSSLVerifyDepth(SSLVerifyDepth);
696: }
697:
698: // -------------------- Connection handler --------------------
699:
700: static class Http11ConnectionHandler implements Handler {
701:
702: protected Http11AprProtocol proto;
703: protected AtomicLong registerCount = new AtomicLong(0);
704: protected RequestGroupInfo global = new RequestGroupInfo();
705:
706: protected ConcurrentHashMap<Long, Http11AprProcessor> connections = new ConcurrentHashMap<Long, Http11AprProcessor>();
707: protected ConcurrentLinkedQueue<Http11AprProcessor> recycledProcessors = new ConcurrentLinkedQueue<Http11AprProcessor>() {
708: protected AtomicInteger size = new AtomicInteger(0);
709:
710: public boolean offer(Http11AprProcessor processor) {
711: boolean offer = (proto.processorCache == -1) ? true
712: : (size.get() < proto.processorCache);
713: //avoid over growing our cache or add after we have stopped
714: boolean result = false;
715: if (offer) {
716: result = super .offer(processor);
717: if (result) {
718: size.incrementAndGet();
719: }
720: }
721: if (!result)
722: unregister(processor);
723: return result;
724: }
725:
726: public Http11AprProcessor poll() {
727: Http11AprProcessor result = super .poll();
728: if (result != null) {
729: size.decrementAndGet();
730: }
731: return result;
732: }
733:
734: public void clear() {
735: Http11AprProcessor next = poll();
736: while (next != null) {
737: unregister(next);
738: next = poll();
739: }
740: super .clear();
741: size.set(0);
742: }
743: };
744:
745: Http11ConnectionHandler(Http11AprProtocol proto) {
746: this .proto = proto;
747: }
748:
749: public SocketState event(long socket, SocketStatus status) {
750: Http11AprProcessor result = connections.get(socket);
751:
752: SocketState state = SocketState.CLOSED;
753: if (result != null) {
754: // Call the appropriate event
755: try {
756: state = result.event(status);
757: } catch (java.net.SocketException e) {
758: // SocketExceptions are normal
759: Http11AprProtocol.log
760: .debug(
761: sm
762: .getString("http11protocol.proto.socketexception.debug"),
763: e);
764: } catch (java.io.IOException e) {
765: // IOExceptions are normal
766: Http11AprProtocol.log
767: .debug(
768: sm
769: .getString("http11protocol.proto.ioexception.debug"),
770: e);
771: }
772: // Future developers: if you discover any other
773: // rare-but-nonfatal exceptions, catch them here, and log as
774: // above.
775: catch (Throwable e) {
776: // any other exception or error is odd. Here we log it
777: // with "ERROR" level, so it will show up even on
778: // less-than-verbose logs.
779: Http11AprProtocol.log
780: .error(
781: sm
782: .getString("http11protocol.proto.error"),
783: e);
784: } finally {
785: if (state != SocketState.LONG) {
786: connections.remove(socket);
787: recycledProcessors.offer(result);
788: if (state == SocketState.OPEN) {
789: proto.endpoint.getPoller().add(socket);
790: }
791: } else {
792: proto.endpoint.getCometPoller().add(socket);
793: }
794: }
795: }
796: return state;
797: }
798:
799: public SocketState process(long socket) {
800: Http11AprProcessor processor = recycledProcessors.poll();
801: try {
802: if (processor == null) {
803: processor = createProcessor();
804: }
805:
806: if (processor instanceof ActionHook) {
807: ((ActionHook) processor).action(
808: ActionCode.ACTION_START, null);
809: }
810:
811: SocketState state = processor.process(socket);
812: if (state == SocketState.LONG) {
813: // Associate the connection with the processor. The next request
814: // processed by this thread will use either a new or a recycled
815: // processor.
816: connections.put(socket, processor);
817: proto.endpoint.getCometPoller().add(socket);
818: } else {
819: recycledProcessors.offer(processor);
820: }
821: return state;
822:
823: } catch (java.net.SocketException e) {
824: // SocketExceptions are normal
825: Http11AprProtocol.log
826: .debug(
827: sm
828: .getString("http11protocol.proto.socketexception.debug"),
829: e);
830: } catch (java.io.IOException e) {
831: // IOExceptions are normal
832: Http11AprProtocol.log
833: .debug(
834: sm
835: .getString("http11protocol.proto.ioexception.debug"),
836: e);
837: }
838: // Future developers: if you discover any other
839: // rare-but-nonfatal exceptions, catch them here, and log as
840: // above.
841: catch (Throwable e) {
842: // any other exception or error is odd. Here we log it
843: // with "ERROR" level, so it will show up even on
844: // less-than-verbose logs.
845: Http11AprProtocol.log.error(sm
846: .getString("http11protocol.proto.error"), e);
847: }
848: recycledProcessors.offer(processor);
849: return SocketState.CLOSED;
850: }
851:
852: protected Http11AprProcessor createProcessor() {
853: Http11AprProcessor processor = new Http11AprProcessor(
854: proto.maxHttpHeaderSize, proto.endpoint);
855: processor.setAdapter(proto.adapter);
856: processor
857: .setMaxKeepAliveRequests(proto.maxKeepAliveRequests);
858: processor.setTimeout(proto.timeout);
859: processor
860: .setDisableUploadTimeout(proto.disableUploadTimeout);
861: processor.setCompression(proto.compression);
862: processor.setCompressionMinSize(proto.compressionMinSize);
863: processor
864: .setNoCompressionUserAgents(proto.noCompressionUserAgents);
865: processor
866: .setCompressableMimeTypes(proto.compressableMimeTypes);
867: processor
868: .setRestrictedUserAgents(proto.restrictedUserAgents);
869: processor.setSocketBuffer(proto.socketBuffer);
870: processor.setMaxSavePostSize(proto.maxSavePostSize);
871: processor.setServer(proto.server);
872: register(processor);
873: return processor;
874: }
875:
876: protected void register(Http11AprProcessor processor) {
877: if (proto.getDomain() != null) {
878: synchronized (this ) {
879: try {
880: long count = registerCount.incrementAndGet();
881: RequestInfo rp = processor.getRequest()
882: .getRequestProcessor();
883: rp.setGlobalProcessor(global);
884: ObjectName rpName = new ObjectName(proto
885: .getDomain()
886: + ":type=RequestProcessor,worker="
887: + proto.getName()
888: + ",name=HttpRequest"
889: + count);
890: if (log.isDebugEnabled()) {
891: log.debug("Register " + rpName);
892: }
893: Registry.getRegistry(null, null)
894: .registerComponent(rp, rpName, null);
895: rp.setRpName(rpName);
896: } catch (Exception e) {
897: log.warn("Error registering request");
898: }
899: }
900: }
901: }
902:
903: protected void unregister(Http11AprProcessor processor) {
904: if (proto.getDomain() != null) {
905: synchronized (this ) {
906: try {
907: RequestInfo rp = processor.getRequest()
908: .getRequestProcessor();
909: rp.setGlobalProcessor(null);
910: ObjectName rpName = rp.getRpName();
911: if (log.isDebugEnabled()) {
912: log.debug("Unregister " + rpName);
913: }
914: Registry.getRegistry(null, null)
915: .unregisterComponent(rpName);
916: rp.setRpName(null);
917: } catch (Exception e) {
918: log.warn("Error unregistering request", e);
919: }
920: }
921: }
922: }
923:
924: }
925:
926: // -------------------- Various implementation classes --------------------
927:
928: protected String domain;
929: protected ObjectName oname;
930: protected MBeanServer mserver;
931:
932: public ObjectName getObjectName() {
933: return oname;
934: }
935:
936: public String getDomain() {
937: return domain;
938: }
939:
940: public ObjectName preRegister(MBeanServer server, ObjectName name)
941: throws Exception {
942: oname = name;
943: mserver = server;
944: domain = name.getDomain();
945: return name;
946: }
947:
948: public void postRegister(Boolean registrationDone) {
949: }
950:
951: public void preDeregister() throws Exception {
952: }
953:
954: public void postDeregister() {
955: }
956: }
|