1 16 17 package org.apache.coyote.tomcat4; 18 19 20 import java.util.Vector ; 21 import org.apache.tomcat.util.IntrospectionUtils; 22 23 import org.apache.coyote.Adapter; 24 import org.apache.coyote.ProtocolHandler; 25 26 import org.apache.catalina.Connector; 27 import org.apache.catalina.Container; 28 import org.apache.catalina.Lifecycle; 29 import org.apache.catalina.LifecycleException; 30 import org.apache.catalina.LifecycleListener; 31 import org.apache.catalina.Logger; 32 import org.apache.catalina.Request; 33 import org.apache.catalina.Response; 34 import org.apache.catalina.Service; 35 import org.apache.catalina.net.DefaultServerSocketFactory; 36 import org.apache.catalina.net.ServerSocketFactory; 37 import org.apache.catalina.util.LifecycleSupport; 38 import org.apache.catalina.util.StringManager; 39 import org.apache.commons.modeler.Registry; 40 41 import javax.management.MBeanRegistration ; 42 import javax.management.ObjectName ; 43 import javax.management.MBeanServer ; 44 45 46 53 54 public final class CoyoteConnector 55 implements Connector, Lifecycle, MBeanRegistration { 56 57 58 60 61 64 private Service service = null; 65 66 67 70 private int acceptCount = 10; 71 72 73 77 private String address = null; 78 79 80 83 private boolean allowTrace = false; 84 85 86 89 private int bufferSize = 2048; 90 91 92 95 protected Container container = null; 96 97 98 101 private Vector created = new Vector (); 102 103 104 107 private int curProcessors = 0; 108 109 110 113 private int debug = 0; 114 115 116 119 private boolean enableLookups = false; 120 121 122 125 private ServerSocketFactory factory = null; 126 127 128 131 private static final String info = 132 "org.apache.coyote.tomcat4.CoyoteConnector2/1.0"; 133 134 135 138 protected LifecycleSupport lifecycle = new LifecycleSupport(this); 139 140 141 144 protected int minProcessors = 5; 145 146 147 150 protected int maxSpareProcessors = 5; 151 152 153 156 private int maxProcessors = 20; 157 158 159 163 private int connectionLinger = Constants.DEFAULT_CONNECTION_LINGER; 164 165 166 170 private int connectionTimeout = Constants.DEFAULT_CONNECTION_TIMEOUT; 171 172 173 177 private int connectionUploadTimeout = 178 Constants.DEFAULT_CONNECTION_UPLOAD_TIMEOUT; 179 180 181 185 private int serverSocketTimeout = Constants.DEFAULT_SERVER_SOCKET_TIMEOUT; 186 187 188 191 private int port = 8080; 192 193 194 200 private String proxyName = null; 201 202 203 209 private int proxyPort = 0; 210 211 212 215 private int redirectPort = 443; 216 217 218 222 private String scheme = "http"; 223 224 225 229 private boolean secure = false; 230 231 233 private boolean tomcatAuthentication = true; 234 235 238 private StringManager sm = 239 StringManager.getManager(Constants.Package); 240 241 242 245 private boolean initialized = false; 246 247 248 251 private boolean started = false; 252 253 254 257 private boolean stopped = false; 258 259 260 263 private Thread thread = null; 264 265 266 269 private boolean tcpNoDelay = true; 270 271 272 278 private boolean disableUploadTimeout = false; 279 280 283 private int maxKeepAliveRequests = 100; 284 285 286 289 private String compression = "off"; 290 291 292 296 private String protocolHandlerClassName = 297 "org.apache.coyote.http11.Http11Protocol"; 298 299 300 303 private boolean useURIValidationHack = true; 304 305 306 309 private ProtocolHandler protocolHandler = null; 310 311 312 315 private Adapter adapter = null; 316 317 318 321 private String URIEncoding = null; 322 323 324 327 private boolean useBodyEncodingForURI = true; 328 329 330 332 333 336 public Service getService() { 337 338 return (this.service); 339 340 } 341 342 343 348 public void setService(Service service) { 349 350 this.service = service; 351 352 } 353 354 355 358 public int getConnectionLinger() { 359 360 return (connectionLinger); 361 362 } 363 364 365 370 public void setConnectionLinger(int connectionLinger) { 371 372 this.connectionLinger = connectionLinger; 373 374 } 375 376 377 380 public int getConnectionTimeout() { 381 382 return (connectionTimeout); 383 384 } 385 386 387 392 public void setConnectionTimeout(int connectionTimeout) { 393 394 this.connectionTimeout = connectionTimeout; 395 396 } 397 398 399 402 public int getConnectionUploadTimeout() { 403 404 return (connectionUploadTimeout); 405 406 } 407 408 409 414 public void setConnectionUploadTimeout(int connectionUploadTimeout) { 415 416 this.connectionUploadTimeout = connectionUploadTimeout; 417 418 } 419 420 421 424 public int getServerSocketTimeout() { 425 426 return (serverSocketTimeout); 427 428 } 429 430 431 436 public void setServerSocketTimeout(int serverSocketTimeout) { 437 438 this.serverSocketTimeout = serverSocketTimeout; 439 440 } 441 442 443 446 public int getAcceptCount() { 447 448 return (acceptCount); 449 450 } 451 452 453 458 public void setAcceptCount(int count) { 459 460 this.acceptCount = count; 461 462 } 463 464 465 468 public String getAddress() { 469 470 return (this.address); 471 472 } 473 474 475 480 public void setAddress(String address) { 481 482 this.address = address; 483 484 } 485 486 487 490 public boolean getAllowTrace() { 491 492 return (this.allowTrace); 493 494 } 495 496 497 502 public void setAllowTrace(boolean allowTrace) { 503 504 this.allowTrace = allowTrace; 505 506 } 507 508 511 public boolean isAvailable() { 512 513 return (started); 514 515 } 516 517 518 521 public int getBufferSize() { 522 523 return (this.bufferSize); 524 525 } 526 527 528 533 public void setBufferSize(int bufferSize) { 534 535 this.bufferSize = bufferSize; 536 537 } 538 539 540 544 public Container getContainer() { 545 546 return (container); 547 548 } 549 550 551 557 public void setContainer(Container container) { 558 559 this.container = container; 560 561 } 562 563 564 567 public String getCompression() { 568 569 return (compression); 570 571 } 572 573 574 580 public void setCompression(String compression) { 581 582 this.compression = compression; 583 584 } 585 586 587 590 public int getCurProcessors() { 591 592 return (curProcessors); 593 594 } 595 596 597 600 public int getDebug() { 601 602 return (debug); 603 604 } 605 606 607 612 public void setDebug(int debug) { 613 614 this.debug = debug; 615 616 } 617 618 619 622 public boolean getEnableLookups() { 623 624 return (this.enableLookups); 625 626 } 627 628 629 634 public void setEnableLookups(boolean enableLookups) { 635 636 this.enableLookups = enableLookups; 637 638 } 639 640 641 644 public ServerSocketFactory getFactory() { 645 646 if (this.factory == null) { 647 synchronized (this) { 648 this.factory = new DefaultServerSocketFactory(); 649 } 650 } 651 return (this.factory); 652 653 } 654 655 656 661 public void setFactory(ServerSocketFactory factory) { 662 663 this.factory = factory; 664 665 } 666 667 668 671 public String getInfo() { 672 673 return (info); 674 675 } 676 677 678 681 public int getMinProcessors() { 682 683 return (minProcessors); 684 685 } 686 687 688 693 public void setMinProcessors(int minProcessors) { 694 695 this.minProcessors = minProcessors; 696 697 } 698 699 700 703 public int getMaxProcessors() { 704 705 return (maxProcessors); 706 707 } 708 709 710 715 public void setMaxProcessors(int maxProcessors) { 716 717 this.maxProcessors = maxProcessors; 718 719 } 720 721 722 725 public int getMaxSpareProcessors() { 726 727 return (maxSpareProcessors); 728 729 } 730 731 732 737 public void setMaxSpareProcessors(int maxSpareProcessors) { 738 739 this.maxSpareProcessors = maxSpareProcessors; 740 741 } 742 743 744 747 public int getPort() { 748 749 return (this.port); 750 751 } 752 753 754 759 public void setPort(int port) { 760 761 this.port = port; 762 763 } 764 765 766 769 public String getProtocolHandlerClassName() { 770 771 return (this.protocolHandlerClassName); 772 773 } 774 775 776 782 public void setProtocolHandlerClassName(String protocolHandlerClassName) { 783 784 this.protocolHandlerClassName = protocolHandlerClassName; 785 786 } 787 788 789 792 public String getProxyName() { 793 794 return (this.proxyName); 795 796 } 797 798 799 804 public void setProxyName(String proxyName) { 805 806 if(! "".equals(proxyName) ) { 807 this.proxyName = proxyName; 808 } else { 809 this.proxyName = null; 810 } 811 812 } 813 814 815 818 public int getProxyPort() { 819 820 return (this.proxyPort); 821 822 } 823 824 825 830 public void setProxyPort(int proxyPort) { 831 832 this.proxyPort = proxyPort; 833 834 } 835 836 837 842 public int getRedirectPort() { 843 844 return (this.redirectPort); 845 846 } 847 848 849 854 public void setRedirectPort(int redirectPort) { 855 856 this.redirectPort = redirectPort; 857 858 } 859 860 863 public boolean getDisableUploadTimeout() { 864 return disableUploadTimeout; 865 } 866 867 874 public void setDisableUploadTimeout( boolean isDisabled ) { 875 disableUploadTimeout = isDisabled; 876 } 877 878 881 public int getMaxKeepAliveRequests() { 882 return maxKeepAliveRequests; 883 } 884 885 888 public void setMaxKeepAliveRequests(int mkar) { 889 maxKeepAliveRequests = mkar; 890 } 891 892 896 public String getScheme() { 897 898 return (this.scheme); 899 900 } 901 902 903 909 public void setScheme(String scheme) { 910 911 this.scheme = scheme; 912 913 } 914 915 916 920 public boolean getSecure() { 921 922 return (this.secure); 923 924 } 925 926 927 933 public void setSecure(boolean secure) { 934 935 this.secure = secure; 936 937 } 938 939 public boolean getTomcatAuthentication() { 940 return tomcatAuthentication; 941 } 942 943 public void setTomcatAuthentication(boolean tomcatAuthentication) { 944 this.tomcatAuthentication = tomcatAuthentication; 945 } 946 947 950 public boolean getTcpNoDelay() { 951 952 return (this.tcpNoDelay); 953 954 } 955 956 957 963 public void setTcpNoDelay(boolean tcpNoDelay) { 964 965 this.tcpNoDelay = tcpNoDelay; 966 967 } 968 969 970 973 public String getURIEncoding() { 974 975 return (this.URIEncoding); 976 977 } 978 979 980 985 public void setURIEncoding(String URIEncoding) { 986 987 this.URIEncoding = URIEncoding; 988 989 } 990 991 992 995 public boolean getUseBodyEncodingForURI() { 996 997 return (this.useBodyEncodingForURI); 998 999 } 1000 1001 1002 1007 public void setUseBodyEncodingForURI(boolean useBodyEncodingForURI) { 1008 1009 this.useBodyEncodingForURI = useBodyEncodingForURI; 1010 1011 } 1012 1013 1014 1017 public boolean getUseURIValidationHack() { 1018 1019 return (this.useURIValidationHack); 1020 1021 } 1022 1023 1024 1029 public void setUseURIValidationHack(boolean useURIValidationHack) { 1030 1031 this.useURIValidationHack = useURIValidationHack; 1032 1033 } 1034 1035 1036 1038 1039 1043 public Request createRequest() { 1044 1045 CoyoteRequest request = new CoyoteRequest(); 1046 request.setConnector(this); 1047 return (request); 1048 1049 } 1050 1051 1052 1056 public Response createResponse() { 1057 1058 CoyoteResponse response = new CoyoteResponse(); 1059 response.setConnector(this); 1060 return (response); 1061 1062 } 1063 1064 1065 1067 1068 1073 private void log(String message) { 1074 1075 Logger logger = container.getLogger(); 1076 String localName = "CoyoteConnector"; 1077 if (logger != null) 1078 logger.log(localName + " " + message); 1079 else 1080 System.out.println(localName + " " + message); 1081 1082 } 1083 1084 1085 1091 private void log(String message, Throwable throwable) { 1092 1093 Logger logger = container.getLogger(); 1094 String localName = "CoyoteConnector"; 1095 if (logger != null) 1096 logger.log(localName + " " + message, throwable); 1097 else { 1098 System.out.println(localName + " " + message); 1099 throwable.printStackTrace(System.out); 1100 } 1101 1102 } 1103 1104 1105 1107 1108 1113 public void addLifecycleListener(LifecycleListener listener) { 1114 1115 lifecycle.addLifecycleListener(listener); 1116 1117 } 1118 1119 1120 1124 public LifecycleListener[] findLifecycleListeners() { 1125 1126 return null; 1128 } 1129 1130 1131 1136 public void removeLifecycleListener(LifecycleListener listener) { 1137 1138 lifecycle.removeLifecycleListener(listener); 1139 1140 } 1141 1142 1143 1146 public void initialize() 1147 throws LifecycleException { 1148 1149 if (initialized) 1150 throw new LifecycleException 1151 (sm.getString("coyoteConnector.alreadyInitialized")); 1152 1153 this.initialized = true; 1154 1155 adapter = new CoyoteAdapter(this); 1157 1158 try { 1160 Class clazz = Class.forName(protocolHandlerClassName); 1161 protocolHandler = (ProtocolHandler) clazz.newInstance(); 1162 } catch (Exception e) { 1163 e.printStackTrace(); 1164 throw new LifecycleException 1165 (sm.getString 1166 ("coyoteConnector.protocolHandlerInstantiationFailed", e)); 1167 } 1168 protocolHandler.setAdapter(adapter); 1169 1170 IntrospectionUtils.setProperty(protocolHandler, "jkHome", 1171 System.getProperty("catalina.base")); 1172 1173 IntrospectionUtils.setProperty(protocolHandler, "port", "" + port); 1175 IntrospectionUtils.setProperty(protocolHandler, "maxThreads", 1176 "" + maxProcessors); 1177 IntrospectionUtils.setProperty(protocolHandler, "minSpareThreads", 1178 "" + minProcessors); 1179 IntrospectionUtils.setProperty(protocolHandler, "maxSpareThreads", 1180 "" + maxSpareProcessors); 1181 IntrospectionUtils.setProperty(protocolHandler, "backlog", 1182 "" + acceptCount); 1183 IntrospectionUtils.setProperty(protocolHandler, "tcpNoDelay", 1184 "" + tcpNoDelay); 1185 IntrospectionUtils.setProperty(protocolHandler, "soLinger", 1186 "" + connectionLinger); 1187 IntrospectionUtils.setProperty(protocolHandler, "soTimeout", 1188 "" + connectionTimeout); 1189 IntrospectionUtils.setProperty(protocolHandler, "timeout", 1190 "" + connectionUploadTimeout); 1191 IntrospectionUtils.setProperty(protocolHandler, "serverSoTimeout", 1192 "" + serverSocketTimeout); 1193 IntrospectionUtils.setProperty(protocolHandler, "disableUploadTimeout", 1194 "" + disableUploadTimeout); 1195 IntrospectionUtils.setProperty(protocolHandler, "maxKeepAliveRequests", 1196 "" + maxKeepAliveRequests); 1197 IntrospectionUtils.setProperty(protocolHandler, "tomcatAuthentication", 1198 "" + tomcatAuthentication); 1199 IntrospectionUtils.setProperty(protocolHandler, "compression", 1200 compression); 1201 if (address != null) { 1202 IntrospectionUtils.setProperty(protocolHandler, "address", 1203 address); 1204 } 1205 1206 if (factory instanceof CoyoteServerSocketFactory) { 1208 IntrospectionUtils.setProperty(protocolHandler, "secure", 1209 "" + true); 1210 CoyoteServerSocketFactory ssf = 1211 (CoyoteServerSocketFactory) factory; 1212 IntrospectionUtils.setProperty(protocolHandler, "algorithm", 1213 ssf.getAlgorithm()); 1214 IntrospectionUtils.setProperty(protocolHandler, "clientauth", 1215 ssf.getClientAuth()); 1216 IntrospectionUtils.setProperty(protocolHandler, "keystore", 1217 ssf.getKeystoreFile()); 1218 IntrospectionUtils.setProperty(protocolHandler, "randomfile", 1219 ssf.getRandomFile()); 1220 IntrospectionUtils.setProperty(protocolHandler, "rootfile", 1221 ssf.getRootFile()); 1222 1223 IntrospectionUtils.setProperty(protocolHandler, "keypass", 1224 ssf.getKeystorePass()); 1225 IntrospectionUtils.setProperty(protocolHandler, "keytype", 1226 ssf.getKeystoreType()); 1227 IntrospectionUtils.setProperty(protocolHandler, "protocol", 1228 ssf.getProtocol()); 1229 IntrospectionUtils.setProperty(protocolHandler, 1230 "sSLImplementation", 1231 ssf.getSSLImplementation()); 1232 } else { 1233 IntrospectionUtils.setProperty(protocolHandler, "secure", 1234 "" + false); 1235 } 1236 1237 try { 1238 protocolHandler.init(); 1239 } catch (Exception e) { 1240 throw new LifecycleException 1241 (sm.getString 1242 ("coyoteConnector.protocolHandlerInitializationFailed", e)); 1243 } 1244 } 1245 1246 1247 1252 public void start() throws LifecycleException { 1253 1254 if (started) 1256 throw new LifecycleException 1257 (sm.getString("coyoteConnector.alreadyStarted")); 1258 lifecycle.fireLifecycleEvent(START_EVENT, null); 1259 started = true; 1260 1261 if( this.oname != null ) { 1264 try { 1266 Registry.getRegistry().registerComponent(protocolHandler, 1267 this.domain + 1268 ":type=protocolHandler,className=" + protocolHandlerClassName, null); 1269 } catch( Exception ex ) { 1270 ex.printStackTrace(); 1271 } 1272 } else { 1273 log( "Coyote can't register jmx for protocol"); 1274 } 1275 1276 try { 1277 protocolHandler.start(); 1278 } catch (Exception e) { 1279 throw new LifecycleException 1280 (sm.getString 1281 ("coyoteConnector.protocolHandlerStartFailed", e)); 1282 } 1283 1284 } 1285 1286 1287 1292 public void stop() throws LifecycleException { 1293 1294 if (!started) 1296 throw new LifecycleException 1297 (sm.getString("coyoteConnector.notStarted")); 1298 lifecycle.fireLifecycleEvent(STOP_EVENT, null); 1299 started = false; 1300 1301 try { 1302 protocolHandler.destroy(); 1303 } catch (Exception e) { 1304 throw new LifecycleException 1305 (sm.getString 1306 ("coyoteConnector.protocolHandlerDestroyFailed", e)); 1307 } 1308 1309 } 1310 1311 protected String domain; 1312 protected ObjectName oname; 1313 protected MBeanServer mserver; 1314 1315 public ObjectName getObjectName() { 1316 return oname; 1317 } 1318 1319 public String getDomain() { 1320 return domain; 1321 } 1322 1323 public ObjectName preRegister(MBeanServer server, 1324 ObjectName name) throws Exception { 1325 oname=name; 1326 mserver=server; 1327 domain=name.getDomain(); 1328 return name; 1329 } 1330 1331 public void postRegister(Boolean registrationDone) { 1332 } 1333 1334 public void preDeregister() throws Exception { 1335 } 1336 1337 public void postDeregister() { 1338 } 1339 1340} 1341 | Popular Tags |