1 25 26 package org.objectweb.jonas.jonasadmin.test.catalina; 27 28 import java.io.IOException ; 29 import java.net.ServerSocket ; 30 31 import org.xml.sax.SAXException ; 32 33 import com.meterware.httpunit.SubmitButton; 34 import com.meterware.httpunit.WebConversation; 35 import com.meterware.httpunit.WebForm; 36 import com.meterware.httpunit.WebLink; 37 import com.meterware.httpunit.WebResponse; 38 39 44 public class ConnectorUtils { 45 46 49 protected static final String FRAME_CONTENT = "content"; 50 51 54 protected static final String FRAME_TREE = "tree"; 55 56 59 private static final String URL_JONASADMIN_CATALINA_CONNECTOR = "ListCatalinaConnectors.do"; 60 61 64 private static final String URL_JONASADMIN_CREATE_CATALINA_CONNECTOR = "CreateCatalinaConnector.do"; 65 66 72 public static String createNewConnector(WebConversation wc) throws Exception { 73 return createNewConnector(wc, "http"); 75 } 76 77 84 public static String createNewConnector(WebConversation wc, String protocol) throws Exception { 85 WebResponse wr = null; 86 WebLink link = null; 87 WebForm form = null; 88 String portText = null; 89 90 wr = getConnectorPage(wc); 92 93 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_CREATE_CATALINA_CONNECTOR + "?type=" 95 + protocol); 96 link.click(); 97 wr = wc.getFrameContents(FRAME_CONTENT); 98 99 portText = "" + findPort(); 100 101 if (protocol.equals("http")) { 102 103 form = wr.getForms()[0]; 104 String maxSpareThreadsText = form.getParameterValue("maxSpareThreadsText"); 105 String URIEncoding = form.getParameterValue("URIEncoding"); 106 String minSpareThreadsText = form.getParameterValue("minSpareThreadsText"); 107 String address = form.getParameterValue("address"); 108 String tcpNoDelay = form.getParameterValue("tcpNoDelay"); 109 String maxThreadsText = form.getParameterValue("maxThreadsText"); 110 String xpoweredBy = form.getParameterValue("xpoweredBy"); 111 String connectorType = form.getParameterValue("connectorType"); 112 String objectName = form.getParameterValue("objectName"); 113 String secure = form.getParameterValue("secure"); 114 String action = form.getParameterValue("action"); 115 String save = form.getParameterValue("save"); 116 String emptySessionPath = form.getParameterValue("emptySessionPath"); 117 String acceptCountText = form.getParameterValue("acceptCountText"); 118 String bufferSizeText = form.getParameterValue("bufferSizeText"); 119 String proxyName = form.getParameterValue("proxyName"); 120 String useBodyEncodingForURI = form.getParameterValue("useBodyEncodingForURI"); 121 String connTimeOutText = form.getParameterValue("connTimeOutText"); 122 String debugLvl = form.getParameterValue("debugLvl"); 123 String redirectPortText = form.getParameterValue("redirectPortText"); 124 String enableLookups = form.getParameterValue("enableLookups"); 125 String allowTrace = form.getParameterValue("allowTrace"); 126 String maxProcessorsText = form.getParameterValue("maxProcessorsText"); 127 String minProcessorsText = form.getParameterValue("minProcessorsText"); 128 String proxyPortText = form.getParameterValue("proxyPortText"); 129 String maxPostSizeText = form.getParameterValue("maxPostSizeText"); 130 131 createNewHttpConnector(form, maxSpareThreadsText, URIEncoding, portText, minSpareThreadsText, address, 132 tcpNoDelay, maxThreadsText, xpoweredBy, connectorType, objectName, secure, action, save, 133 emptySessionPath, acceptCountText, bufferSizeText, proxyName, useBodyEncodingForURI, 134 connTimeOutText, debugLvl, redirectPortText, enableLookups, allowTrace, maxProcessorsText, 135 minProcessorsText, proxyPortText, maxPostSizeText); 136 } else if (protocol.equals("https")) { 137 form = wr.getForms()[0]; 138 String maxSpareThreadsText = form.getParameterValue("maxSpareThreadsText"); 139 String keystorePass = form.getParameterValue("keystorePass"); 140 String URIEncoding = form.getParameterValue("URIEncoding"); 141 String minSpareThreadsText = form.getParameterValue("minSpareThreadsText"); 142 String address = form.getParameterValue("address"); 143 String keystoreType = form.getParameterValue("keystoreType"); 144 String algorithm = form.getParameterValue("algorithm"); 145 String tcpNoDelay = form.getParameterValue("tcpNoDelay"); 146 String maxThreadsText = form.getParameterValue("maxThreadsText"); 147 String xpoweredBy = form.getParameterValue("xpoweredBy"); 148 String connectorType = form.getParameterValue("connectorType"); 149 String sslProtocol = form.getParameterValue("sslProtocol"); 150 String objectName = form.getParameterValue("objectName"); 151 String secure = form.getParameterValue("secure"); 152 String action = form.getParameterValue("action"); 153 String save = form.getParameterValue("save"); 154 String emptySessionPath = form.getParameterValue("emptySessionPath"); 155 String keystoreFile = form.getParameterValue("keystoreFile"); 156 String acceptCountText = form.getParameterValue("acceptCountText"); 157 String bufferSizeText = form.getParameterValue("bufferSizeText"); 158 String proxyName = form.getParameterValue("proxyName"); 159 String useBodyEncodingForURI = form.getParameterValue("useBodyEncodingForURI"); 160 String connTimeOutText = form.getParameterValue("connTimeOutText"); 161 String debugLvl = form.getParameterValue("debugLvl"); 162 String redirectPortText = form.getParameterValue("redirectPortText"); 163 String enableLookups = form.getParameterValue("enableLookups"); 164 String clientAuth = form.getParameterValue("clientAuth"); 165 String allowTrace = form.getParameterValue("allowTrace"); 166 String maxProcessorsText = form.getParameterValue("maxProcessorsText"); 167 String minProcessorsText = form.getParameterValue("minProcessorsText"); 168 String ciphers = form.getParameterValue("ciphers"); 169 String proxyPortText = form.getParameterValue("proxyPortText"); 170 String maxPostSizeText = form.getParameterValue("maxPostSizeText"); 171 172 createNewHttpsConnector(form, maxSpareThreadsText, keystorePass, URIEncoding, portText, 173 minSpareThreadsText, address, keystoreType, algorithm, tcpNoDelay, maxThreadsText, xpoweredBy, 174 connectorType, sslProtocol, objectName, secure, action, save, emptySessionPath, keystoreFile, 175 acceptCountText, bufferSizeText, proxyName, useBodyEncodingForURI, connTimeOutText, debugLvl, 176 redirectPortText, enableLookups, clientAuth, allowTrace, maxProcessorsText, minProcessorsText, 177 ciphers, proxyPortText, maxPostSizeText); 178 } else if (protocol.equals("ajp")) { 179 form = wr.getForms()[0]; 180 String maxSpareThreadsText = form.getParameterValue("maxSpareThreadsText"); 181 String URIEncoding = form.getParameterValue("URIEncoding"); 182 String minSpareThreadsText = form.getParameterValue("minSpareThreadsText"); 183 String address = form.getParameterValue("address"); 184 String tcpNoDelay = form.getParameterValue("tcpNoDelay"); 185 String maxThreadsText = form.getParameterValue("maxThreadsText"); 186 String xpoweredBy = form.getParameterValue("xpoweredBy"); 187 String connectorType = form.getParameterValue("connectorType"); 188 String objectName = form.getParameterValue("objectName"); 189 String secure = form.getParameterValue("secure"); 190 String action = form.getParameterValue("action"); 191 String save = form.getParameterValue("save"); 192 String emptySessionPath = form.getParameterValue("emptySessionPath"); 193 String acceptCountText = form.getParameterValue("acceptCountText"); 194 String bufferSizeText = form.getParameterValue("bufferSizeText"); 195 String useBodyEncodingForURI = form.getParameterValue("useBodyEncodingForURI"); 196 String connTimeOutText = form.getParameterValue("connTimeOutText"); 197 String debugLvl = form.getParameterValue("debugLvl"); 198 String redirectPortText = form.getParameterValue("redirectPortText"); 199 String enableLookups = form.getParameterValue("enableLookups"); 200 String allowTrace = form.getParameterValue("allowTrace"); 201 String maxProcessorsText = form.getParameterValue("maxProcessorsText"); 202 String minProcessorsText = form.getParameterValue("minProcessorsText"); 203 String maxPostSizeText = form.getParameterValue("maxPostSizeText"); 204 205 createNewAjpConnector(form, maxSpareThreadsText, URIEncoding, portText, minSpareThreadsText, address, 206 tcpNoDelay, maxThreadsText, xpoweredBy, connectorType, objectName, secure, action, save, 207 emptySessionPath, acceptCountText, bufferSizeText, useBodyEncodingForURI, connTimeOutText, 208 debugLvl, redirectPortText, enableLookups, allowTrace, maxProcessorsText, minProcessorsText, 209 maxPostSizeText); 210 } 211 return portText; 212 } 213 214 221 public static WebResponse getConnectorPage(WebConversation wc) throws SAXException , IOException { 222 WebResponse wr; 224 WebLink link; 225 226 wr = wc.getFrameContents(FRAME_TREE); 227 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_CATALINA_CONNECTOR); 228 if (link == null) { 229 throw new IllegalStateException ("No link found for link : '" + URL_JONASADMIN_CATALINA_CONNECTOR + "'."); 230 } 231 link.click(); 232 233 wr = wc.getFrameContents(FRAME_CONTENT); 234 return wr; 235 } 236 237 242 private static int findPort() throws Exception { 243 int port = 0; 244 245 ServerSocket ss; 246 ss = new ServerSocket (port); port = ss.getLocalPort(); 248 ss.close(); 249 return port; 250 } 251 252 284 public static void createNewHttpConnector(WebForm form, String maxSpareThreadsText, String URIEncoding, 285 String portText, String minSpareThreadsText, String address, String tcpNoDelay, String maxThreadsText, 286 String xpoweredBy, String connectorType, String objectName, String secure, String action, String save, 287 String emptySessionPath, String acceptCountText, String bufferSizeText, String proxyName, 288 String useBodyEncodingForURI, String connTimeOutText, String debugLvl, String redirectPortText, 289 String enableLookups, String allowTrace, String maxProcessorsText, String minProcessorsText, 290 String proxyPortText, String maxPostSizeText) throws Exception { 291 292 SubmitButton button = null; 293 294 form.setParameter("maxSpareThreadsText", maxSpareThreadsText); 295 form.setParameter("URIEncoding", URIEncoding); 296 form.setParameter("portText", portText); 297 form.setParameter("minSpareThreadsText", minSpareThreadsText); 298 form.setParameter("address", address); 299 form.setParameter("tcpNoDelay", tcpNoDelay); 300 form.setParameter("maxThreadsText", maxThreadsText); 301 form.setParameter("xpoweredBy", xpoweredBy); 302 form.setParameter("connectorType", connectorType); 303 form.setParameter("objectName", objectName); 304 form.setParameter("secure", secure); 305 form.setParameter("action", action); 306 form.setParameter("save", save); 307 form.setParameter("emptySessionPath", emptySessionPath); 308 form.setParameter("acceptCountText", acceptCountText); 309 form.setParameter("bufferSizeText", bufferSizeText); 310 form.setParameter("proxyName", proxyName); 311 form.setParameter("useBodyEncodingForURI", useBodyEncodingForURI); 312 form.setParameter("connTimeOutText", connTimeOutText); 313 form.setParameter("debugLvl", debugLvl); 314 form.setParameter("redirectPortText", redirectPortText); 315 form.setParameter("enableLookups", enableLookups); 316 form.setParameter("allowTrace", allowTrace); 317 form.setParameter("maxProcessorsText", maxProcessorsText); 318 form.setParameter("minProcessorsText", minProcessorsText); 319 form.setParameter("proxyPortText", proxyPortText); 320 form.setParameter("maxPostSizeText", maxPostSizeText); 321 322 button = form.getSubmitButton("btn_apply"); 323 button.click(); 324 } 325 326 365 public static void createNewHttpsConnector(WebForm form, String maxSpareThreadsText, String keystorePass, 366 String URIEncoding, String portText, String minSpareThreadsText, String address, String keystoreType, 367 String algorithm, String tcpNoDelay, String maxThreadsText, String xpoweredBy, String connectorType, 368 String sslProtocol, String objectName, String secure, String action, String save, String emptySessionPath, 369 String keystoreFile, String acceptCountText, String bufferSizeText, String proxyName, 370 String useBodyEncodingForURI, String connTimeOutText, String debugLvl, String redirectPortText, 371 String enableLookups, String clientAuth, String allowTrace, String maxProcessorsText, 372 String minProcessorsText, String ciphers, String proxyPortText, String maxPostSizeText) throws Exception { 373 374 SubmitButton button = null; 375 376 form.setParameter("maxSpareThreadsText", maxSpareThreadsText); 377 form.setParameter("keystorePass", keystorePass); 378 form.setParameter("URIEncoding", URIEncoding); 379 form.setParameter("portText", portText); 380 form.setParameter("minSpareThreadsText", minSpareThreadsText); 381 form.setParameter("address", address); 382 form.setParameter("keystoreType", keystoreType); 383 form.setParameter("algorithm", algorithm); 384 form.setParameter("tcpNoDelay", tcpNoDelay); 385 form.setParameter("maxThreadsText", maxThreadsText); 386 form.setParameter("xpoweredBy", xpoweredBy); 387 form.setParameter("connectorType", connectorType); 388 form.setParameter("sslProtocol", sslProtocol); 389 form.setParameter("objectName", objectName); 390 form.setParameter("secure", secure); 391 form.setParameter("action", action); 392 form.setParameter("save", save); 393 form.setParameter("emptySessionPath", emptySessionPath); 394 form.setParameter("keystoreFile", keystoreFile); 395 form.setParameter("acceptCountText", acceptCountText); 396 form.setParameter("bufferSizeText", bufferSizeText); 397 form.setParameter("proxyName", proxyName); 398 form.setParameter("useBodyEncodingForURI", useBodyEncodingForURI); 399 form.setParameter("connTimeOutText", connTimeOutText); 400 form.setParameter("debugLvl", debugLvl); 401 form.setParameter("redirectPortText", redirectPortText); 402 form.setParameter("enableLookups", enableLookups); 403 form.setParameter("clientAuth", clientAuth); 404 form.setParameter("allowTrace", allowTrace); 405 form.setParameter("maxProcessorsText", maxProcessorsText); 406 form.setParameter("minProcessorsText", minProcessorsText); 407 form.setParameter("ciphers", ciphers); 408 form.setParameter("proxyPortText", proxyPortText); 409 form.setParameter("maxPostSizeText", maxPostSizeText); 410 411 button = form.getSubmitButton("btn_apply"); 412 button.click(); 413 } 414 415 445 public static void createNewAjpConnector(WebForm form, String maxSpareThreadsText, String URIEncoding, 446 String portText, String minSpareThreadsText, String address, String tcpNoDelay, String maxThreadsText, 447 String xpoweredBy, String connectorType, String objectName, String secure, String action, String save, 448 String emptySessionPath, String acceptCountText, String bufferSizeText, String useBodyEncodingForURI, 449 String connTimeOutText, String debugLvl, String redirectPortText, String enableLookups, String allowTrace, 450 String maxProcessorsText, String minProcessorsText, String maxPostSizeText) throws Exception { 451 452 SubmitButton button = null; 453 454 form.setParameter("maxSpareThreadsText", maxSpareThreadsText); 455 form.setParameter("URIEncoding", URIEncoding); 456 form.setParameter("portText", portText); 457 form.setParameter("minSpareThreadsText", minSpareThreadsText); 458 form.setParameter("address", address); 459 form.setParameter("tcpNoDelay", tcpNoDelay); 460 form.setParameter("maxThreadsText", maxThreadsText); 461 form.setParameter("xpoweredBy", xpoweredBy); 462 form.setParameter("connectorType", connectorType); 463 form.setParameter("objectName", objectName); 464 form.setParameter("secure", secure); 465 form.setParameter("action", action); 466 form.setParameter("save", save); 467 form.setParameter("emptySessionPath", emptySessionPath); 468 form.setParameter("acceptCountText", acceptCountText); 469 form.setParameter("bufferSizeText", bufferSizeText); 470 form.setParameter("useBodyEncodingForURI", useBodyEncodingForURI); 471 form.setParameter("connTimeOutText", connTimeOutText); 472 form.setParameter("debugLvl", debugLvl); 473 form.setParameter("redirectPortText", redirectPortText); 474 form.setParameter("enableLookups", enableLookups); 475 form.setParameter("allowTrace", allowTrace); 476 form.setParameter("maxProcessorsText", maxProcessorsText); 477 form.setParameter("minProcessorsText", minProcessorsText); 478 form.setParameter("maxPostSizeText", maxPostSizeText); 479 480 button = form.getSubmitButton("btn_apply"); 481 button.click(); 482 } 483 484 490 public static void deleteConnector(WebConversation wc, String port) throws Exception { 491 String [] tabPort = {port}; 492 deleteConnectors(wc, tabPort); 493 } 494 495 501 public static void deleteConnectors(WebConversation wc, String [] tabPort) throws Exception { 502 WebResponse wr = null; 503 WebForm form = null; 504 WebLink link = null; 505 SubmitButton button = null; 506 507 String action = ""; 508 509 wr = getConnectorPage(wc); 510 511 form = wr.getForms()[0]; 513 action = form.getParameterValue("action"); 514 for (int i = 0; i < tabPort.length; i++) { 515 form.setCheckbox("selectedItems", "jonas:type=Connector,port=" + tabPort[i], true); 516 } 517 518 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "remove"); 520 link.click(); 521 wr = wc.getFrameContents(FRAME_CONTENT); 522 523 form = wr.getForms()[0]; 525 button = form.getSubmitButton("btnSubmit"); 526 button.click(); 527 } 528 529 547 public static void modifyHttpConnector(WebForm form, String acceptCountText, String maxPostSizeText, 548 String connTimeOutText, String URIEncoding, String bufferSizeText, String address, String redirectPortText, 549 String maxThreadsText, String minSpareThreadsText, String maxSpareThreadsText, String proxyName, 550 String proxyPortText, String allowTrace, String emptySessionPath, String enableLookups, 551 String useBodyEncodingForURI, String xpoweredBy, String tcpNoDelay, String debugLvl) throws Exception { 552 553 SubmitButton button = null; 554 555 String objectName = null; 556 String action = null; 557 String save = null; 558 String connectorType = null; 559 String portText = null; 560 561 objectName = form.getParameterValue("objectName"); 563 action = form.getParameterValue("action"); 564 save = form.getParameterValue("save"); 565 connectorType = form.getParameterValue("connectorType"); 566 portText = form.getParameterValue("portText"); 567 568 form.setParameter("objectName", objectName); 569 form.setParameter("action", action); 570 form.setParameter("save", save); 571 form.setParameter("connectorType", connectorType); 572 form.setParameter("portText", portText); 573 form.setParameter("acceptCountText", acceptCountText); 574 form.setParameter("maxPostSizeText", maxPostSizeText); 575 form.setParameter("connTimeOutText", connTimeOutText); 576 form.setParameter("URIEncoding", URIEncoding); 577 form.setParameter("bufferSizeText", bufferSizeText); 578 form.setParameter("address", address); 579 form.setParameter("redirectPortText", redirectPortText); 580 form.setParameter("maxThreadsText", maxThreadsText); 581 form.setParameter("minSpareThreadsText", minSpareThreadsText); 582 form.setParameter("maxSpareThreadsText", maxSpareThreadsText); 583 form.setParameter("proxyName", proxyName); 584 form.setParameter("proxyPortText", proxyPortText); 585 form.setParameter("allowTrace", allowTrace); 586 form.setParameter("emptySessionPath", emptySessionPath); 587 form.setParameter("enableLookups", enableLookups); 588 form.setParameter("useBodyEncodingForURI", useBodyEncodingForURI); 589 form.setParameter("xpoweredBy", xpoweredBy); 590 form.setParameter("tcpNoDelay", tcpNoDelay); 591 form.setParameter("debugLvl", debugLvl); 592 593 button = form.getSubmitButton("btn_apply"); 594 button.click(); 595 } 596 } 597 | Popular Tags |