1 2 3 27 28 29 package org.apache.coyote.tomcat5; 30 31 import java.lang.reflect.Constructor ; 32 import java.net.URLEncoder ; 33 import java.lang.reflect.Method ; 34 import java.util.ArrayList ; 35 import java.util.StringTokenizer ; 36 import java.util.Vector ; 37 import java.util.HashMap ; 38 import java.util.Iterator ; 39 40 import java.security.cert.X509Certificate ; 42 import javax.management.ObjectName ; 44 import javax.management.MBeanServer ; 45 import javax.management.MBeanRegistration ; 46 import javax.management.MalformedObjectNameException ; 47 48 import javax.servlet.http.HttpServletRequest ; 49 50 import com.sun.org.apache.commons.modeler.Registry; 51 import com.sun.org.apache.commons.logging.Log; 52 import com.sun.org.apache.commons.logging.LogFactory; 53 54 import org.apache.tomcat.util.IntrospectionUtils; 55 import org.apache.tomcat.util.http.mapper.Mapper; 56 57 import org.apache.coyote.Adapter; 58 import org.apache.coyote.ProtocolHandler; 59 60 import org.apache.catalina.Connector; 61 import org.apache.catalina.Container; 62 import org.apache.catalina.Lifecycle; 63 import org.apache.catalina.LifecycleException; 64 import org.apache.catalina.LifecycleListener; 65 import org.apache.catalina.Logger; 66 import org.apache.catalina.Request; 67 import org.apache.catalina.Response; 68 import org.apache.catalina.Service; 69 import org.apache.catalina.Engine; 70 import org.apache.catalina.Globals; 72 import org.apache.catalina.core.ContainerBase; 74 import org.apache.catalina.core.StandardEngine; 75 import org.apache.catalina.net.DefaultServerSocketFactory; 76 import org.apache.catalina.net.ServerSocketFactory; 77 import org.apache.catalina.util.LifecycleSupport; 78 import org.apache.catalina.util.StringManager; 79 import com.sun.appserv.ProxyHandler; 81 83 90 91 92 public class CoyoteConnector 93 implements Connector, Lifecycle, MBeanRegistration 94 { 95 private static Log log = LogFactory.getLog(CoyoteConnector.class); 96 97 99 104 private String defaultClassName = 105 "org.apache.coyote.tomcat5.CoyoteAdapter"; 106 108 109 111 114 private HashMap properties = new HashMap (); 115 116 119 private Service service = null; 120 121 122 125 private int acceptCount = 10; 126 127 128 132 private String address = null; 133 134 135 138 private boolean allowTrace = true; 139 140 141 144 private int bufferSize = 4096; 145 146 147 150 protected Container container = null; 151 152 153 156 private String compression = "off"; 157 158 159 162 private int debug = 0; 163 164 165 168 private boolean enableLookups = false; 169 170 171 174 private ServerSocketFactory factory = null; 175 176 179 private int maxHttpHeaderSize = 4 * 1024; 180 181 184 private boolean xpoweredBy; 185 186 187 190 private static final String info = 191 "org.apache.coyote.tomcat5.CoyoteConnector/2.0"; 192 193 194 197 protected LifecycleSupport lifecycle = new LifecycleSupport(this); 198 199 200 203 protected int minProcessors = 5; 204 205 206 209 private int maxProcessors = 20; 210 211 212 216 private int connectionLinger = Constants.DEFAULT_CONNECTION_LINGER; 217 218 219 223 private int connectionTimeout = Constants.DEFAULT_CONNECTION_TIMEOUT; 224 225 226 230 private int connectionUploadTimeout = 231 Constants.DEFAULT_CONNECTION_UPLOAD_TIMEOUT; 232 233 234 238 private int serverSocketTimeout = Constants.DEFAULT_SERVER_SOCKET_TIMEOUT; 239 240 241 244 private int port = 8080; 245 246 247 253 private String proxyName = null; 254 255 256 262 private int proxyPort = 0; 263 264 265 268 private int redirectPort = 443; 269 270 271 275 private String defaultHost; 276 278 279 283 private String scheme = "http"; 284 285 286 290 private boolean secure = false; 291 292 294 private boolean tomcatAuthentication = true; 295 296 299 private StringManager sm = 300 StringManager.getManager(Constants.Package); 301 302 303 309 private boolean disableUploadTimeout = false; 310 311 314 private int maxKeepAliveRequests = 100; 315 316 317 321 private int maxPostSize = 2 * 1024 * 1024; 322 323 324 327 private boolean initialized = false; 328 329 330 333 private boolean started = false; 334 335 336 339 private boolean stopped = false; 340 341 342 345 private Thread thread = null; 346 347 348 351 private boolean tcpNoDelay = true; 352 353 354 358 private String protocolHandlerClassName = 359 "org.apache.coyote.http11.Http11Protocol"; 360 361 364 private ProtocolHandler protocolHandler = null; 365 366 367 370 private Adapter adapter = null; 371 372 373 376 private Mapper mapper = new Mapper(); 377 378 379 382 private MapperListener mapperListener = new MapperListener(mapper); 383 384 385 388 private String URIEncoding = null; 389 390 391 private boolean isEnabled = true; 393 395 396 401 protected boolean authPassthroughEnabled = false; 402 403 protected ProxyHandler proxyHandler = null; 404 406 408 411 public Object getProperty(String name) { 412 return properties.get(name); 413 } 414 415 418 public void setProperty(String name, Object value) { 419 properties.put(name, value); 420 } 421 422 425 public void removeProperty(String name) { 426 properties.remove(name); 427 } 428 429 432 public Service getService() { 433 434 return (this.service); 435 436 } 437 438 439 444 public void setService(Service service) { 445 446 this.service = service; 447 setProperty("service", service); 448 449 } 450 451 452 455 public String getCompression() { 456 457 return (compression); 458 459 } 460 461 462 468 public void setCompression(String compression) { 469 470 this.compression = compression; 471 setProperty("compression", compression); 472 473 } 474 475 476 479 public int getConnectionLinger() { 480 481 return (connectionLinger); 482 483 } 484 485 486 491 public void setConnectionLinger(int connectionLinger) { 492 493 this.connectionLinger = connectionLinger; 494 setProperty("soLinger", String.valueOf(connectionLinger)); 495 496 } 497 498 499 502 public int getConnectionTimeout() { 503 504 return (connectionTimeout); 505 506 } 507 508 509 514 public void setConnectionTimeout(int connectionTimeout) { 515 516 this.connectionTimeout = connectionTimeout; 517 setProperty("soTimeout", String.valueOf(connectionTimeout)); 518 519 } 520 521 522 525 public int getConnectionUploadTimeout() { 526 527 return (connectionUploadTimeout); 528 529 } 530 531 532 537 public void setConnectionUploadTimeout(int connectionUploadTimeout) { 538 539 this.connectionUploadTimeout = connectionUploadTimeout; 540 setProperty("timeout", String.valueOf(connectionUploadTimeout)); 541 542 } 543 544 545 548 public int getServerSocketTimeout() { 549 550 return (serverSocketTimeout); 551 552 } 553 554 555 560 public void setServerSocketTimeout(int serverSocketTimeout) { 561 562 this.serverSocketTimeout = serverSocketTimeout; 563 setProperty("serverSoTimeout", String.valueOf(serverSocketTimeout)); 564 565 } 566 567 568 571 public int getAcceptCount() { 572 573 return (acceptCount); 574 575 } 576 577 578 583 public void setAcceptCount(int count) { 584 585 this.acceptCount = count; 586 setProperty("backlog", String.valueOf(count)); 587 588 } 589 590 591 594 public String getAddress() { 595 596 return (this.address); 597 598 } 599 600 601 606 public void setAddress(String address) { 607 608 this.address = address; 609 setProperty("address", address); 610 611 } 612 613 614 615 618 public boolean getAllowTrace() { 619 620 return (this.allowTrace); 621 622 } 623 624 625 629 public void setAllowTrace(boolean allowTrace) { 630 631 this.allowTrace = allowTrace; 632 setProperty("allowTrace", String.valueOf(allowTrace)); 633 634 } 635 636 637 640 public boolean isAvailable() { 641 642 return (started); 643 644 } 645 646 647 650 public int getBufferSize() { 651 652 return (this.bufferSize); 653 654 } 655 656 657 662 public void setBufferSize(int bufferSize) { 663 664 this.bufferSize = bufferSize; 665 setProperty("bufferSize", String.valueOf(bufferSize)); 666 667 } 668 669 670 674 public Container getContainer() { 675 if( container==null ) { 676 findContainer(); 678 } 679 return (container); 680 681 } 682 683 684 690 public void setContainer(Container container) { 691 692 this.container = container; 693 694 } 695 696 697 700 public int getDebug() { 701 702 return (debug); 703 704 } 705 706 707 712 public void setDebug(int debug) { 713 714 this.debug = debug; 715 716 } 717 718 719 722 public boolean getEnableLookups() { 723 724 return (this.enableLookups); 725 726 } 727 728 729 734 public void setEnableLookups(boolean enableLookups) { 735 736 this.enableLookups = enableLookups; 737 setProperty("enableLookups", String.valueOf(enableLookups)); 738 739 } 740 741 742 745 public ServerSocketFactory getFactory() { 746 747 return (this.factory); 748 749 } 750 751 752 757 public void setFactory(ServerSocketFactory factory) { 758 759 this.factory = factory; 760 761 } 762 763 764 767 public String getInfo() { 768 769 return (info); 770 771 } 772 773 774 777 public Mapper getMapper() { 778 779 return (mapper); 780 781 } 782 783 784 787 public int getMinProcessors() { 788 789 return (minProcessors); 790 791 } 792 793 794 799 public void setMinProcessors(int minProcessors) { 800 801 this.minProcessors = minProcessors; 802 setProperty("minThreads", String.valueOf(minProcessors)); 803 804 } 805 806 807 810 public int getMaxProcessors() { 811 812 return (maxProcessors); 813 814 } 815 816 817 822 public void setMaxProcessors(int maxProcessors) { 823 824 this.maxProcessors = maxProcessors; 825 setProperty("maxThreads", String.valueOf(maxProcessors)); 826 827 } 828 829 830 834 public int getMaxPostSize() { 835 836 return (maxPostSize); 837 838 } 839 840 841 848 public void setMaxPostSize(int maxPostSize) { 849 850 this.maxPostSize = maxPostSize; 851 setProperty("maxPostSize", String.valueOf(maxPostSize)); 852 } 853 854 855 858 public int getPort() { 859 860 return (this.port); 861 862 } 863 864 865 870 public void setPort(int port) { 871 872 this.port = port; 873 setProperty("port", String.valueOf(port)); 874 875 } 876 877 878 881 public String getProtocol() { 882 883 if ("org.apache.coyote.http11.Http11Protocol".equals 884 (getProtocolHandlerClassName())) { 885 return "HTTP/1.1"; 886 } else if ("org.apache.jk.server.JkCoyoteHandler".equals 887 (getProtocolHandlerClassName())) { 888 return "AJP/1.3"; 889 } 890 return null; 891 892 } 893 894 895 900 public void setProtocol(String protocol) { 901 902 if (protocol.equals("HTTP/1.1")) { 903 setProtocolHandlerClassName 904 ("org.apache.coyote.http11.Http11Protocol"); 905 } else if (protocol.equals("AJP/1.3")) { 906 setProtocolHandlerClassName 907 ("org.apache.jk.server.JkCoyoteHandler"); 908 } else { 909 setProtocolHandlerClassName(null); 910 } 911 912 } 913 914 915 918 public String getProtocolHandlerClassName() { 919 920 return (this.protocolHandlerClassName); 921 922 } 923 924 925 931 public void setProtocolHandlerClassName(String protocolHandlerClassName) { 932 933 this.protocolHandlerClassName = protocolHandlerClassName; 934 935 } 936 937 938 941 public ProtocolHandler getProtocolHandler() { 942 943 return (this.protocolHandler); 944 945 } 946 947 948 951 public String getProxyName() { 952 953 return (this.proxyName); 954 955 } 956 957 958 963 public void setProxyName(String proxyName) { 964 965 if(proxyName != null && proxyName.length() > 0) { 966 this.proxyName = proxyName; 967 setProperty("proxyName", proxyName); 968 } else { 969 this.proxyName = null; 970 removeProperty("proxyName"); 971 } 972 973 } 974 975 976 979 public int getProxyPort() { 980 981 return (this.proxyPort); 982 983 } 984 985 986 991 public void setProxyPort(int proxyPort) { 992 993 this.proxyPort = proxyPort; 994 setProperty("proxyPort", String.valueOf(proxyPort)); 995 996 } 997 998 999 1004 public int getRedirectPort() { 1005 1006 return (this.redirectPort); 1007 1008 } 1009 1010 1011 1016 public void setRedirectPort(int redirectPort) { 1017 1018 this.redirectPort = redirectPort; 1019 setProperty("redirectPort", String.valueOf(redirectPort)); 1020 1021 } 1022 1023 1026 public boolean getDisableUploadTimeout() { 1027 return disableUploadTimeout; 1028 } 1029 1030 1037 public void setDisableUploadTimeout( boolean isDisabled ) { 1038 disableUploadTimeout = isDisabled; 1039 setProperty("disableUploadTimeout", String.valueOf(isDisabled)); 1040 } 1041 1042 1045 public int getMaxHttpHeaderSize() { 1046 return maxHttpHeaderSize; 1047 } 1048 1049 1052 public void setMaxHttpHeaderSize(int size) { 1053 maxHttpHeaderSize = size; 1054 setProperty("maxHttpHeaderSize", String.valueOf(size)); 1055 } 1056 1057 1060 public boolean getKeepAlive() { 1061 return ((maxKeepAliveRequests != 0) && (maxKeepAliveRequests != 1)); 1062 } 1063 1064 1067 public void setKeepAlive(boolean keepAlive) { 1068 if (!keepAlive) { 1069 setMaxKeepAliveRequests(1); 1070 } 1071 } 1072 1073 1077 public int getMaxKeepAliveRequests() { 1078 return maxKeepAliveRequests; 1079 } 1080 1081 1084 public void setMaxKeepAliveRequests(int mkar) { 1085 maxKeepAliveRequests = mkar; 1086 setProperty("maxKeepAliveRequests", String.valueOf(mkar)); 1087 } 1088 1089 1093 public String getScheme() { 1094 1095 return (this.scheme); 1096 1097 } 1098 1099 1100 1106 public void setScheme(String scheme) { 1107 1108 this.scheme = scheme; 1109 setProperty("scheme", scheme); 1110 1111 } 1112 1113 1114 1118 public boolean getSecure() { 1119 1120 return (this.secure); 1121 1122 } 1123 1124 1125 1131 public void setSecure(boolean secure) { 1132 1133 this.secure = secure; 1134 setProperty("secure", String.valueOf(secure)); 1135 1136 } 1137 1138 public boolean getTomcatAuthentication() { 1139 return tomcatAuthentication; 1140 } 1141 1142 public void setTomcatAuthentication(boolean tomcatAuthentication) { 1143 this.tomcatAuthentication = tomcatAuthentication; 1144 setProperty("tomcatAuthentication", String.valueOf(tomcatAuthentication)); 1145 } 1146 1147 1148 1151 public boolean getTcpNoDelay() { 1152 1153 return (this.tcpNoDelay); 1154 1155 } 1156 1157 1158 1164 public void setTcpNoDelay(boolean tcpNoDelay) { 1165 1166 this.tcpNoDelay = tcpNoDelay; 1167 setProperty("tcpNoDelay", String.valueOf(tcpNoDelay)); 1168 1169 } 1170 1171 1172 1175 public String getURIEncoding() { 1176 1177 return (this.URIEncoding); 1178 1179 } 1180 1181 1182 1187 public void setURIEncoding(String URIEncoding) { 1188 1189 this.URIEncoding = URIEncoding; 1190 setProperty("uRIEncoding", URIEncoding); 1191 1192 } 1193 1194 1195 1202 public boolean isXpoweredBy() { 1203 return xpoweredBy; 1204 } 1205 1206 1207 1215 public void setXpoweredBy(boolean xpoweredBy) { 1216 this.xpoweredBy = xpoweredBy; 1217 setProperty("xpoweredBy", String.valueOf(xpoweredBy)); 1218 } 1219 1220 1221 1227 public void setDefaultHost(String defaultHost) { 1228 this.defaultHost = defaultHost; 1229 } 1230 1231 1236 public String getDefaultHost() { 1237 return this.defaultHost; 1238 } 1239 1241 1242 1249 public boolean getAuthPassthroughEnabled() { 1250 return this.authPassthroughEnabled; 1251 } 1252 1253 1259 public void setAuthPassthroughEnabled(boolean authPassthroughEnabled) { 1260 this.authPassthroughEnabled = authPassthroughEnabled; 1261 } 1262 1263 1269 public ProxyHandler getProxyHandler() { 1270 return proxyHandler; 1271 } 1272 1273 1278 public void setProxyHandler(ProxyHandler proxyHandler) { 1279 this.proxyHandler = proxyHandler; 1280 } 1281 1283 1284 public void setIsEnabled(boolean isEnabled) { 1286 this.isEnabled = isEnabled; 1287 } 1288 1289 public boolean isEnabled() { 1290 return isEnabled; 1291 } 1292 1294 1295 1297 1298 1302 public Request createRequest() { 1303 1304 CoyoteRequest request = new CoyoteRequest(); 1305 request.setConnector(this); 1306 return (request); 1307 1308 } 1309 1310 1311 1315 public Response createResponse() { 1316 1317 CoyoteResponse response = new CoyoteResponse(); 1318 response.setConnector(this); 1319 return (response); 1320 1321 } 1322 1323 1324 1326 1327 1332 private void log(String message) { 1333 1334 Logger logger = container.getLogger(); 1335 String localName = "CoyoteConnector"; 1336 if (logger != null) 1337 logger.log(localName + " " + message); 1338 else 1339 System.out.println(localName + " " + message); 1340 1341 } 1342 1343 1344 1350 private void log(String message, Throwable throwable) { 1351 1352 Logger logger = container.getLogger(); 1353 String localName = "CoyoteConnector"; 1354 if (logger != null) 1355 logger.log(localName + " " + message, throwable); 1356 else { 1357 System.out.println(localName + " " + message); 1358 throwable.printStackTrace(System.out); 1359 } 1360 1361 } 1362 1363 1364 1366 1367 1372 public void addLifecycleListener(LifecycleListener listener) { 1373 1374 lifecycle.addLifecycleListener(listener); 1375 1376 } 1377 1378 1379 1383 public LifecycleListener[] findLifecycleListeners() { 1384 1385 return null; 1387 } 1388 1389 1390 1395 public void removeLifecycleListener(LifecycleListener listener) { 1396 1397 lifecycle.removeLifecycleListener(listener); 1398 1399 } 1400 1401 1404 public void initialize() 1405 throws LifecycleException 1406 { 1407 if (initialized) { 1408 log.info(sm.getString("coyoteConnector.alreadyInitialized")); 1409 return; 1410 } 1411 1412 this.initialized = true; 1413 1414 if( oname == null && (container instanceof StandardEngine)) { 1415 try { 1416 StandardEngine cb=(StandardEngine)container; 1418 String encodedAddr = null; 1419 if (getAddress() != null) { 1420 encodedAddr = URLEncoder.encode(getAddress()); 1421 } 1422 String addSuffix=(getAddress()==null) ?"": ",address=" + encodedAddr; 1423 oname=new ObjectName (cb.getName() + ":type=Connector,port="+ 1424 getPort() + addSuffix); 1425 Registry.getRegistry().registerComponent(this, oname, null); 1426 controller=oname; 1427 } catch (Exception e) { 1428 log.error( "Error registering connector ", e); 1429 } 1430 log.debug("Creating name for connector " + oname); 1431 } 1432 1433 1434 if ( adapter == null){ 1441 try { 1442 Class clazz = Class.forName(defaultClassName); 1443 Constructor constructor = 1444 clazz.getConstructor(new Class []{CoyoteConnector.class}); 1445 adapter = 1446 (Adapter)constructor.newInstance(new Object []{this}); 1447 } catch (Exception e) { 1448 throw new LifecycleException 1449 (sm.getString 1450 ("coyoteConnector.apadterClassInstantiationFailed", e)); 1451 } 1452 } 1453 1455 if ( protocolHandler == null ) { 1457 try { 1458 Class clazz = Class.forName(protocolHandlerClassName); 1459 protocolHandler = (ProtocolHandler) clazz.newInstance(); 1460 } catch (Exception e) { 1461 throw new LifecycleException 1462 (sm.getString 1463 ("coyoteConnector.protocolHandlerInstantiationFailed", e)); 1464 } 1465 } 1466 protocolHandler.setAdapter(adapter); 1467 1468 IntrospectionUtils.setProperty(protocolHandler, "jkHome", 1469 System.getProperty("catalina.base")); 1470 1471 if (factory instanceof CoyoteServerSocketFactory) { 1474 IntrospectionUtils.setProperty(protocolHandler, "secure", 1475 "" + true); 1476 CoyoteServerSocketFactory ssf = 1477 (CoyoteServerSocketFactory) factory; 1478 IntrospectionUtils.setProperty(protocolHandler, "algorithm", 1479 ssf.getAlgorithm()); 1480 if (ssf.getClientAuth()) { 1481 IntrospectionUtils.setProperty(protocolHandler, "clientauth", 1482 "" + ssf.getClientAuth()); 1483 } 1484 IntrospectionUtils.setProperty(protocolHandler, "keystore", 1485 ssf.getKeystoreFile()); 1486 IntrospectionUtils.setProperty(protocolHandler, "randomfile", 1487 ssf.getRandomFile()); 1488 IntrospectionUtils.setProperty(protocolHandler, "rootfile", 1489 ssf.getRootFile()); 1490 1491 IntrospectionUtils.setProperty(protocolHandler, "keypass", 1492 ssf.getKeystorePass()); 1493 IntrospectionUtils.setProperty(protocolHandler, "keytype", 1494 ssf.getKeystoreType()); 1495 IntrospectionUtils.setProperty(protocolHandler, "protocol", 1496 ssf.getProtocol()); 1497 IntrospectionUtils.setProperty(protocolHandler, "protocols", 1498 ssf.getProtocols()); 1499 IntrospectionUtils.setProperty(protocolHandler, 1500 "sSLImplementation", 1501 ssf.getSSLImplementation()); 1502 IntrospectionUtils.setProperty(protocolHandler, "ciphers", 1503 ssf.getCiphers()); 1504 IntrospectionUtils.setProperty(protocolHandler, "keyAlias", 1505 ssf.getKeyAlias()); 1506 } else { 1507 IntrospectionUtils.setProperty(protocolHandler, "secure", 1508 "" + secure); 1509 } 1510 1511 1515 Iterator keys = properties.keySet().iterator(); 1516 while( keys.hasNext() ) { 1517 String name = (String )keys.next(); 1518 String value = properties.get(name).toString(); 1519 String trnName = translateAttributeName(name); 1520 IntrospectionUtils.setProperty(protocolHandler, trnName, value); 1521 } 1522 1523 1524 try { 1525 protocolHandler.init(); 1526 } catch (Exception e) { 1527 throw new LifecycleException 1528 (sm.getString 1529 ("coyoteConnector.protocolHandlerInitializationFailed", e)); 1530 } 1531 } 1532 1533 1537 private String translateAttributeName(String name) { 1538 if ("clientAuth".equals(name)) { 1539 return "clientauth"; 1540 } else if ("keystoreFile".equals(name)) { 1541 return "keystore"; 1542 } else if ("randomFile".equals(name)) { 1543 return "randomfile"; 1544 } else if ("rootFile".equals(name)) { 1545 return "rootfile"; 1546 } else if ("keystorePass".equals(name)) { 1547 return "keypass"; 1548 } else if ("keystoreType".equals(name)) { 1549 return "keytype"; 1550 } else if ("sslProtocol".equals(name)) { 1551 return "protocol"; 1552 } else if ("sslProtocols".equals(name)) { 1553 return "protocols"; 1554 } 1555 return name; 1556 } 1557 1558 1559 1564 public void start() throws LifecycleException { 1565 if( !initialized ) 1566 initialize(); 1567 1568 if (started) { 1570 log.info(sm.getString("coyoteConnector.alreadyStarted")); 1571 return; 1572 } 1573 lifecycle.fireLifecycleEvent(START_EVENT, null); 1574 started = true; 1575 1576 if ( this.oname != null ) { 1579 try { 1581 Registry.getRegistry().registerComponent 1582 (protocolHandler, this.domain, "protocolHandler", 1583 "type=protocolHandler,className=" 1584 + protocolHandlerClassName); 1585 } catch (Exception ex) { 1586 log.error(sm.getString 1587 ("coyoteConnector.protocolRegistrationFailed"), ex); 1588 } 1589 } else { 1590 log.info(sm.getString 1591 ("coyoteConnector.cannotRegisterProtocol")); 1592 } 1593 1594 try { 1595 protocolHandler.start(); 1596 } catch (Exception e) { 1597 throw new LifecycleException 1598 (sm.getString 1599 ("coyoteConnector.protocolHandlerStartFailed", e)); 1600 } 1601 1602 if( this.domain != null ) { 1603 mapperListener.setDomain( domain ); 1604 mapperListener.setPort(this.getPort()); 1606 mapperListener.setDefaultHost(this.defaultHost); 1607 mapperListener.init(); 1610 try { 1611 Registry.getRegistry().registerComponent 1612 (mapper, this.domain, "Mapper", 1613 "type=Mapper"); 1614 } catch (Exception ex) { 1615 log.error(sm.getString 1616 ("coyoteConnector.protocolRegistrationFailed"), ex); 1617 } 1618 } 1619 } 1620 1621 1622 1627 public void stop() throws LifecycleException { 1628 1629 if (!started) { 1631 log.error(sm.getString("coyoteConnector.notStarted")); 1632 return; 1633 1634 } 1635 lifecycle.fireLifecycleEvent(STOP_EVENT, null); 1636 started = false; 1637 1638 if ( domain != null){ 1640 try { 1641 Registry.getRegistry().unregisterComponent(new ObjectName (domain,"type", "Mapper")); 1642 Registry.getRegistry().unregisterComponent(new ObjectName (domain 1643 + ":type=protocolHandler,className=" 1644 + protocolHandlerClassName)); 1645 } catch (MalformedObjectNameException e) { 1646 log.info( "Error unregistering mapper ", e); 1647 } 1648 } 1649 1651 try { 1652 protocolHandler.destroy(); 1653 } catch (Exception e) { 1654 throw new LifecycleException 1655 (sm.getString 1656 ("coyoteConnector.protocolHandlerDestroyFailed", e)); 1657 } 1658 1659 } 1660 1661 1663 public boolean getClientAuth() { 1664 boolean ret = false; 1665 1666 String prop = (String ) getProperty("clientauth"); 1667 if (prop != null) { 1668 ret = Boolean.valueOf(prop).booleanValue(); 1669 } else { 1670 ServerSocketFactory factory = this.getFactory(); 1671 if (factory instanceof CoyoteServerSocketFactory) { 1672 ret = ((CoyoteServerSocketFactory)factory).getClientAuth(); 1673 } 1674 } 1675 1676 return ret; 1677 } 1678 1679 public void setClientAuth(boolean clientAuth) { 1680 setProperty("clientauth", String.valueOf(clientAuth)); 1681 ServerSocketFactory factory = this.getFactory(); 1682 if (factory instanceof CoyoteServerSocketFactory) { 1683 ((CoyoteServerSocketFactory)factory).setClientAuth(clientAuth); 1684 } 1685 } 1686 1687 1688 public String getKeystoreFile() { 1689 String ret = (String ) getProperty("keystore"); 1690 if (ret == null) { 1691 ServerSocketFactory factory = this.getFactory(); 1692 if (factory instanceof CoyoteServerSocketFactory) { 1693 ret = ((CoyoteServerSocketFactory)factory).getKeystoreFile(); 1694 } 1695 } 1696 1697 return ret; 1698 } 1699 1700 public void setKeystoreFile(String keystoreFile) { 1701 setProperty("keystore", keystoreFile); 1702 ServerSocketFactory factory = this.getFactory(); 1703 if (factory instanceof CoyoteServerSocketFactory) { 1704 ((CoyoteServerSocketFactory)factory).setKeystoreFile(keystoreFile); 1705 } 1706 } 1707 1708 1711 public String getKeystorePass() { 1712 String ret = (String ) getProperty("keypass"); 1713 if (ret == null) { 1714 ServerSocketFactory factory = getFactory(); 1715 if (factory instanceof CoyoteServerSocketFactory ) { 1716 return ((CoyoteServerSocketFactory)factory).getKeystorePass(); 1717 } 1718 } 1719 1720 return ret; 1721 } 1722 1723 1726 public void setKeystorePass(String keystorePass) { 1727 setProperty("keypass", keystorePass); 1728 ServerSocketFactory factory = getFactory(); 1729 if( factory instanceof CoyoteServerSocketFactory ) { 1730 ((CoyoteServerSocketFactory)factory).setKeystorePass(keystorePass); 1731 } 1732 } 1733 1734 1741 public String getCiphers() { 1742 String ret = (String ) getProperty("ciphers"); 1743 if (ret == null) { 1744 ServerSocketFactory factory = getFactory(); 1745 if (factory instanceof CoyoteServerSocketFactory) { 1746 ret = ((CoyoteServerSocketFactory)factory).getCiphers(); 1747 } 1748 } 1749 1750 return ret; 1751 } 1752 1753 1761 public void setCiphers(String ciphers) { 1762 setProperty("ciphers", ciphers); 1763 ServerSocketFactory factory = getFactory(); 1764 if (factory instanceof CoyoteServerSocketFactory) { 1765 ((CoyoteServerSocketFactory)factory).setCiphers(ciphers); 1766 } 1767 } 1768 1769 1773 public void setSSLSessionTimeout(String timeout) { 1774 setProperty("sslSessionTimeout", timeout); 1775 } 1776 1777 1781 public void setSSL3SessionTimeout(String timeout) { 1782 setProperty("ssl3SessionTimeout", timeout); 1783 } 1784 1785 1788 public void setSSLSessionCacheSize(String cacheSize) { 1789 setProperty("sslSessionCacheSize", cacheSize); 1790 } 1791 1792 1798 public String getKeyAlias() { 1799 String ret = (String ) getProperty("keyAlias"); 1800 if (ret == null) { 1801 ServerSocketFactory factory = getFactory(); 1802 if (factory instanceof CoyoteServerSocketFactory) { 1803 ret = ((CoyoteServerSocketFactory)factory).getKeyAlias(); 1804 } 1805 } 1806 1807 return ret; 1808 } 1809 1810 1817 public void setKeyAlias(String alias) { 1818 setProperty("keyAlias", alias); 1819 ServerSocketFactory factory = getFactory(); 1820 if (factory instanceof CoyoteServerSocketFactory) { 1821 ((CoyoteServerSocketFactory)factory).setKeyAlias(alias); 1822 } 1823 } 1824 1825 1830 public String getSslProtocol() { 1831 String ret = (String ) getProperty("sslProtocol"); 1832 if (ret == null) { 1833 ServerSocketFactory factory = getFactory(); 1834 if (factory instanceof CoyoteServerSocketFactory) { 1835 ret = ((CoyoteServerSocketFactory)factory).getProtocol(); 1836 } 1837 } 1838 1839 return ret; 1840 } 1841 1842 1847 public void setSslProtocol(String sslProtocol) { 1848 setProperty("sslProtocol", sslProtocol); 1849 ServerSocketFactory factory = getFactory(); 1850 if (factory instanceof CoyoteServerSocketFactory) { 1851 ((CoyoteServerSocketFactory)factory).setProtocol(sslProtocol); 1852 } 1853 } 1854 1855 1860 public String getSslProtocols() { 1861 String ret = (String ) getProperty("sslProtocols"); 1862 if (ret == null) { 1863 ServerSocketFactory factory = getFactory(); 1864 if (factory instanceof CoyoteServerSocketFactory) { 1865 ret = ((CoyoteServerSocketFactory)factory).getProtocols(); 1866 } 1867 } 1868 1869 return ret; 1870 } 1871 1872 1877 public void setSslProtocols(String sslProtocols) { 1878 setProperty("sslProtocols", sslProtocols); 1879 ServerSocketFactory factory = getFactory(); 1880 if (factory instanceof CoyoteServerSocketFactory) { 1881 ((CoyoteServerSocketFactory)factory).setProtocols(sslProtocols); 1882 } 1883 } 1884 1885 1889 public X509Certificate [] getCertificates(Request request) { 1890 1891 CoyoteRequest cRequest = null; 1892 if (request instanceof CoyoteRequest) { 1893 cRequest=(CoyoteRequest) request; 1894 } else { 1895 return null; 1896 } 1897 1898 X509Certificate certs[] = (X509Certificate []) 1899 cRequest.getAttribute(Globals.CERTIFICATES_ATTR); 1900 if ((certs == null) || (certs.length < 1)) { 1901 certs = (X509Certificate []) 1902 cRequest.getAttribute(Globals.SSL_CERTIFICATE_ATTR); 1903 } 1904 return certs; 1905 } 1906 1908 1909 protected String domain; 1911 protected ObjectName oname; 1912 protected MBeanServer mserver; 1913 ObjectName controller; 1914 1915 public ObjectName getController() { 1916 return controller; 1917 } 1918 1919 public void setController(ObjectName controller) { 1920 this.controller = controller; 1921 } 1922 1923 public ObjectName getObjectName() { 1924 return oname; 1925 } 1926 1927 public String getDomain() { 1928 return domain; 1929 } 1930 1931 public ObjectName preRegister(MBeanServer server, 1932 ObjectName name) throws Exception { 1933 oname=name; 1934 mserver=server; 1935 domain=name.getDomain(); 1936 return name; 1937 } 1938 1939 public void postRegister(Boolean registrationDone) { 1940 } 1941 1942 public void preDeregister() throws Exception { 1943 } 1944 1945 public void postDeregister() { 1946 try { 1947 if( started ) { 1948 stop(); 1949 } 1950 } catch( Throwable t ) { 1951 log.error( "Unregistering - can't stop", t); 1952 } 1953 } 1954 1955 private void findContainer() { 1956 try { 1957 ObjectName parentName=new ObjectName ( domain + ":" + 1959 "type=Service"); 1960 1961 log.debug("Adding to " + parentName ); 1962 if( mserver.isRegistered(parentName )) { 1963 mserver.invoke(parentName, "addConnector", new Object [] { this }, 1964 new String [] {"org.apache.catalina.Connector"}); 1965 } 1969 ObjectName engName=new ObjectName ( domain + ":" + "type=Engine"); 1972 if( mserver.isRegistered(engName )) { 1973 Object obj=mserver.getAttribute(engName, "managedResource"); 1974 log.debug("Found engine " + obj + " " + obj.getClass()); 1975 container=(Container)obj; 1976 1977 initialize(); 1979 1980 log.debug("Initialized"); 1981 return; 1984 } 1985 } catch( Exception ex ) { 1986 log.error( "Error finding container " + ex); 1987 } 1988 } 1989 1990 public void init() throws Exception { 1991 1992 if( this.getService() != null ) { 1993 log.debug( "Already configured" ); 1994 return; 1995 } 1996 if( container==null ) { 1997 findContainer(); 1998 } 1999 } 2000 2001 public void destroy() throws Exception { 2002 if( oname!=null && controller==oname ) { 2003 log.debug("Unregister itself " + oname ); 2004 Registry.getRegistry().unregisterComponent(oname); 2005 } 2006 if( getService() == null) 2007 return; 2008 getService().removeConnector(this); 2009 } 2010 2011 2012 2016 public void setAdapter(Adapter adapter){ 2017 this.adapter = adapter; 2018 } 2019 2020 2021 2024 public Adapter getAdapter(){ 2025 return adapter; 2026 } 2027 2028 2029 2032 public void setProtocolHandler(ProtocolHandler protocolHandler){ 2033 this.protocolHandler = protocolHandler; 2034 } 2035 2037} 2038 | Popular Tags |