1 25 26 package org.objectweb.j2eemanagement.servlets; 27 28 import java.io.IOException ; 30 import java.io.PrintWriter ; 31 import java.net.MalformedURLException ; 32 import java.rmi.RemoteException ; 33 import java.util.List ; 34 35 import javax.management.AttributeNotFoundException ; 36 import javax.management.InstanceNotFoundException ; 37 import javax.management.MBeanException ; 38 import javax.management.MBeanServerConnection ; 39 import javax.management.ObjectName ; 40 import javax.management.ReflectionException ; 41 import javax.management.j2ee.ListenerRegistration ; 42 import javax.management.j2ee.Management ; 43 import javax.management.j2ee.ManagementHome ; 44 import javax.management.remote.JMXConnector ; 45 import javax.management.remote.JMXConnectorFactory ; 46 import javax.management.remote.JMXServiceURL ; 47 import javax.naming.Context ; 48 import javax.naming.InitialContext ; 49 import javax.rmi.PortableRemoteObject ; 50 import javax.servlet.ServletConfig ; 51 import javax.servlet.ServletException ; 52 import javax.servlet.http.HttpServlet ; 53 import javax.servlet.http.HttpServletRequest ; 54 import javax.servlet.http.HttpServletResponse ; 55 56 import org.objectweb.jonas.mejb.DomainManagement; 57 import org.objectweb.jonas.mejb.DomainManagementHome; 58 59 65 public class MgmtServlet extends HttpServlet { 66 67 69 static final String APP_TITLE_LARGE = "J2EE Management sample with Servlet accessing the MEJB"; 70 71 static final String APP_TITLE = "J2EE Management sample"; 72 73 static final String PARAM_DOMAIN = "domainName"; 74 75 static final String PARAM_VIEW = "view"; 76 77 static final String VIEW_INIT = "init"; 78 79 static final String VIEW_NOTIFICATIONS = "notifications"; 80 81 static final String VIEW_OTHER = "other"; 82 83 static final String JAR = "jar"; 84 85 static final String WAR = "war"; 86 87 static final String RAR = "rar"; 88 89 static final String EAR = "ear"; 90 93 private MyListener mListener = null; 94 95 97 102 public void init(ServletConfig pConfig) throws ServletException { 103 super.init(pConfig); 104 mListener = null; 106 } 107 108 111 118 protected void doGet(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException , 119 ServletException { 120 dispatch(pRequest, pResponse); 121 } 122 123 130 protected void doPost(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException , 131 ServletException { 132 dispatch(pRequest, pResponse); 133 } 134 135 141 protected void dispatch(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException { 142 143 pResponse.setContentType("text/html"); 144 PrintWriter out = pResponse.getWriter(); 145 146 String sParamDomain = pRequest.getParameter(PARAM_DOMAIN); 148 String sParamView = pRequest.getParameter(PARAM_VIEW); 149 150 if ((sParamDomain == null) || (sParamDomain.length() == 0)) { 152 doViewError("Parameter domain not found", pRequest, out); 153 } else if ((sParamView == null) || (sParamView.length() == 0) || VIEW_INIT.equals(sParamView)) { 154 doViewInit(sParamDomain, pRequest, out); 155 } else if (VIEW_NOTIFICATIONS.equals(sParamView)) { 156 doViewNotifications(out); 157 } else if (VIEW_OTHER.equals(sParamView)) { 158 doViewOther(sParamDomain, pRequest, out); 159 } else { 160 doViewError("Unknown View", pRequest, out); 161 } 162 163 } 164 165 171 protected void printHeader(PrintWriter pOut, String pTitle, String pSubTitle) { 172 173 pOut.println("<html>"); 174 pOut.println("<head>"); 175 pOut.println("<title>" + pTitle); 176 if (pSubTitle != null) { 177 pOut.println(" - " + pSubTitle); 178 } 179 pOut.println("</title>"); 180 pOut.println("</head>"); 181 pOut.println("<body style=\"background : white; color : black;\">"); 182 printHeaderTitle(pOut, pTitle, pSubTitle); 183 } 184 185 191 protected void printHeaderAutoRefresh(PrintWriter pOut, String pTitle, String pSubTitle) { 192 193 pOut.println("<html>"); 194 pOut.println("<head>"); 195 pOut.println("<title>" + pTitle + "</title>"); 196 pOut.println("<script language=\"JavaScript\">"); 197 pOut.println("function startRefresh(){ setTimeout(\"refresh()\",30000); self.focus(); }"); 198 pOut.println("function refresh(){ window.location.reload(); }"); 199 pOut.println("</script>"); 200 pOut.println("</head>"); 201 pOut.println("<body onload=\"startRefresh()\" style=\"background : white; color : black;\">"); 202 printHeaderTitle(pOut, pTitle, pSubTitle); 203 } 204 205 211 protected void printHeaderTitle(PrintWriter pOut, String pTitle, String pSubTitle) { 212 213 pOut.println("<table width=\"100%\" border=\"0\">"); 214 pOut.println("<tr>"); 215 pOut.println("<td rowspan=\"2\"><img SRC=\"img/logo_jonas.jpg\" alt=\"JOnAS Logo\"></td>"); 216 pOut.println("<td align=\"center\"><h1>" + pTitle + "</h1></td>"); 217 pOut.println("</tr>"); 218 pOut.println("<tr>"); 219 if (pSubTitle != null) { 220 pOut.println("<td align=\"center\"><h1>" + pSubTitle + "</h1></td>"); 221 } 222 pOut.println("</tr>"); 223 pOut.println("</table>"); 224 } 225 226 230 protected void printFooter(PrintWriter pOut) { 231 pOut.println("</body>"); 232 pOut.println("</html>"); 233 } 234 235 243 protected void printNavigationFooter(String pDomainName, HttpServletRequest pRequest, PrintWriter pOut, 244 String pPrevious, String pNext) { 245 246 String sViewIndex = pRequest.getContextPath(); 248 String sViewNotifications = pRequest.getRequestURI() + "?" + PARAM_DOMAIN + "=" + pDomainName + "&" 250 + PARAM_VIEW + "=" + VIEW_NOTIFICATIONS; 251 String sPrevView = null; 253 if (pPrevious != null) { 254 sPrevView = pRequest.getRequestURI() + "?" + PARAM_DOMAIN + "=" + pDomainName + "&" + PARAM_VIEW + "=" 255 + pPrevious; 256 } 257 String sNextView = null; 259 if (pNext != null) { 260 sNextView = pRequest.getRequestURI() + "?" + PARAM_DOMAIN + "=" + pDomainName + "&" + PARAM_VIEW + "=" 261 + pNext; 262 } 263 264 pOut.print("<table border=\"1\" align=\"center\" cellspacing=\"0\" cellpadding=\"5\">"); 266 pOut.print("<tr>"); 267 pOut.print("<td align=\"center\"> <a HREF=\"" + sViewIndex + "\">Index</a> </td>"); 268 pOut.print("<td align=\"center\"> <a HREF=\"" + sViewNotifications 269 + "\" target=\"ViewNotifications\">Notifications</a> </td>"); 270 if (sPrevView != null) { 271 pOut.println("<td align=\"center\"> <a HREF=\"" + sPrevView + "\">Previous</a> </td>"); 272 } 273 if (sNextView != null) { 274 pOut.println("<td align=\"center\"> <a HREF=\"" + sNextView + "\">Next</a> </td>"); 275 } 276 pOut.println("</tr></table>"); 277 printFooter(pOut); 279 } 280 281 287 protected void doViewError(String pError, HttpServletRequest pRequest, PrintWriter pOut) { 288 289 printHeader(pOut, APP_TITLE, "Error"); 291 pOut.println("<h2>" + pError + "</h2>"); 293 pOut.println("<a HREF=\"" + pRequest.getContextPath() + "\">Return</a>"); 295 printFooter(pOut); 297 } 298 299 305 protected void doViewInit(String pDomainName, HttpServletRequest pRequest, PrintWriter pOut) { 306 307 310 pOut.println("<h2>Initial context</h2>"); 314 pOut.println("<ul>"); 315 Context initialContext = null; 316 try { 317 initialContext = new InitialContext (); 318 pOut.println("<li>Initial context OK</li>"); 319 } catch (Exception e) { 320 pOut.print("<li>Cannot get initial context for JNDI: "); 321 pOut.println(e + "</li>"); 322 pOut.println("</ul>"); 323 return; 324 } 325 pOut.println("</ul><br>"); 326 327 pOut.println("<h2>Create MEJB</h2>"); 331 pOut.println("<ul>"); 332 333 ManagementHome mgmtHome = null; 335 DomainManagementHome domainMgmtHome = null; 336 try { 337 mgmtHome = (ManagementHome ) PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/ejb/mgmt/MEJB"), 338 ManagementHome .class); 339 } catch (Exception e) { 340 pOut.println("<li>Cannot lookup java:comp/env/ejb/mgmt/MEJB: " + e + "</li>"); 341 pOut.println("</ul>"); 342 return; 343 } 344 345 pOut.println("<h2>Create DomainMEJB</h2>"); 346 pOut.println("<ul>"); 347 348 try { 349 domainMgmtHome = (DomainManagementHome) PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/ejb/mgmt/DomainMEJB"), 350 DomainManagementHome.class); 351 } catch (Exception e) { 352 pOut.println("<li>Cannot lookup java:comp/env/ejb/mgmt/DomainMEJB: " + e + "</li>"); 353 pOut.println("</ul>"); 354 } 356 Management mgmt = null; 358 DomainManagement dmgmt = null; 360 361 try { 362 mgmt = mgmtHome.create(); 363 pOut.println("<li>MEJB created</li>"); 364 } catch (Exception e) { 365 pOut.println("<li>Cannot create MEJB: " + e + "</li>"); 366 return; 367 } 368 369 try { 370 dmgmt = domainMgmtHome.create(); 371 pOut.println("<li>DomainMEJB created</li>"); 372 } catch (Exception e) { 373 pOut.println("<li>Cannot create DomainMEJB: " + e + "</li>"); 374 return; 375 } 376 pOut.println("</ul><br />"); 377 378 ObjectName onDomain = accessJ2EEDomain(pDomainName, mgmt, pOut); 382 if (onDomain == null) { 383 return; 384 } 385 ObjectName onServer = accessJ2EEServer(onDomain, mgmt, pOut); 389 if (onServer == null) { 390 return; 391 } 392 393 String [] serverNames = null; 397 String [] serverNamesDom = null; 398 String [] servers = null; 399 try { 400 pOut.println("<h2>Getting list of servers with MEJB </h2>"); 401 serverNames = (String []) mgmt.getAttribute(onDomain, "serverNames"); 402 servers = (String []) mgmt.getAttribute(onDomain, "servers"); 403 pOut.println("<ul>"); 404 for(int i = 0; i < serverNames.length; i++){ 405 pOut.println("<li>" + serverNames[i] + "</li>"); 406 } 407 pOut.println("</ul>"); 408 409 } catch (Exception e){ 410 pOut.println("<li>Could not make MEJB list servers. </li>" + e); 411 e.printStackTrace(pOut); 412 return; 413 } 414 415 try { 416 pOut.println("<h2>Getting list of servers with DomainMEJB </h2>"); 417 serverNamesDom = (String []) dmgmt.getAttribute(null, onDomain, "serverNames"); 418 pOut.println("<ul>"); 419 for(int i = 0; i < serverNamesDom.length; i++){ 420 pOut.println("<li>" + serverNamesDom[i] + "</li>"); 421 } 422 pOut.println("</ul>"); 423 424 } catch (Exception e){ 425 pOut.println("<li>Could not make DomainMEJB list servers. </li>" + e); 426 e.printStackTrace(pOut); 427 return; 428 } 429 430 if (servers.length > 1) { 434 pOut.println("<h2>Try to manage the current domain: deploy/undeploy on all servers in the domain</h2>"); 435 pOut.println("<ul>"); 436 pOut.println("<li>Use the J2EEDomain object name: \"" + onDomain.toString() + "\"</li>"); 437 438 String fileName = null; 439 fileName = "sb.jar"; 442 deployModuleWithTarget(JAR, onDomain, servers, mgmt, fileName, pOut); 443 444 fileName = "earsample.ear"; 447 deployModuleWithTarget(EAR, onDomain, servers, mgmt, fileName, pOut); 448 449 pOut.println("</ul><br>"); 450 } 451 452 pOut.println("<h2>Try to manage the current server</h2>"); 456 pOut.println("<ul>"); 457 pOut.println("<li>Using the J2EEServer object name: \"" + onServer.toString() + "\"</li>"); 458 459 String jarFileName = "sb.jar"; 462 deployJarModule(onServer, mgmt, jarFileName, pOut); 463 464 String earFileName = "earsample.ear"; 467 deployEarModule(onServer, mgmt, earFileName, pOut); 468 469 earFileName = "autoload/earsample.ear"; 471 deployEarModule(onServer, mgmt, earFileName, pOut); 472 473 String rarFileName = "autoload/JOnAS_jdbcCP.rar"; 476 deployRarModule(onServer, mgmt, rarFileName, pOut); 477 478 pOut.println("</ul><br>"); 479 480 484 pOut.println("<h2>Register a event listener</h2>"); 485 pOut.println("<ul>"); 486 if (mListener == null) { 487 mListener = new MyListener(); 488 pOut.println("<li>MyListener created</li>"); 489 } 490 491 try { 493 ListenerRegistration lr = mgmt.getListenerRegistry(); 494 if (lr != null) { 495 pOut.println("<li>Add listener on J2EEServer (" + onServer.toString() + ")</li>"); 496 String sHandler = "MEJBTester"; 497 lr.addNotificationListener(onServer, mListener, null, sHandler); 498 pOut.println("<li>Notification Listener added</li>"); 499 String sViewNotifications = pRequest.getRequestURI() + "?" + PARAM_DOMAIN + "=" + pDomainName + "&" 500 + PARAM_VIEW + "=" + VIEW_NOTIFICATIONS; 501 pOut.println("<a HREF=\"" + sViewNotifications 502 + "\" target=\"ViewNotifications\">See list of notifications</a>"); 503 pOut.println("</ul>"); 504 } else { 505 pOut.println("<li>Can't add remote listener for the moment</li>"); 506 pOut.println("</ul>"); 507 } 508 } catch (Exception e) { 509 pOut.println("<li>Can't add notification listener on " + onServer.toString() + " : " + e + "</li>"); 510 } 511 512 pOut.println("<h2>View Sample Init is OK </h2>"); 513 514 printNavigationFooter(pDomainName, pRequest, pOut, null, VIEW_OTHER); 516 } 517 518 522 protected void doViewNotifications(PrintWriter pOut) { 523 524 printHeaderAutoRefresh(pOut, APP_TITLE, "Notifications"); 526 pOut.println("<h2>List of notifications</h2>"); 527 528 if (mListener == null) { 530 pOut.println("Listener not found !"); 531 } else { 532 List list = mListener.getlistNotifications(); 534 if (list.size() > 0) { 535 pOut.println("<ol>"); 536 for (int i = 0; i < list.size(); i++) { 537 pOut.println("<li>" + list.get(i) + "</li>"); 538 } 539 pOut.println("</ol>"); 540 } else { 541 pOut.println("No notifications, the list is empty"); 542 } 543 } 544 545 printFooter(pOut); 547 } 548 549 555 protected void doViewOther(String pDomainName, HttpServletRequest pRequest, PrintWriter pOut) { 556 557 printHeader(pOut, APP_TITLE, "Other"); 559 560 pOut.println("<h2>Other</h2>"); 561 562 printNavigationFooter(pDomainName, pRequest, pOut, VIEW_INIT, null); 564 } 565 566 573 private ObjectName accessJ2EEDomain(String pDomainName, Management mgmt, PrintWriter pOut) { 574 ObjectName onDomain = null; 575 pOut.println("<h2>Access the J2EEDomain MBean</h2>"); 576 pOut.println("<ul>"); 577 578 try { 580 String name = pDomainName + ":j2eeType=J2EEDomain,name=" + pDomainName; 581 onDomain = ObjectName.getInstance(name); 582 pOut.println("<li>J2EEDomain object name created: \"" + name.toString() + "\"</li>"); 583 } catch (Exception e) { 584 pOut.println("<li>Cannot create object name for J2EEDomain managed object: " + e + "</li>"); 585 pOut.println("</ul>"); 586 return null; 587 } 588 try { 590 boolean exists = mgmt.isRegistered(onDomain); 591 if (exists) { 592 pOut.println("<li>Found this J2EEDomain managed object registered in the current MBean server</li>"); 593 pOut.println("</ul>"); 594 } else { 595 pOut.println("<li><b>Can't find this J2EEDomain managed object in the current MBean server</b></li>"); 596 pOut.println("</ul>"); 597 return null; 598 } 599 } catch (Exception e) { 600 pOut.println("<li>Error when using this J2EEDomain managed object: " + e + "</li>"); 601 pOut.println("</ul>"); 602 return null; 603 } 604 return onDomain; 605 } 606 607 614 private ObjectName accessJ2EEServer(ObjectName onDomain, Management mgmt, PrintWriter pOut) { 615 pOut.println("<h2>Access the J2EEServer MBeans</h2>"); 616 pOut.println("<ul>"); 617 ObjectName onServer = null; 618 try { 619 String [] listServers = (String []) mgmt.getAttribute(onDomain, "servers"); 620 int nbServers = listServers.length; 621 if (nbServers == 0) { 622 pOut.println("<li>No J2EE servers belonging to this domain (problem with domain management !!)</li>"); 623 pOut.println("</ul><br>"); 624 return null; 625 } else { 626 if (nbServers == 1) { 627 String serverName = (String ) listServers[0]; 628 onServer = ObjectName.getInstance(serverName); 629 if (mgmt.isRegistered(onServer)) { 630 pOut.println("<li>One J2EE server running in this domain. Its object name is: \"" + serverName + "\"</li>"); 631 pOut.println("</ul><br>"); 632 return onServer; 633 } else { 634 pOut.println("<li><b>Can't find the J2EEServer MBean having object name: " + serverName + " in the current MBean server</b></li>"); 635 pOut.println("</ul><br>"); 636 return null; 637 } 638 } else { 639 pOut.println("<li>List of J2EE servers belonging to this domain (list of the associated MBean object names):</li>"); 640 pOut.println("<ol>"); 641 for (int i = 0; i < nbServers; i++) { 642 String sServer = listServers[i]; 643 ObjectName on = ObjectName.getInstance(sServer); 644 if (mgmt.isRegistered(on)) { 645 pOut.print("<li>The MBean having object name \"" + sServer); 646 pOut.println("\" is registered in the current MBean server."); 647 pOut.println("</li>"); 648 onServer = on; 649 } else { 650 pOut.print("<li>Found object name \"" + sServer); 651 pOut.println("\" in the severs list, but this name is not registered in the current MBean server."); 652 String name = on.getKeyProperty("name"); 653 String [] signature = {"java.lang.String"}; 654 String [] params = new String [1]; 655 params[0] = name; 656 String [] urls = (String []) mgmt.invoke(onDomain, "getConnectorServerURLs", params, signature); 657 pOut.println("<ul>"); 658 for (int j = 0; j < params.length; j++) { 659 String url = urls[j]; 660 pOut.print("<li>Try to connect to server " + name + ". Use MBean server connector url: " + url + "</li>"); 661 MBeanServerConnection connection = createConnection(url); 662 if (connection != null) { 663 try { 665 if (connection.isRegistered(on)) { 666 pOut.print("<li>Found MBean having object name \"" + sServer + "\" registered in the connected MBean server"); 667 } else { 668 pOut.print("<li>The MBean having object name \"" + sServer + "\" is not registered in the connected MBean server"); 669 } 670 } catch (IOException ioe) { 671 pOut.print("<li>Exception when trying to use connection: " + ioe.toString()); 672 } 673 } 674 } 675 pOut.println("</ul>"); 676 pOut.println("</li>"); 677 } 678 } 679 pOut.println("</ol>"); 680 pOut.println("</ul><br>"); 681 return onServer; 682 } 683 } 684 } catch (Exception e) { 685 pOut.println("<li>Error when managing the J2EEServer: " + e + "</li>"); 686 pOut.println("</ul><br>"); 687 return null; 688 } 689 } 690 691 private MBeanServerConnection createConnection(String connectorServerURL) { 692 MBeanServerConnection connection; 693 JMXConnector connector = null; 695 try { 696 JMXServiceURL url = new JMXServiceURL (connectorServerURL); 697 connector = JMXConnectorFactory.newJMXConnector(url, null); 698 connector.connect(null); 699 connection = connector.getMBeanServerConnection(); 700 } catch (MalformedURLException e) { 701 connection = null; 703 } catch (IOException e) { 704 connection = null; 706 } catch (java.lang.SecurityException e) { 707 connection = null; 709 } 710 return connection; 711 } 712 713 720 private void deployJarModule(ObjectName onServer, Management mgmt, String jarFileName, PrintWriter pOut) { 721 String [] signature = {"java.lang.String"}; 722 String [] params = new String [1]; 723 params[0] = jarFileName; 724 pOut.println("<li>Test if " + jarFileName + " deployed</li>"); 725 boolean isDeployed = false; 726 try { 727 isDeployed = ((Boolean ) mgmt.invoke(onServer, "isJarDeployed", params, signature)).booleanValue(); 728 } catch (Exception e) { 729 pOut.println("<li>Problem when invoking isJarDeployed management operation: " + e.toString()); 730 } 731 if (!isDeployed) { 732 pOut.println("<li>Try to deploy " + jarFileName + " !</li>"); 733 try { 734 String deployedObjectName = (String ) mgmt.invoke(onServer, "deployJar", params, signature); 735 pOut.println("<li>The Object Name of the deployed J2EEModule is: \"" + deployedObjectName + "\". </li>"); 736 } catch (MBeanException mbe) { 737 pOut.println("<li>Could not deploy " + jarFileName + " because of exception: " 738 + mbe.getTargetException().toString()); 739 } catch (Exception e) { 740 pOut.println("<li>Could not deploy " + jarFileName + " because of exception: " + e.toString() + " </li>"); 741 } 742 } else { 743 pOut.println("<li>Try to un-deploy " + jarFileName + " !</li>"); 744 try { 745 mgmt.invoke(onServer, "unDeployJar", params, signature); 746 pOut.println("<li>Done undeploy.>"); 747 } catch (MBeanException mbe) { 748 pOut.println("<li>Could not undeploy " + jarFileName + " because of exception: " 749 + mbe.getTargetException().toString()); 750 } catch (Exception e) { 751 pOut.println("<li>Could not undeploy " + jarFileName + " because of exception: " + e.toString() + " </li>"); 752 } 753 } 754 } 755 762 private void deployEarModule(ObjectName onServer, Management mgmt, String earFileName, PrintWriter pOut) { 763 String [] signature = {"java.lang.String"}; 764 String [] params = new String [1]; 765 params[0] = earFileName; 766 pOut.println("<li>Test if " + earFileName + " deployed</li>"); 767 boolean isDeployed = false; 768 try { 769 isDeployed = ((Boolean ) mgmt.invoke(onServer, "isEarDeployed", params, signature)).booleanValue(); 770 } catch (Exception e) { 771 pOut.println("<li>Problem when invoking isEarDeployed management operation: " + e.toString()); 772 } 773 if (!isDeployed) { 774 pOut.println("<li>Try to deploy " + earFileName + " !</li>"); 775 try { 776 String deployedObjectName = (String ) mgmt.invoke(onServer, "deployEar", params, signature); 777 pOut.println("<li>The Object Name of the deployed J2EEModule is: \"" + deployedObjectName + "\". </li>"); 778 } catch (MBeanException mbe) { 779 pOut.println("<li>Could not deploy " + earFileName + " because of exception: " 780 + mbe.getTargetException().toString()); 781 } catch (Exception e) { 782 pOut.println("<li>Could not deploy " + earFileName + " because of exception: " + e.toString() + " </li>"); 783 } 784 } else { 785 pOut.println("<li>Try to un-deploy " + earFileName + " !</li>"); 786 try { 787 mgmt.invoke(onServer, "unDeployEar", params, signature); 788 pOut.println("<li>Done undeploy.>"); 789 } catch (MBeanException mbe) { 790 pOut.println("<li>Could not undeploy " + earFileName + " because of exception: " 791 + mbe.getTargetException().toString()); 792 } catch (Exception e) { 793 pOut.println("<li>Could not undeploy " + earFileName + " because of exception: " + e.toString() + " </li>"); 794 } 795 } 796 } 797 798 805 private void deployRarModule(ObjectName onServer, Management mgmt, String rarFileName, PrintWriter pOut) { 806 String [] signature = {"java.lang.String"}; 807 String [] params = new String [1]; 808 params[0] = rarFileName; 809 pOut.println("<li>Test if " + rarFileName + " deployed</li>"); 810 boolean isDeployed = false; 811 try { 812 isDeployed = ((Boolean ) mgmt.invoke(onServer, "isRarDeployed", params, signature)).booleanValue(); 813 } catch (Exception e) { 814 pOut.println("<li>Problem when invoking isRarDeployed management operation: " + e.toString()); 815 } 816 if (!isDeployed) { 817 pOut.println("<li>Try to deploy " + rarFileName + " !</li>"); 818 try { 819 String deployedObjectName = (String ) mgmt.invoke(onServer, "deployRar", params, signature); 820 pOut.println("<li>The Object Name of the deployed J2EEModule is: \"" + deployedObjectName + "\". </li>"); 821 } catch (MBeanException mbe) { 822 pOut.println("<li>Could not deploy " + rarFileName + " because of exception: " 823 + mbe.getTargetException().toString()); 824 } catch (Exception e) { 825 pOut.println("<li>Could not deploy " + rarFileName + " because of exception: " + e.toString() + " </li>"); 826 } 827 } else { 828 pOut.println("<li>Try to un-deploy " + rarFileName + " !</li>"); 829 try { 830 mgmt.invoke(onServer, "unDeployRar", params, signature); 831 pOut.println("<li>Done undeploy.>"); 832 } catch (MBeanException mbe) { 833 pOut.println("<li>Could not undeploy " + rarFileName + " because of exception: " 834 + mbe.getTargetException().toString()); 835 } catch (Exception e) { 836 pOut.println("<li>Could not undeploy " + rarFileName + " because of exception: " + e.toString() + " </li>"); 837 } 838 } 839 } 840 841 849 private void deployModuleWithTarget(String moduleType, ObjectName onDomain, String [] target, Management mgmt, String fileName, PrintWriter pOut) { 850 String [] signature = {"[Ljava.lang.String;", "java.lang.String"}; 851 Object [] params = new Object [2]; 852 params[0] = target; 853 params[1] = fileName; 854 pOut.println("<li>Try to deploy " + fileName + " on target !</li>"); 855 String operationNameSuf = null; 856 if (moduleType.equals(JAR)) { 857 operationNameSuf = "eployJar"; 858 } else if (moduleType.equals(WAR)) { 859 operationNameSuf = "eployWar"; 860 } else if (moduleType.equals(RAR)) { 861 operationNameSuf = "eployWar"; 862 } else if (moduleType.equals(EAR)) { 863 operationNameSuf = "eployEar"; 864 } else { 865 return; 866 } 867 try { 868 String operationName = "d" + operationNameSuf; 869 Boolean done = (Boolean ) mgmt.invoke(onDomain, operationName, params, signature); 870 if (done.booleanValue()) { 871 operationName = "unD" + operationNameSuf; 872 mgmt.invoke(onDomain, operationName, params, signature); 873 } 874 } catch (MBeanException mbe) { 875 pOut.println("<li>Could not deploy/undeploy " + fileName + " because of exception: " 876 + mbe.getTargetException().toString()); 877 } catch (Exception e) { 878 pOut.println("<li>Could not deploy " + fileName + " because of exception: " + e.toString() + " </li>"); 879 } 880 } 881 } | Popular Tags |