1 45 package org.openejb.webadmin.main; 46 47 import java.io.ByteArrayInputStream ; 48 import java.io.File ; 49 import java.io.FileInputStream ; 50 import java.io.FileOutputStream ; 51 import java.io.FileWriter ; 52 import java.io.IOException ; 53 import java.io.ObjectInputStream ; 54 import java.io.ObjectOutputStream ; 55 import java.io.PrintWriter ; 56 import java.util.Properties ; 57 58 import javax.ejb.Handle ; 59 import javax.naming.Context ; 60 import javax.naming.InitialContext ; 61 import javax.rmi.PortableRemoteObject ; 62 63 import org.exolab.castor.xml.ValidationException; 64 import org.openejb.OpenEJBException; 65 import org.openejb.webadmin.HttpRequest; 66 import org.openejb.webadmin.HttpResponse; 67 import org.openejb.webadmin.WebAdminBean; 68 import org.openejb.alt.config.Bean; 69 import org.openejb.alt.config.ConfigUtils; 70 import org.openejb.alt.config.Service; 71 import org.openejb.alt.config.sys.ConnectionManager; 72 import org.openejb.alt.config.sys.Connector; 73 import org.openejb.alt.config.sys.Container; 74 import org.openejb.alt.config.sys.Deployments; 75 import org.openejb.alt.config.sys.JndiProvider; 76 import org.openejb.alt.config.sys.Openejb; 77 import org.openejb.alt.config.sys.ProxyFactory; 78 import org.openejb.alt.config.sys.Resource; 79 import org.openejb.alt.config.sys.SecurityService; 80 import org.openejb.alt.config.sys.TransactionService; 81 import org.openejb.core.EnvProps; 82 import org.openejb.util.FileUtils; 83 import org.openejb.util.StringUtilities; 84 85 101 public class ConfigBean extends WebAdminBean { 102 103 private static final String HANDLE_FILE = System.getProperty("file.separator") + "configurationHandle.obj"; 104 105 106 public void ejbCreate() { 107 section = "Configuration"; 108 } 109 110 115 public void preProcess(HttpRequest request, HttpResponse response) throws IOException {} 116 117 122 public void postProcess(HttpRequest request, HttpResponse response) throws IOException {} 123 124 129 public void writeHtmlTitle(PrintWriter body) throws IOException { 130 body.print(HTML_TITLE); 131 } 132 133 138 public void writePageTitle(PrintWriter body) throws IOException { 139 body.print("Edit your OpenEJB Configuration"); 140 } 141 142 146 public void writeSubMenuItems(PrintWriter body) throws IOException {} 147 148 152 public void writeBody(PrintWriter body) throws IOException { 153 Openejb openejb; 154 ConfigurationDataObject configurationData; 155 String configLocation = System.getProperty("openejb.configuration"); 156 157 String type = request.getQueryParameter(ConfigHTMLWriter.QUERY_PARAMETER_TYPE); 159 String method = request.getQueryParameter(ConfigHTMLWriter.QUERY_PARAMETER_METHOD); 160 String handleFile = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_HANDLE_FILE); 161 String submitOpenejb = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_SUBMIT_OPENEJB); 162 String submitService = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_SUBMIT_SERVICE); 163 String containerType = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_CONTAINER_TYPE); 164 165 if (handleFile == null) { 168 configurationData = getConfigurationObject(); 169 handleFile = createHandle(configurationData); 170 try { 171 configLocation = ConfigUtils.searchForConfiguration(); 172 173 openejb = ConfigUtils.readConfig(configLocation); 174 } catch (OpenEJBException e) { 175 throw new IOException (e.getMessage()); 176 } 177 } else { 178 configurationData = getHandle(handleFile); 179 openejb = configurationData.getOpenejb(); 180 } 181 182 if (submitOpenejb != null) { 185 body.println(submitOpenejb(configLocation, openejb)); 186 return; 187 } else if (ConfigHTMLWriter.FORM_VALUE_SUBMIT_CONNECTOR.equals(submitService)) { 188 submitConnector(body, openejb, handleFile, configLocation); 189 } else if (containerType != null) { 190 submitContainer(body, openejb, handleFile, configLocation); 191 } else if (ConfigHTMLWriter.FORM_VALUE_SUBMIT_DEPLOYMENTS.equals(submitService)) { 192 submitDeployments(body, openejb, handleFile, configLocation); 193 } else if (submitService != null) { 194 submitService(body, openejb, handleFile, configLocation, submitService); 195 } else if (ConfigHTMLWriter.TYPE_CONNECTOR.equals(type)) { 196 beginConnector(method, handleFile, body, openejb, configLocation); 197 } else if (ConfigHTMLWriter.TYPE_CONTAINER.equals(type)) { 198 beginContainer(method, handleFile, body, openejb, configLocation); 199 } else if (ConfigHTMLWriter.TYPE_DEPLOYMENTS.equals(type)) { 200 beginDeployments(method, handleFile, body, openejb, configLocation); 201 } else if (type != null) { 202 beginService(method, handleFile, body, openejb, configLocation, type); 203 } else { 204 ConfigHTMLWriter.writeOpenejb(body, openejb, handleFile, configLocation); 205 } 206 207 configurationData.setOpenejb(openejb); 209 } 210 211 222 private void beginConnector(String method, String handleFile, PrintWriter body, Openejb openejb, String configLocation) 223 throws IOException { 224 String connectorId = request.getFormParameter(ConfigHTMLWriter.TYPE_CONNECTOR); 225 Connector[] connectors = openejb.getConnector(); 226 int connectorIndex = -1; 227 228 connectorId = (connectorId == null) ? "" : connectorId; 230 for (int i = 0; i < connectors.length; i++) { 231 if (connectorId.equals(connectors[i].getId())) { 232 connectorIndex = i; 233 break; 234 } 235 } 236 237 if (ConfigHTMLWriter.CREATE.equals(method)) { 239 ConfigHTMLWriter.writeConnector(body, null, handleFile, -1); 240 } else if (ConfigHTMLWriter.EDIT.equals(method)) { 241 ConfigHTMLWriter.writeConnector( 242 body, 243 (connectorIndex == -1) ? null : connectors[connectorIndex], 244 handleFile, 245 connectorIndex); 246 } else if (ConfigHTMLWriter.DELETE.equals(method)) { 247 if (connectorIndex > -1) 248 openejb.removeConnector(connectorIndex); 249 ConfigHTMLWriter.writeOpenejb(body, openejb, handleFile, configLocation); 250 } else { 251 throw new IOException ("Invalid method"); 252 } 253 } 254 255 268 private void beginContainer(String method, String handleFile, PrintWriter body, Openejb openejb, String configLocation) 269 throws IOException { 270 String containerId = request.getFormParameter(ConfigHTMLWriter.TYPE_CONTAINER); 271 Container[] containers = openejb.getContainer(); 272 int containerIndex = -1; 273 Properties properties = new Properties (); 274 275 containerId = (containerId == null) ? "" : containerId; 278 for (int i = 0; i < containers.length; i++) { 279 if (containerId.equals(containers[i].getId())) { 280 containerIndex = i; 281 break; 282 } 283 } 284 285 if (ConfigHTMLWriter.CREATE.equals(method)) { 288 ConfigHTMLWriter.writeContainer(body, new ContainerData(), handleFile); 289 } else if (ConfigHTMLWriter.EDIT.equals(method)) { 290 ContainerData data = new ContainerData(); 292 if (containerIndex > -1) { 293 data.setId(StringUtilities.nullToBlankString(containers[containerIndex].getId())); 294 data.setJar(StringUtilities.nullToBlankString(containers[containerIndex].getJar())); 295 data.setProvider(StringUtilities.nullToBlankString(containers[containerIndex].getProvider())); 296 data.setContainerType(StringUtilities.nullToBlankString(containers[containerIndex].getCtype())); 297 ByteArrayInputStream in = 298 new ByteArrayInputStream ( 299 StringUtilities.nullToBlankString(containers[containerIndex].getContent()).getBytes()); 300 properties.load(in); 301 302 data.setBulkPassivate(properties.getProperty(EnvProps.IM_PASSIVATE_SIZE, "")); 303 data.setGlobalTxDatabase(properties.getProperty(EnvProps.GLOBAL_TX_DATABASE, "")); 304 data.setIndex(containerIndex); 305 data.setLocalTxDatabase(properties.getProperty(EnvProps.LOCAL_TX_DATABASE, "")); 306 data.setPassivator(properties.getProperty(EnvProps.IM_PASSIVATOR, "")); 307 data.setPoolSize(properties.getProperty(EnvProps.IM_POOL_SIZE, "")); 308 data.setStrictPooling(properties.getProperty(EnvProps.IM_STRICT_POOLING, "true")); 309 data.setTimeOut(properties.getProperty(EnvProps.IM_TIME_OUT, "")); 310 data.setEdit(true); 311 } 312 313 ConfigHTMLWriter.writeContainer(body, data, handleFile); 314 } else if (ConfigHTMLWriter.DELETE.equals(method)) { 315 if (containerIndex > -1) 316 openejb.removeContainer(containerIndex); 317 ConfigHTMLWriter.writeOpenejb(body, openejb, handleFile, configLocation); 318 } else { 319 throw new IOException ("Invalid method"); 320 } 321 } 322 323 334 private void beginDeployments( 335 String method, 336 String handleFile, 337 PrintWriter body, 338 Openejb openejb, 339 String configLocation) 340 throws IOException { 341 String deploymentId = request.getFormParameter(ConfigHTMLWriter.TYPE_DEPLOYMENTS); 343 Deployments[] deployments = openejb.getDeployments(); 344 int deploymentIndex = -1; 345 346 deploymentId = StringUtilities.nullToBlankString(deploymentId); 348 for (int i = 0; i < deployments.length; i++) { 349 if (deploymentId.equals(deployments[i].getDir()) || deploymentId.equals(deployments[i].getJar())) { 350 deploymentIndex = i; 351 break; 352 } 353 } 354 355 if (ConfigHTMLWriter.CREATE.equals(method)) { 357 ConfigHTMLWriter.writeDeployments(body, null, handleFile, -1); 358 } else if (ConfigHTMLWriter.EDIT.equals(method)) { 359 ConfigHTMLWriter.writeDeployments(body, deployments[deploymentIndex], handleFile, deploymentIndex); 360 } else if (ConfigHTMLWriter.DELETE.equals(method)) { 361 if (deploymentIndex > -1) 362 openejb.removeDeployments(deploymentIndex); 363 ConfigHTMLWriter.writeOpenejb(body, openejb, handleFile, configLocation); 364 } else { 365 throw new IOException ("Invalid method"); 366 } 367 } 368 369 385 private void beginService( 386 String method, 387 String handleFile, 388 PrintWriter body, 389 Openejb openejb, 390 String configLocation, 391 String type) 392 throws IOException { 393 String serviceId = StringUtilities.nullToBlankString(request.getFormParameter(type)); 395 Service service = null; 396 Service[] services = new Service[0]; 397 String submit = ""; 398 399 403 404 if (ConfigHTMLWriter.TYPE_CONNECTION_MANAGER.equals(type)) { 407 service = openejb.getConnectionManager(); 408 submit = ConfigHTMLWriter.FORM_VALUE_SUBMIT_CONNECTION_MANAGER; 409 } else if (ConfigHTMLWriter.TYPE_JNDI_PROVIDER.equals(type)) { 410 services = openejb.getJndiProvider(); 411 submit = ConfigHTMLWriter.FORM_VALUE_SUBMIT_JNDI_PROVIDER; 412 } else if (ConfigHTMLWriter.TYPE_PROXY_FACTORY.equals(type)) { 413 service = openejb.getProxyFactory(); 414 submit = ConfigHTMLWriter.FORM_VALUE_SUBMIT_PROXY_FACTORY; 415 } else if (ConfigHTMLWriter.TYPE_SECURITY_SERVICE.equals(type)) { 416 service = openejb.getSecurityService(); 417 submit = ConfigHTMLWriter.FORM_VALUE_SUBMIT_SECURITY_SERVICE; 418 } else if (ConfigHTMLWriter.TYPE_TRANSACTION_SERVICE.equals(type)) { 419 service = openejb.getTransactionService(); 420 submit = ConfigHTMLWriter.FORM_VALUE_SUBMIT_TRANSACTION_SERVICE; 421 } else if (ConfigHTMLWriter.TYPE_RESOURCE.equals(type)) { 422 services = openejb.getResource(); 423 submit = ConfigHTMLWriter.FORM_VALUE_SUBMIT_RESOURCE; 424 } 425 426 int serviceIndex = -1; 427 428 for (int i = 0; i < services.length; i++) { 430 if (serviceId.equals(services[i].getId())) { 431 serviceIndex = i; 432 service = services[i]; 433 break; 434 } 435 } 436 437 if (ConfigHTMLWriter.CREATE.equals(method)) { 439 ConfigHTMLWriter.writeService(body, null, handleFile, submit, -1); 440 } else if (ConfigHTMLWriter.EDIT.equals(method)) { 441 ConfigHTMLWriter.writeService(body, service, handleFile, submit, serviceIndex); 442 } else if (ConfigHTMLWriter.DELETE.equals(method)) { 443 if (ConfigHTMLWriter.TYPE_CONNECTION_MANAGER.equals(type)) { 446 openejb.setConnectionManager(null); 447 } else if (ConfigHTMLWriter.TYPE_JNDI_PROVIDER.equals(type) && serviceIndex > -1) { 448 openejb.removeJndiProvider(serviceIndex); 449 } else if (ConfigHTMLWriter.TYPE_PROXY_FACTORY.equals(type)) { 450 openejb.setProxyFactory(null); 451 } else if (ConfigHTMLWriter.TYPE_SECURITY_SERVICE.equals(type)) { 452 openejb.setSecurityService(null); 453 } else if (ConfigHTMLWriter.TYPE_TRANSACTION_SERVICE.equals(type)) { 454 openejb.setTransactionService(null); 455 } else if (ConfigHTMLWriter.TYPE_RESOURCE.equals(type) && serviceIndex > -1) { 456 openejb.removeResource(serviceIndex); 457 } 458 ConfigHTMLWriter.writeOpenejb(body, openejb, handleFile, configLocation); 459 } else { 460 throw new IOException ("Invalid method"); 461 } 462 } 463 464 474 private void submitConnector(PrintWriter body, Openejb openejb, String handleFile, String configLocation) throws IOException { 475 Connector connector; 476 477 String id = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_ID).trim(); 479 String jar = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_JAR).trim(); 480 String provider = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_PROVIDER).trim(); 481 String jdbcDriver = request.getFormParameter(EnvProps.JDBC_DRIVER).trim(); 482 String jdbcUrl = request.getFormParameter(EnvProps.JDBC_URL).trim(); 483 String userName = request.getFormParameter(EnvProps.USER_NAME).trim(); 484 String password = request.getFormParameter(EnvProps.PASSWORD).trim(); 485 int index = Integer.parseInt(request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_INDEX).trim()); 486 StringBuffer contentBuffer = new StringBuffer (125); 487 StringBuffer validationError = new StringBuffer (50); 488 489 if (index > -1) { 492 connector = openejb.getConnector(index); 493 } else { 494 connector = new Connector(); 495 } 496 497 if (!"".equals(jdbcDriver)) 499 contentBuffer.append(EnvProps.JDBC_DRIVER).append(" ").append(jdbcDriver).append('\n'); 500 if (!"".equals(jdbcUrl)) 501 contentBuffer.append(EnvProps.JDBC_URL).append(" ").append(jdbcUrl).append('\n'); 502 if (!"".equals(userName)) 503 contentBuffer.append(EnvProps.USER_NAME).append(" ").append(userName).append('\n'); 504 if (!"".equals(password)) 505 contentBuffer.append(EnvProps.PASSWORD).append(" ").append(password).append('\n'); 506 if (!"".equals(id.trim())) 507 connector.setId(id.trim()); 508 if (!"".equals(jar.trim())) 509 connector.setJar(jar); 510 if (!"".equals(provider.trim())) 511 connector.setProvider(provider); 512 513 connector.setContent((contentBuffer.length() > 0) ? contentBuffer.toString() : null); 514 515 try { connector.validate(); 517 } catch (ValidationException e) { 518 body.print("<font color=\"red\">You must fix the following errors before proceeding:<br>\n<b>"); 520 body.print(e.getMessage()); 521 body.print("</b></font>\n<br><br>"); 522 523 ConfigHTMLWriter.writeConnector(body, connector, handleFile, index); 524 return; 525 } 526 527 if (index == -1) { 529 openejb.addConnector(connector); 530 } 531 532 ConfigHTMLWriter.writeOpenejb(body, openejb, handleFile, configLocation); 533 } 534 535 547 private void submitContainer(PrintWriter body, Openejb openejb, String handleFile, String configLocation) 548 throws IOException { 549 ContainerData data = new ContainerData(); 550 int index = Integer.parseInt(request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_INDEX)); 551 String submit = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_SUBMIT_SERVICE); 552 Container container; 553 StringBuffer contentBuffer = new StringBuffer (125); 554 StringBuffer errorBuffer = new StringBuffer (100); 555 556 data.setBulkPassivate( 558 StringUtilities.nullToBlankString(request.getFormParameter(EnvProps.IM_PASSIVATE_SIZE)).trim()); 559 data.setContainerType( 560 StringUtilities.nullToBlankString(request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_CONTAINER_TYPE)).trim()); 561 data.setGlobalTxDatabase( 562 StringUtilities.nullToBlankString(request.getFormParameter(EnvProps.GLOBAL_TX_DATABASE)).trim()); 563 data.setId(StringUtilities.nullToBlankString(request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_ID)).trim()); 564 data.setIndex(index); 565 data.setJar(StringUtilities.nullToBlankString(request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_JAR)).trim()); 566 data.setLocalTxDatabase( 567 StringUtilities.nullToBlankString(request.getFormParameter(EnvProps.LOCAL_TX_DATABASE)).trim()); 568 data.setPassivator(StringUtilities.nullToBlankString(request.getFormParameter(EnvProps.IM_PASSIVATOR)).trim()); 569 data.setPoolSize(StringUtilities.nullToBlankString(request.getFormParameter(EnvProps.IM_POOL_SIZE)).trim()); 570 data.setProvider( 571 StringUtilities.nullToBlankString(request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_PROVIDER)).trim()); 572 data.setStrictPooling( 573 StringUtilities.nullToBlankString(request.getFormParameter(EnvProps.IM_STRICT_POOLING)).trim()); 574 data.setTimeOut(StringUtilities.nullToBlankString(request.getFormParameter(EnvProps.IM_TIME_OUT)).trim()); 575 576 if (ConfigHTMLWriter.FORM_VALUE_SUBMIT_CONTAINER.equals(submit)) { 578 if (index > -1) { 579 container = openejb.getContainer(index); 580 } else { 581 container = new Container(); 582 } 583 584 container.setCtype(data.getContainerType().trim()); 586 if (!"".equals(data.getId().trim())) 587 container.setId(data.getId().trim()); 588 if (!"".equals(data.getJar().trim())) 589 container.setJar(data.getJar().trim()); 590 if ("".equals(data.getProvider().trim())) 591 container.setProvider(data.getProvider().trim()); 592 593 if (Bean.CMP_ENTITY.equals(data.getContainerType())) { 595 if (!"".equals(data.getPoolSize())) 596 contentBuffer.append(EnvProps.IM_POOL_SIZE).append(" ").append(data.getPoolSize()).append('\n'); 597 if (!"".equals(data.getGlobalTxDatabase())) 598 contentBuffer.append(EnvProps.GLOBAL_TX_DATABASE).append(" ").append(data.getGlobalTxDatabase()).append( 599 '\n'); 600 else 601 errorBuffer.append("Global Database File is a required field.<br>\n"); 602 if (!"".equals(data.getLocalTxDatabase())) 603 contentBuffer.append(EnvProps.LOCAL_TX_DATABASE).append(" ").append(data.getLocalTxDatabase()).append( 604 '\n'); 605 else 606 errorBuffer.append("Local Database File is a required field.<br>\n"); 607 } else if (Bean.STATEFUL.equals(data.getContainerType())) { 608 if (!"".equals(data.getPassivator())) 609 contentBuffer.append(EnvProps.IM_PASSIVATOR).append(" ").append(data.getPassivator()).append('\n'); 610 if (!"".equals(data.getTimeOut())) 611 contentBuffer.append(EnvProps.IM_TIME_OUT).append(" ").append(data.getTimeOut()).append('\n'); 612 if (!"".equals(data.getPoolSize())) 613 contentBuffer.append(EnvProps.IM_POOL_SIZE).append(" ").append(data.getPoolSize()).append('\n'); 614 if (!"".equals(data.getBulkPassivate())) 615 contentBuffer.append(EnvProps.IM_PASSIVATE_SIZE).append(" ").append(data.getBulkPassivate()).append( 616 '\n'); 617 } else if (Bean.STATELESS.equals(data.getContainerType())) { 618 if (!"".equals(data.getTimeOut())) 619 contentBuffer.append(EnvProps.IM_TIME_OUT).append(" ").append(data.getTimeOut()).append('\n'); 620 if (!"".equals(data.getPoolSize())) 621 contentBuffer.append(EnvProps.IM_POOL_SIZE).append(" ").append(data.getPoolSize()).append('\n'); 622 if (!"".equals(data.getStrictPooling())) 623 contentBuffer.append(EnvProps.IM_STRICT_POOLING).append(" ").append(data.getStrictPooling()).append( 624 '\n'); 625 626 container.setContent((contentBuffer.length() > 0) ? contentBuffer.toString() : null); 627 } 628 629 try { container.validate(); 631 } catch (ValidationException e) { 632 errorBuffer.insert(0, e.getMessage() + "<br>"); 633 } 634 635 if (errorBuffer.length() > 0) { 637 errorBuffer.insert(0, "<font color=\"red\">You must fix the following errors: <br><b>").append( 638 "</b></font><br>"); 639 body.println(errorBuffer.toString()); 640 ConfigHTMLWriter.writeContainer(body, data, handleFile); 641 return; 642 } 643 644 ConfigHTMLWriter.writeOpenejb(body, openejb, handleFile, configLocation); 645 } else { 646 ConfigHTMLWriter.writeContainer(body, data, handleFile); 648 } 649 } 650 651 660 private void submitDeployments(PrintWriter body, Openejb openejb, String handleFile, String configLocation) { 661 String deploymentType = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_DEPLOYMENT_TYPE); 662 String deploymentText = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_DEPLOYMENT_TEXT); 663 int index = Integer.parseInt(request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_INDEX)); 664 Deployments deployments; 665 666 if (index > -1) { 668 deployments = openejb.getDeployments(index); 669 } else { 670 deployments = new Deployments(); 671 openejb.addDeployments(deployments); 672 } 673 674 if (ConfigHTMLWriter.DEPLOYMENT_TYPE_DIR.equals(deploymentType.trim())) { 676 deployments.setDir(deploymentText.trim()); 677 } else { 678 deployments.setJar(deploymentText.trim()); 679 } 680 681 ConfigHTMLWriter.writeOpenejb(body, openejb, handleFile, configLocation); 682 } 683 684 696 private void submitService( 697 PrintWriter body, 698 Openejb openejb, 699 String handleFile, 700 String configLocation, 701 String submit) 702 throws IOException { 703 String id = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_ID); 704 String jar = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_JAR); 705 String provider = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_PROVIDER); 706 String content = request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_CONTENT); 707 int index = Integer.parseInt(request.getFormParameter(ConfigHTMLWriter.FORM_FIELD_INDEX)); 708 Service service = null; 709 710 if (ConfigHTMLWriter.FORM_VALUE_SUBMIT_CONNECTION_MANAGER.equals(submit)) { 712 if (openejb.getConnectionManager() == null) { 713 service = new ConnectionManager(); 714 openejb.setConnectionManager((ConnectionManager) service); 715 } else { 716 service = openejb.getConnectionManager(); 717 } 718 } else if (ConfigHTMLWriter.FORM_VALUE_SUBMIT_PROXY_FACTORY.equals(submit)) { 719 if (openejb.getProxyFactory() == null) { 720 service = new ProxyFactory(); 721 openejb.setProxyFactory((ProxyFactory) service); 722 } else { 723 service = openejb.getProxyFactory(); 724 } 725 } else if (ConfigHTMLWriter.FORM_VALUE_SUBMIT_SECURITY_SERVICE.equals(submit)) { 726 if (openejb.getSecurityService() == null) { 727 service = new SecurityService(); 728 openejb.setSecurityService((SecurityService) service); 729 } else { 730 service = openejb.getSecurityService(); 731 } 732 } else if (ConfigHTMLWriter.FORM_VALUE_SUBMIT_TRANSACTION_SERVICE.equals(submit)) { 733 if (openejb.getTransactionService() == null) { 734 service = new TransactionService(); 735 openejb.setTransactionService((TransactionService) service); 736 } else { 737 service = openejb.getTransactionService(); 738 } 739 } else if (ConfigHTMLWriter.FORM_VALUE_SUBMIT_JNDI_PROVIDER.equals(submit)) { 740 if (index > -1) { 741 service = openejb.getJndiProvider(index); 742 } else { 743 service = new JndiProvider(); 744 } 745 } else if (ConfigHTMLWriter.FORM_VALUE_SUBMIT_RESOURCE.equals(submit)) { 746 if (index > -1) { 747 service = openejb.getResource(index); 748 } else { 749 service = new Resource(); 750 } 751 } else { 752 throw new IOException ("Invalid Service type"); 753 } 754 755 if (!"".equals(content.trim())) { 757 service.setContent(content.trim()); 758 } 759 if (!"".equals(id.trim())) { 760 service.setId(id.trim()); 761 } 762 if (!"".equals(jar.trim())) { 763 service.setJar(jar.trim()); 764 } 765 if (!"".equals(provider.trim())) { 766 service.setProvider(provider.trim()); 767 } 768 769 try { service.validate(); 771 } catch (ValidationException e) { 772 body.print("<font color=\"red\">You must fix the following errors before continuing.<br>\n<b>"); 774 body.print(e.getMessage()); 775 body.println("</b></font><br><br>"); 776 ConfigHTMLWriter.writeService(body, service, handleFile, submit, index); 777 return; 778 } 779 780 if (ConfigHTMLWriter.FORM_VALUE_SUBMIT_JNDI_PROVIDER.equals(submit)) { 782 if (index == -1) 783 openejb.addJndiProvider((JndiProvider) service); 784 } else if (ConfigHTMLWriter.FORM_VALUE_SUBMIT_RESOURCE.equals(submit)) { 785 if (index == -1) 786 openejb.addResource((Resource) service); 787 } 788 789 ConfigHTMLWriter.writeOpenejb(body, openejb, handleFile, configLocation); 790 } 791 792 800 private String submitOpenejb(String configLocation, Openejb openejb) throws IOException { 801 FileWriter writer = new FileWriter (configLocation); 802 803 try { 804 openejb.marshal(writer); 805 } catch (Exception e) { 806 throw new IOException (e.getMessage()); 807 } 808 809 return "Your changes were written to: " + configLocation; 810 } 811 812 819 private String createHandle(ConfigurationDataObject configurationData) throws IOException { 820 File myHandleFile = new File (FileUtils.createTempDirectory().getAbsolutePath() + HANDLE_FILE); 822 if (!myHandleFile.exists()) { 823 myHandleFile.createNewFile(); 824 } 825 826 ObjectOutputStream objectOut = new ObjectOutputStream (new FileOutputStream (myHandleFile)); 827 objectOut.writeObject(configurationData.getHandle()); objectOut.flush(); 829 objectOut.close(); 830 831 return myHandleFile.getAbsolutePath(); 832 } 833 834 840 private ConfigurationDataObject getConfigurationObject() throws IOException { 841 Properties p = new Properties (); 842 p.put(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.core.ivm.naming.InitContextFactory"); 843 844 try { 846 InitialContext ctx = new InitialContext (p); 847 Object obj = ctx.lookup("config/webadmin/ConfigurationData"); 848 ConfigurationDataHome home = 850 (ConfigurationDataHome) PortableRemoteObject.narrow(obj, ConfigurationDataHome.class); 851 return home.create(); 852 } catch (Exception e) { 853 throw new IOException (e.getMessage()); 854 } 855 } 856 857 864 private ConfigurationDataObject getHandle(String handleFile) throws IOException { 865 File myHandleFile = new File (handleFile); 866 867 ObjectInputStream objectIn = new ObjectInputStream (new FileInputStream (myHandleFile)); 869 Handle configurationHandle; 871 try { 872 configurationHandle = (Handle ) objectIn.readObject(); 873 return (ConfigurationDataObject) configurationHandle.getEJBObject(); 874 } catch (Exception e) { 875 throw new IOException (e.getMessage()); 876 } 877 } 878 } | Popular Tags |