1 16 package org.apache.axis.utils; 17 18 import org.apache.axis.client.AdminClient; 19 import org.apache.axis.monitor.SOAPMonitorConstants; 20 import org.w3c.dom.Document ; 21 import org.w3c.dom.Element ; 22 import org.w3c.dom.NamedNodeMap ; 23 import org.w3c.dom.Node ; 24 import org.w3c.dom.NodeList ; 25 26 import javax.swing.BoxLayout ; 27 import javax.swing.ButtonGroup ; 28 import javax.swing.DefaultListModel ; 29 import javax.swing.JButton ; 30 import javax.swing.JCheckBox ; 31 import javax.swing.JDialog ; 32 import javax.swing.JFrame ; 33 import javax.swing.JLabel ; 34 import javax.swing.JList ; 35 import javax.swing.JOptionPane ; 36 import javax.swing.JPanel ; 37 import javax.swing.JPasswordField ; 38 import javax.swing.JProgressBar ; 39 import javax.swing.JRadioButton ; 40 import javax.swing.JScrollPane ; 41 import javax.swing.JSplitPane ; 42 import javax.swing.JTabbedPane ; 43 import javax.swing.JTable ; 44 import javax.swing.JTextArea ; 45 import javax.swing.JTextField ; 46 import javax.swing.ListSelectionModel ; 47 import javax.swing.SwingConstants ; 48 import javax.swing.SwingUtilities ; 49 import javax.swing.UIManager ; 50 import javax.swing.WindowConstants ; 51 import javax.swing.border.BevelBorder ; 52 import javax.swing.border.EmptyBorder ; 53 import javax.swing.border.EtchedBorder ; 54 import javax.swing.event.DocumentEvent ; 55 import javax.swing.event.DocumentListener ; 56 import javax.swing.event.ListSelectionEvent ; 57 import javax.swing.event.ListSelectionListener ; 58 import javax.swing.table.AbstractTableModel ; 59 import javax.swing.event.ChangeListener ; 60 import javax.xml.parsers.ParserConfigurationException ; 61 import java.awt.BorderLayout ; 62 import java.awt.Color ; 63 import java.awt.Dimension ; 64 import java.awt.FlowLayout ; 65 import java.awt.Font ; 66 import java.awt.GridBagConstraints ; 67 import java.awt.GridBagLayout ; 68 import java.awt.GridLayout ; 69 import java.awt.Insets ; 70 import java.awt.event.ActionEvent ; 71 import java.awt.event.ActionListener ; 72 import java.awt.event.WindowAdapter ; 73 import java.awt.event.WindowEvent ; 74 import java.io.ByteArrayInputStream ; 75 import java.io.IOException ; 76 import java.io.ObjectInputStream ; 77 import java.io.ObjectOutputStream ; 78 import java.lang.reflect.InvocationTargetException ; 79 import java.net.Socket ; 80 import java.net.URL ; 81 import java.net.MalformedURLException ; 82 import java.text.DateFormat ; 83 import java.util.Collection ; 84 import java.util.Date ; 85 import java.util.Enumeration ; 86 import java.util.HashMap ; 87 import java.util.Iterator ; 88 import java.util.Vector ; 89 90 98 public class SOAPMonitor extends JFrame implements ActionListener , ChangeListener { 99 100 103 private JPanel main_panel = null; 104 105 108 private JTabbedPane tabbed_pane = null; 109 110 113 private JTabbedPane top_pane = null; 114 115 118 private int port = 5001; 119 120 123 private String axisHost = "localhost"; 124 125 128 private int axisPort = 8080; 129 130 133 private String axisURL = null; 134 135 138 private Vector pages = null; 139 140 143 private final String titleStr = "SOAP Monitor Administration"; 144 145 148 private JPanel set_panel = null; 149 150 153 private JLabel titleLabel = null; 154 155 158 private JButton add_btn = null; 159 160 163 private JButton del_btn = null; 164 165 168 private JButton save_btn = null; 169 170 173 private JButton login_btn = null; 174 175 178 private DefaultListModel model1 = null; 179 180 183 private DefaultListModel model2 = null; 184 185 188 private JList list1 = null; 189 190 193 private JList list2 = null; 194 195 198 private HashMap serviceMap = null; 199 200 203 private Document originalDoc = null; 204 205 208 private static String axisUser = null; 209 210 213 private static String axisPass = null; 214 215 218 private AdminClient adminClient = new AdminClient(); 219 220 226 public static void main(String args[]) throws Exception { 227 SOAPMonitor soapMonitor = null; 228 Options opts = new Options(args); 229 if (opts.isFlagSet('?') > 0) { 230 System.out.println( 231 "Usage: SOAPMonitor [-l<url>] [-u<user>] [-w<password>] [-?]"); 232 System.exit(0); 233 } 234 235 soapMonitor = new SOAPMonitor(); 237 238 soapMonitor.axisURL = opts.getURL(); 241 URL url = new URL (soapMonitor.axisURL); 242 soapMonitor.axisHost = url.getHost(); 243 244 axisUser = opts.getUser(); 246 axisPass = opts.getPassword(); 247 248 soapMonitor.doLogin(); 250 } 251 252 255 public SOAPMonitor() { 256 setTitle("SOAP Monitor Application"); 257 Dimension d = getToolkit().getScreenSize(); 258 setSize(640, 480); 259 setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2); 260 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 261 addWindowListener(new MyWindowAdapter()); 262 263 try { 265 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 266 } catch (Exception e) { 267 } 268 269 main_panel = new JPanel (); 271 main_panel.setBackground(Color.white); 272 main_panel.setLayout(new BorderLayout ()); 273 top_pane = new JTabbedPane (); 274 set_panel = new JPanel (); 275 276 titleLabel = new JLabel (titleStr); 278 titleLabel.setFont(new Font ("Serif", Font.BOLD, 18)); 279 280 model1 = new DefaultListModel (); 282 list1 = new JList (model1); 283 list1.setFixedCellWidth(250); 284 JScrollPane scroll1 = new JScrollPane (list1); 285 286 model2 = new DefaultListModel (); 288 list2 = new JList (model2); 289 list2.setFixedCellWidth(250); 290 JScrollPane scroll2 = new JScrollPane (list2); 291 292 add_btn = new JButton ("Turn On [ >> ]"); 294 del_btn = new JButton ("[ << ] Turn Off"); 295 JPanel center_panel = new JPanel (); 296 GridBagLayout layout = new GridBagLayout (); 297 center_panel.setLayout(layout); 298 GridBagConstraints c = new GridBagConstraints (); 299 c.gridx = 0; 300 c.gridy = 0; 301 c.insets = new Insets (10, 10, 10, 10); 302 layout.setConstraints(add_btn, c); 303 center_panel.add(add_btn); 304 c.gridx = 0; 305 c.gridy = 1; 306 c.insets = new Insets (10, 10, 10, 10); 307 layout.setConstraints(del_btn, c); 308 center_panel.add(del_btn); 309 310 save_btn = new JButton ("Save changes"); 312 login_btn = new JButton ("Change server"); 313 JPanel south_panel = new JPanel (); 314 layout = new GridBagLayout (); 315 c.gridx = 0; 316 c.gridy = 0; 317 c.insets = new Insets (10, 10, 10, 10); 318 layout.setConstraints(save_btn, c); 319 south_panel.add(save_btn); 320 c.gridx = 1; 321 c.gridy = 0; 322 c.insets = new Insets (10, 10, 10, 10); 323 layout.setConstraints(login_btn, c); 324 south_panel.add(login_btn); 325 326 set_panel.setLayout(new BorderLayout (5, 5)); 328 set_panel.add(titleLabel, BorderLayout.NORTH); 329 set_panel.add(south_panel, BorderLayout.SOUTH); 330 set_panel.add(scroll1, BorderLayout.WEST); 331 set_panel.add(scroll2, BorderLayout.EAST); 332 set_panel.add(center_panel, BorderLayout.CENTER); 333 334 add_btn.addActionListener(this); 336 del_btn.addActionListener(this); 337 save_btn.addActionListener(this); 338 login_btn.addActionListener(this); 339 340 add_btn.setEnabled(false); 342 del_btn.setEnabled(false); 343 save_btn.setEnabled(false); 344 login_btn.setEnabled(false); 345 top_pane.add("Setting", set_panel); 346 top_pane.add("Monitoring", main_panel); 347 getContentPane().add(top_pane); 348 349 tabbed_pane = new JTabbedPane (JTabbedPane.TOP); 351 main_panel.add(tabbed_pane, BorderLayout.CENTER); 352 top_pane.addChangeListener(this); 353 top_pane.setEnabled(false); 354 setVisible(true); 355 } 356 357 362 private boolean doLogin() { 363 Dimension d = null; 364 365 LoginDlg login = new LoginDlg(); 367 login.show(); 368 if (!login.isLogin()) { 369 login_btn.setEnabled(true); 370 return false; 371 } 372 login.dispose(); 373 save_btn.setEnabled(false); 374 login_btn.setEnabled(false); 375 376 String url_str = login.getURL(); 378 try { 379 URL url = new URL (url_str); 380 axisHost = url.getHost(); 381 axisPort = url.getPort(); 382 if (axisPort == -1) { 383 axisPort = 8080; 384 } 385 String axisPath = url.getPath(); 386 axisURL = "http://" + axisHost + ":" + axisPort + axisPath; 387 } catch (MalformedURLException e) { 388 JOptionPane pane = new JOptionPane (); 389 String msg = e.toString(); 390 pane.setMessageType(JOptionPane.WARNING_MESSAGE); 391 pane.setMessage(msg); 392 pane.setOptions(new String []{"OK"}); 393 JDialog dlg = pane.createDialog(null, "Login status"); 394 dlg.setVisible(true); 395 login_btn.setEnabled(true); 396 return false; 397 } 398 titleLabel.setText(titleStr + " for [" + axisHost + ":" + axisPort 399 + "]"); 400 final JProgressBar progressBar = new JProgressBar (0, 100); 401 BarThread stepper = new BarThread(progressBar); 402 stepper.start(); 403 JFrame progress = new JFrame (); 404 d = new Dimension (250, 50); 405 progress.setSize(d); 406 d = getToolkit().getScreenSize(); 407 progress.getContentPane().add(progressBar); 408 progress.setTitle("Now loading data ..."); 409 progress.setLocation((d.width - progress.getWidth()) / 2, 410 (d.height - progress.getHeight()) / 2); 411 progress.show(); 412 413 pages = new Vector (); 415 addPage(new SOAPMonitorPage(axisHost)); 416 serviceMap = new HashMap (); 417 originalDoc = getServerWSDD(); 418 model1.clear(); 419 model2.clear(); 420 if (originalDoc != null) { 421 String ret = null; 422 NodeList nl = originalDoc.getElementsByTagName("service"); 423 for (int i = 0; i < nl.getLength(); i++) { 424 Node node = nl.item(i); 425 NamedNodeMap map = node.getAttributes(); 426 ret = map.getNamedItem("name").getNodeValue(); 427 serviceMap.put(ret, node); 428 if (!isMonitored(node)) { 429 model1.addElement((String ) ret); 430 } else { 431 model2.addElement((String ) ret); 432 } 433 } 434 if (model1.size() > 0) { 435 add_btn.setEnabled(true); 436 } 437 if (model2.size() > 0) { 438 del_btn.setEnabled(true); 439 } 440 progress.dispose(); 441 save_btn.setEnabled(true); 442 login_btn.setEnabled(true); 443 top_pane.setEnabled(true); 444 return true; 445 } else { 446 progress.dispose(); 447 login_btn.setEnabled(true); 448 return false; 449 } 450 } 451 452 455 class BarThread extends Thread { 456 457 460 private int wait = 100; 461 462 465 JProgressBar progressBar = null; 466 467 472 public BarThread(JProgressBar bar) { 473 progressBar = bar; 474 } 475 476 479 public void run() { 480 int min = progressBar.getMinimum(); 481 int max = progressBar.getMaximum(); 482 Runnable runner = new Runnable () { 483 public void run() { 484 int val = progressBar.getValue(); 485 progressBar.setValue(val + 1); 486 } 487 }; 488 for (int i = min; i < max; i++) { 489 try { 490 SwingUtilities.invokeAndWait(runner); 491 Thread.sleep(wait); 492 } catch (InterruptedException ignoredException) { 493 } catch (InvocationTargetException ignoredException) { 494 } 495 } 496 } 497 } 498 499 504 private Document getServerWSDD() { 505 Document doc = null; 506 try { 507 String [] param = new String []{"-u" + axisUser, "-w" + axisPass, 508 "-l " + axisURL, "list"}; 509 String ret = adminClient.process(param); 510 doc = XMLUtils.newDocument( 511 new ByteArrayInputStream (ret.getBytes())); 512 } catch (Exception e) { 513 JOptionPane pane = new JOptionPane (); 514 String msg = e.toString(); 515 pane.setMessageType(JOptionPane.WARNING_MESSAGE); 516 pane.setMessage(msg); 517 pane.setOptions(new String []{"OK"}); 518 JDialog dlg = pane.createDialog(null, "Login status"); 519 dlg.setVisible(true); 520 } 521 return doc; 522 } 523 524 530 private boolean doDeploy(Document wsdd) { 531 String deploy = null; 532 Options opt = null; 533 deploy = XMLUtils.DocumentToString(wsdd); 534 try { 535 String [] param = new String []{"-u" + axisUser, "-w" + axisPass, 536 "-l " + axisURL, ""}; 537 opt = new Options(param); 538 adminClient.process(opt, 539 new ByteArrayInputStream (deploy.getBytes())); 540 } catch (Exception e) { 541 return false; 542 } 543 return true; 544 } 545 546 552 private Document getNewDocumentAsNode(Node target) { 553 Document doc = null; 554 Node node = null; 555 try { 556 doc = XMLUtils.newDocument(); 557 } catch (ParserConfigurationException e) { 558 e.printStackTrace(); 559 } 560 node = doc.importNode(target, true); 561 doc.appendChild(node); 562 return doc; 563 } 564 565 573 private Node addMonitor(Node target) { 574 Document doc = null; 575 Node node = null; 576 Node newNode = null; 577 String ret = null; 578 NodeList nl = null; 579 final String reqFlow = "requestFlow"; 580 final String resFlow = "responseFlow"; 581 final String monitor = "soapmonitor"; 582 final String handler = "handler"; 583 final String type = "type"; 584 doc = getNewDocumentAsNode(target); 585 586 nl = doc.getElementsByTagName(resFlow); 588 if (nl.getLength() == 0) { 589 node = doc.getDocumentElement().getFirstChild(); 590 newNode = doc.createElement(resFlow); 591 doc.getDocumentElement().insertBefore(newNode, node); 592 } 593 594 nl = doc.getElementsByTagName(reqFlow); 596 if (nl.getLength() == 0) { 597 node = doc.getDocumentElement().getFirstChild(); 598 newNode = doc.createElement(reqFlow); 599 doc.getDocumentElement().insertBefore(newNode, node); 600 } 601 602 nl = doc.getElementsByTagName(reqFlow); 604 node = nl.item(0).getFirstChild(); 605 newNode = doc.createElement(handler); 606 ((Element ) newNode).setAttribute(type, monitor); 607 nl.item(0).insertBefore(newNode, node); 608 609 nl = doc.getElementsByTagName(resFlow); 611 node = nl.item(0).getFirstChild(); 612 newNode = doc.createElement(handler); 613 ((Element ) newNode).setAttribute(type, monitor); 614 nl.item(0).insertBefore(newNode, node); 615 616 return (Node ) doc.getDocumentElement(); 617 } 618 619 627 private Node delMonitor(Node target) { 628 Document doc = null; 629 Node node = null; 630 Node newNode = null; 631 String ret = null; 632 NodeList nl = null; 633 final String reqFlow = "requestFlow"; 634 final String resFlow = "responseFlow"; 635 final String monitor = "soapmonitor"; 636 final String handler = "handler"; 637 final String type = "type"; 638 doc = getNewDocumentAsNode(target); 639 nl = doc.getElementsByTagName(handler); 640 int size; 641 size = nl.getLength(); 642 Node [] removeNode = new Node [size]; 643 if (size > 0) { 644 newNode = nl.item(0).getParentNode(); 645 } 646 for (int i = 0; i < size; i++) { 647 node = nl.item(i); 648 NamedNodeMap map = node.getAttributes(); 649 ret = map.getNamedItem(type).getNodeValue(); 650 if (ret.equals(monitor)) { 651 removeNode[i] = node; 652 } 653 } 654 for (int i = 0; i < size; i++) { 655 Node child = removeNode[i]; 656 if (child != null) { 657 child.getParentNode().removeChild(child); 658 } 659 } 660 661 return (Node ) doc.getDocumentElement(); 662 } 663 664 670 private boolean isMonitored(Node target) { 671 Document doc = null; 672 Node node = null; 673 String ret = null; 674 NodeList nl = null; 675 final String monitor = "soapmonitor"; 676 final String handler = "handler"; 677 final String type = "type"; 678 doc = getNewDocumentAsNode(target); 679 nl = doc.getElementsByTagName(handler); 680 for (int i = 0; i < nl.getLength(); i++) { 681 node = nl.item(i); 682 NamedNodeMap map = node.getAttributes(); 683 ret = map.getNamedItem(type).getNodeValue(); 684 if (ret.equals(monitor)) { 685 return true; 686 } else { 687 return false; 688 } 689 } 690 return false; 691 } 692 693 701 private Node addAuthenticate(Node target) { 702 Document doc = null; 703 Node node = null; 704 Node newNode = null; 705 String ret = null; 706 NodeList nl = null; 707 final String reqFlow = "requestFlow"; 708 final String handler = "handler"; 709 final String type = "type"; 710 final String authentication = 711 "java:org.apache.axis.handlers.SimpleAuthenticationHandler"; 712 final String authorization = 713 "java:org.apache.axis.handlers.SimpleAuthorizationHandler"; 714 final String param = "parameter"; 715 final String name = "name"; 716 final String role = "allowedRoles"; 717 final String value = "value"; 718 final String admin = "admin"; 719 boolean authNode = false; 720 boolean roleNode = false; 721 doc = getNewDocumentAsNode(target); 722 723 nl = doc.getElementsByTagName(reqFlow); 725 if (nl.getLength() == 0) { 726 node = doc.getDocumentElement().getFirstChild(); 727 newNode = doc.createElement(reqFlow); 728 doc.getDocumentElement().insertBefore(newNode, node); 729 } 730 731 nl = doc.getElementsByTagName(handler); 734 for (int i = 0; i < nl.getLength(); i++) { 735 node = nl.item(i); 736 NamedNodeMap map = node.getAttributes(); 737 ret = map.getNamedItem(type).getNodeValue(); 738 if (ret.equals(authorization)) { 739 authNode = true; 740 break; 741 } 742 } 743 if (!authNode) { 744 nl = doc.getElementsByTagName(reqFlow); 745 node = nl.item(0).getFirstChild(); 746 newNode = doc.createElement(handler); 747 ((Element ) newNode).setAttribute(type, authorization); 748 nl.item(0).insertBefore(newNode, node); 749 } 750 751 authNode = false; 754 nl = doc.getElementsByTagName(handler); 755 for (int i = 0; i < nl.getLength(); i++) { 756 node = nl.item(i); 757 NamedNodeMap map = node.getAttributes(); 758 ret = map.getNamedItem(type).getNodeValue(); 759 if (ret.equals(authentication)) { 760 authNode = true; 761 break; 762 } 763 } 764 if (!authNode) { 765 nl = doc.getElementsByTagName(reqFlow); 766 node = nl.item(0).getFirstChild(); 767 newNode = doc.createElement(handler); 768 ((Element ) newNode).setAttribute(type, authentication); 769 nl.item(0).insertBefore(newNode, node); 770 } 771 772 nl = doc.getElementsByTagName(param); 774 for (int i = 0; i < nl.getLength(); i++) { 775 node = nl.item(i); 776 NamedNodeMap map = node.getAttributes(); 777 node = map.getNamedItem(name); 778 if (node != null) { 779 ret = node.getNodeValue(); 780 if (ret.equals(role)) { 781 roleNode = true; 782 break; 783 } 784 } 785 } 786 if (!roleNode) { 787 nl = doc.getElementsByTagName(param); 788 newNode = doc.createElement(param); 789 ((Element ) newNode).setAttribute(name, role); 790 ((Element ) newNode).setAttribute(value, admin); 791 doc.getDocumentElement().insertBefore(newNode, nl.item(0)); 792 } 793 return (Node ) doc.getDocumentElement(); 794 } 795 796 799 class MyWindowAdapter extends WindowAdapter { 800 801 806 public void windowClosing(WindowEvent e) { 807 System.exit(0); 808 } 809 } 810 811 816 private void addPage(SOAPMonitorPage pg) { 817 tabbed_pane.addTab(" " + pg.getHost() + " ", pg); 818 pages.addElement(pg); 819 } 820 821 824 private void delPage() { 825 tabbed_pane.removeAll(); 826 pages.removeAllElements(); 827 } 828 829 832 public void start() { 833 Enumeration e = pages.elements(); 835 while (e.hasMoreElements()) { 836 SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement(); 837 if (pg != null) { 838 pg.start(); 839 } 840 } 841 } 842 843 846 847 850 public void stop() { 851 Enumeration e = pages.elements(); 853 while (e.hasMoreElements()) { 854 SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement(); 855 if (pg != null) { 856 pg.stop(); 857 } 858 } 859 } 860 861 864 class LoginDlg extends JDialog implements ActionListener { 865 866 869 private JButton ok_button = null; 870 871 874 private JButton cancel_button = null; 875 876 879 private JTextField user = new JTextField (20); 880 881 884 private JPasswordField pass = new JPasswordField (20); 885 886 889 private JTextField url = new JTextField (20); 890 891 894 private boolean loginState = false; 895 896 899 public LoginDlg() { 900 setTitle("SOAP Monitor Login"); 901 UIManager.put("Label.font", new Font ("Dialog", Font.BOLD, 12)); 902 JPanel panel = new JPanel (); 903 ok_button = new JButton ("OK"); 904 ok_button.addActionListener(this); 905 cancel_button = new JButton ("Cancel"); 906 cancel_button.addActionListener(this); 907 908 url.setText(axisURL); 910 JLabel userLabel = new JLabel ("User:"); 911 JLabel passLabel = new JLabel ("Password:"); 912 JLabel urlLabel = new JLabel ("Axis URL:"); 913 userLabel.setHorizontalAlignment(JTextField.RIGHT); 914 passLabel.setHorizontalAlignment(JTextField.RIGHT); 915 urlLabel.setHorizontalAlignment(JTextField.RIGHT); 916 panel.add(userLabel); 917 panel.add(user); 918 panel.add(passLabel); 919 panel.add(pass); 920 panel.add(urlLabel); 921 panel.add(url); 922 panel.add(ok_button); 923 panel.add(cancel_button); 924 setContentPane(panel); 925 user.setText(SOAPMonitor.axisUser); 926 pass.setText(SOAPMonitor.axisPass); 927 GridLayout layout = new GridLayout (4, 2); 928 layout.setHgap(15); 929 layout.setVgap(5); 930 panel.setLayout(layout); 931 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 932 setModal(true); 933 pack(); 934 Dimension d = getToolkit().getScreenSize(); 935 setLocation((d.width - getWidth()) / 2, 936 (d.height - getHeight()) / 2); 937 } 938 939 944 public void actionPerformed(ActionEvent e) { 945 if (e.getSource() == ok_button) { 947 loginState = true; 948 SOAPMonitor.axisUser = user.getText(); 949 SOAPMonitor.axisPass = new String (pass.getPassword()); 950 this.hide(); 951 } else if (e.getSource() == cancel_button) { 952 this.dispose(); 953 } 954 } 955 956 961 public String getURL() { 962 return url.getText(); 963 } 964 965 970 public boolean isLogin() { 971 return loginState; 972 } 973 } 974 975 979 class SOAPMonitorPage extends JPanel 980 implements Runnable , ListSelectionListener , ActionListener { 981 982 985 private final String STATUS_ACTIVE = "The SOAP Monitor is started."; 986 987 990 private final String STATUS_STOPPED = "The SOAP Monitor is stopped."; 991 992 995 private final String STATUS_CLOSED = 996 "The server communication has been terminated."; 997 998 1001 private final String STATUS_NOCONNECT = 1002 "The SOAP Monitor is unable to communcate with the server."; 1003 1004 1007 private String host = null; 1008 1009 1012 private Socket socket = null; 1013 1014 1017 private ObjectInputStream in = null; 1018 1019 1022 private ObjectOutputStream out = null; 1023 1024 1027 private SOAPMonitorTableModel model = null; 1028 1029 1032 private JTable table = null; 1033 1034 1037 private JScrollPane scroll = null; 1038 1039 1042 private JPanel list_panel = null; 1043 1044 1047 private JPanel list_buttons = null; 1048 1049 1052 private JButton remove_button = null; 1053 1054 1057 private JButton remove_all_button = null; 1058 1059 1062 private JButton filter_button = null; 1063 1064 1067 private JPanel details_panel = null; 1068 1069 1072 private JPanel details_header = null; 1073 1074 1077 private JSplitPane details_soap = null; 1078 1079 1082 private JPanel details_buttons = null; 1083 1084 1087 private JLabel details_time = null; 1088 1089 1092 private JLabel details_target = null; 1093 1094 1097 private JLabel details_status = null; 1098 1099 1102 private JLabel details_time_value = null; 1103 1104 1107 private JLabel details_target_value = null; 1108 1109 1112 private JLabel details_status_value = null; 1113 1114 1117 private EmptyBorder empty_border = null; 1118 1119 1122 private EtchedBorder etched_border = null; 1123 1124 1127 private JPanel request_panel = null; 1128 1129 1132 private JPanel response_panel = null; 1133 1134 1137 private JLabel request_label = null; 1138 1139 1142 private JLabel response_label = null; 1143 1144 1147 private SOAPMonitorTextArea request_text = null; 1148 1149 1152 private SOAPMonitorTextArea response_text = null; 1153 1154 1157 private JScrollPane request_scroll = null; 1158 1159 1162 private JScrollPane response_scroll = null; 1163 1164 1167 private JButton layout_button = null; 1168 1169 1172 private JSplitPane split = null; 1173 1174 1177 private JPanel status_area = null; 1178 1179 1182 private JPanel status_buttons = null; 1183 1184 1187 private JButton start_button = null; 1188 1189 1192 private JButton stop_button = null; 1193 1194 1197 private JLabel status_text = null; 1198 1199 1202 private JPanel status_text_panel = null; 1203 1204 1207 private SOAPMonitorFilter filter = null; 1208 1209 1212 private GridBagLayout details_header_layout = null; 1213 1214 1217 private GridBagConstraints details_header_constraints = null; 1218 1219 1222 private JCheckBox reflow_xml = null; 1223 1224 1229 public SOAPMonitorPage(String host_name) { 1230 host = host_name; 1231 1232 filter = new SOAPMonitorFilter(); 1234 1235 etched_border = new EtchedBorder (); 1237 1238 model = new SOAPMonitorTableModel(); 1240 table = new JTable (model); 1241 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 1242 table.setRowSelectionInterval(0, 0); 1243 table.setPreferredScrollableViewportSize(new Dimension (600, 96)); 1244 table.getSelectionModel().addListSelectionListener(this); 1245 scroll = new JScrollPane (table); 1246 remove_button = new JButton ("Remove"); 1247 remove_button.addActionListener(this); 1248 remove_button.setEnabled(false); 1249 remove_all_button = new JButton ("Remove All"); 1250 remove_all_button.addActionListener(this); 1251 filter_button = new JButton ("Filter ..."); 1252 filter_button.addActionListener(this); 1253 list_buttons = new JPanel (); 1254 list_buttons.setLayout(new FlowLayout ()); 1255 list_buttons.add(remove_button); 1256 list_buttons.add(remove_all_button); 1257 list_buttons.add(filter_button); 1258 list_panel = new JPanel (); 1259 list_panel.setLayout(new BorderLayout ()); 1260 list_panel.add(scroll, BorderLayout.CENTER); 1261 list_panel.add(list_buttons, BorderLayout.SOUTH); 1262 list_panel.setBorder(empty_border); 1263 1264 details_time = new JLabel ("Time: ", SwingConstants.RIGHT); 1266 details_target = new JLabel ("Target Service: ", 1267 SwingConstants.RIGHT); 1268 details_status = new JLabel ("Status: ", SwingConstants.RIGHT); 1269 details_time_value = new JLabel (); 1270 details_target_value = new JLabel (); 1271 details_status_value = new JLabel (); 1272 Dimension preferred_size = details_time.getPreferredSize(); 1273 preferred_size.width = 1; 1274 details_time.setPreferredSize(preferred_size); 1275 details_target.setPreferredSize(preferred_size); 1276 details_status.setPreferredSize(preferred_size); 1277 details_time_value.setPreferredSize(preferred_size); 1278 details_target_value.setPreferredSize(preferred_size); 1279 details_status_value.setPreferredSize(preferred_size); 1280 details_header = new JPanel (); 1281 details_header_layout = new GridBagLayout (); 1282 details_header.setLayout(details_header_layout); 1283 details_header_constraints = new GridBagConstraints (); 1284 details_header_constraints.fill = GridBagConstraints.BOTH; 1285 details_header_constraints.weightx = 0.5; 1286 details_header_layout.setConstraints(details_time, 1287 details_header_constraints); 1288 details_header.add(details_time); 1289 details_header_layout.setConstraints(details_time_value, 1290 details_header_constraints); 1291 details_header.add(details_time_value); 1292 details_header_layout.setConstraints(details_target, 1293 details_header_constraints); 1294 details_header.add(details_target); 1295 details_header_constraints.weightx = 1.0; 1296 details_header_layout.setConstraints(details_target_value, 1297 details_header_constraints); 1298 details_header.add(details_target_value); 1299 details_header_constraints.weightx = .5; 1300 details_header_layout.setConstraints(details_status, 1301 details_header_constraints); 1302 details_header.add(details_status); 1303 details_header_layout.setConstraints(details_status_value, 1304 details_header_constraints); 1305 details_header.add(details_status_value); 1306 details_header.setBorder(etched_border); 1307 request_label = new JLabel ("SOAP Request", SwingConstants.CENTER); 1308 request_text = new SOAPMonitorTextArea(); 1309 request_text.setEditable(false); 1310 request_scroll = new JScrollPane (request_text); 1311 request_panel = new JPanel (); 1312 request_panel.setLayout(new BorderLayout ()); 1313 request_panel.add(request_label, BorderLayout.NORTH); 1314 request_panel.add(request_scroll, BorderLayout.CENTER); 1315 response_label = 1316 new JLabel ("SOAP Response", SwingConstants.CENTER); 1317 response_text = new SOAPMonitorTextArea(); 1318 response_text.setEditable(false); 1319 response_scroll = new JScrollPane (response_text); 1320 response_panel = new JPanel (); 1321 response_panel.setLayout(new BorderLayout ()); 1322 response_panel.add(response_label, BorderLayout.NORTH); 1323 response_panel.add(response_scroll, BorderLayout.CENTER); 1324 details_soap = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT); 1325 details_soap.setTopComponent(request_panel); 1326 details_soap.setRightComponent(response_panel); 1327 details_soap.setResizeWeight(.5); 1328 details_panel = new JPanel (); 1329 layout_button = new JButton ("Switch Layout"); 1330 layout_button.addActionListener(this); 1331 reflow_xml = new JCheckBox ("Reflow XML text"); 1332 reflow_xml.addActionListener(this); 1333 details_buttons = new JPanel (); 1334 details_buttons.setLayout(new FlowLayout ()); 1335 details_buttons.add(reflow_xml); 1336 details_buttons.add(layout_button); 1337 details_panel.setLayout(new BorderLayout ()); 1338 details_panel.add(details_header, BorderLayout.NORTH); 1339 details_panel.add(details_soap, BorderLayout.CENTER); 1340 details_panel.add(details_buttons, BorderLayout.SOUTH); 1341 details_panel.setBorder(empty_border); 1342 1343 split = new JSplitPane (JSplitPane.VERTICAL_SPLIT); 1345 split.setTopComponent(list_panel); 1346 split.setRightComponent(details_panel); 1347 1348 start_button = new JButton ("Start"); 1350 start_button.addActionListener(this); 1351 stop_button = new JButton ("Stop"); 1352 stop_button.addActionListener(this); 1353 status_buttons = new JPanel (); 1354 status_buttons.setLayout(new FlowLayout ()); 1355 status_buttons.add(start_button); 1356 status_buttons.add(stop_button); 1357 status_text = new JLabel (); 1358 status_text.setBorder(new BevelBorder (BevelBorder.LOWERED)); 1359 status_text_panel = new JPanel (); 1360 status_text_panel.setLayout(new BorderLayout ()); 1361 status_text_panel.add(status_text, BorderLayout.CENTER); 1362 status_text_panel.setBorder(empty_border); 1363 status_area = new JPanel (); 1364 status_area.setLayout(new BorderLayout ()); 1365 status_area.add(status_buttons, BorderLayout.WEST); 1366 status_area.add(status_text_panel, BorderLayout.CENTER); 1367 status_area.setBorder(etched_border); 1368 1369 setLayout(new BorderLayout ()); 1371 add(split, BorderLayout.CENTER); 1372 add(status_area, BorderLayout.SOUTH); 1373 } 1374 1375 1380 public String getHost() { 1381 return host; 1382 } 1383 1384 1389 public void setStatus(String txt) { 1390 status_text.setForeground(Color.black); 1391 status_text.setText(" " + txt); 1392 } 1393 1394 1399 public void setErrorStatus(String txt) { 1400 status_text.setForeground(Color.red); 1401 status_text.setText(" " + txt); 1402 } 1403 1404 1407 public void start() { 1408 String codehost = axisHost; 1409 if (socket == null) { 1410 try { 1411 socket = new Socket (codehost, port); 1413 1414 out = new ObjectOutputStream (socket.getOutputStream()); 1416 out.flush(); 1417 1418 in = new ObjectInputStream (socket.getInputStream()); 1421 new Thread (this).start(); 1422 } catch (Exception e) { 1423 e.printStackTrace(); 1427 setErrorStatus(STATUS_NOCONNECT); 1428 socket = null; 1429 } 1430 } else { 1431 } 1433 if (socket != null) { 1434 start_button.setEnabled(false); 1436 stop_button.setEnabled(true); 1437 setStatus(STATUS_ACTIVE); 1438 } 1439 } 1440 1441 1444 public void stop() { 1445 if (socket != null) { 1446 if (out != null) { 1448 try { 1449 out.close(); 1450 } catch (IOException ioe) { 1451 } 1452 out = null; 1453 } 1454 if (in != null) { 1455 try { 1456 in.close(); 1457 } catch (IOException ioe) { 1458 } 1459 in = null; 1460 } 1461 if (socket != null) { 1462 try { 1463 socket.close(); 1464 } catch (IOException ioe) { 1465 } 1466 socket = null; 1467 } 1468 } else { 1469 } 1471 1472 start_button.setEnabled(true); 1474 stop_button.setEnabled(false); 1475 setStatus(STATUS_STOPPED); 1476 } 1477 1478 1482 public void run() { 1483 Long id; 1484 Integer message_type; 1485 String target; 1486 String soap; 1487 SOAPMonitorData data; 1488 int selected; 1489 int row; 1490 boolean update_needed; 1491 while (socket != null) { 1492 try { 1493 message_type = (Integer ) in.readObject(); 1495 1496 switch (message_type.intValue()) { 1498 case SOAPMonitorConstants.SOAP_MONITOR_REQUEST: 1499 1500 id = (Long ) in.readObject(); 1502 target = (String ) in.readObject(); 1503 soap = (String ) in.readObject(); 1504 1505 data = new SOAPMonitorData(id, target, soap); 1507 model.addData(data); 1508 1509 selected = table.getSelectedRow(); 1512 if ((selected == 0) && model.filterMatch(data)) { 1513 valueChanged(null); 1514 } 1515 break; 1516 case SOAPMonitorConstants.SOAP_MONITOR_RESPONSE: 1517 1518 id = (Long ) in.readObject(); 1520 soap = (String ) in.readObject(); 1521 data = model.findData(id); 1522 if (data != null) { 1523 update_needed = false; 1524 1525 selected = table.getSelectedRow(); 1527 1528 if (selected == 0) { 1531 update_needed = true; 1532 } 1533 1534 row = model.findRow(data); 1537 if ((row != -1) && (row == selected)) { 1538 update_needed = true; 1539 } 1540 1541 data.setSOAPResponse(soap); 1543 model.updateData(data); 1544 1545 if (update_needed) { 1547 valueChanged(null); 1548 } 1549 } 1550 break; 1551 } 1552 } catch (Exception e) { 1553 if (stop_button.isEnabled()) { 1556 stop(); 1557 setErrorStatus(STATUS_CLOSED); 1558 } 1559 } 1560 } 1561 } 1562 1563 1568 public void valueChanged(ListSelectionEvent e) { 1569 int row = table.getSelectedRow(); 1570 1571 if (row > 0) { 1573 remove_button.setEnabled(true); 1574 } else { 1575 remove_button.setEnabled(false); 1576 } 1577 1578 if (row == 0) { 1580 row = model.getRowCount() - 1; 1581 if (row == 0) { 1582 row = -1; 1583 } 1584 } 1585 if (row == -1) { 1586 details_time_value.setText(""); 1588 details_target_value.setText(""); 1589 details_status_value.setText(""); 1590 request_text.setText(""); 1591 response_text.setText(""); 1592 } else { 1593 SOAPMonitorData soap = model.getData(row); 1595 details_time_value.setText(soap.getTime()); 1596 details_target_value.setText(soap.getTargetService()); 1597 details_status_value.setText(soap.getStatus()); 1598 if (soap.getSOAPRequest() == null) { 1599 request_text.setText(""); 1600 } else { 1601 request_text.setText(soap.getSOAPRequest()); 1602 request_text.setCaretPosition(0); 1603 } 1604 if (soap.getSOAPResponse() == null) { 1605 response_text.setText(""); 1606 } else { 1607 response_text.setText(soap.getSOAPResponse()); 1608 response_text.setCaretPosition(0); 1609 } 1610 } 1611 } 1612 1613 1618 public void actionPerformed(ActionEvent e) { 1619 if (e.getSource() == remove_button) { 1621 int row = table.getSelectedRow(); 1622 model.removeRow(row); 1623 table.clearSelection(); 1624 table.repaint(); 1625 valueChanged(null); 1626 } 1627 1628 if (e.getSource() == remove_all_button) { 1630 model.clearAll(); 1631 table.setRowSelectionInterval(0, 0); 1632 table.repaint(); 1633 valueChanged(null); 1634 } 1635 1636 if (e.getSource() == filter_button) { 1638 filter.showDialog(); 1639 if (filter.okPressed()) { 1640 model.setFilter(filter); 1642 table.repaint(); 1643 } 1644 } 1645 1646 if (e.getSource() == start_button) { 1648 start(); 1649 } 1650 1651 if (e.getSource() == stop_button) { 1653 stop(); 1654 } 1655 1656 if (e.getSource() == layout_button) { 1658 details_panel.remove(details_soap); 1659 details_soap.removeAll(); 1660 if (details_soap.getOrientation() 1661 == JSplitPane.HORIZONTAL_SPLIT) { 1662 details_soap = new JSplitPane (JSplitPane.VERTICAL_SPLIT); 1663 } else { 1664 details_soap = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT); 1665 } 1666 details_soap.setTopComponent(request_panel); 1667 details_soap.setRightComponent(response_panel); 1668 details_soap.setResizeWeight(.5); 1669 details_panel.add(details_soap, BorderLayout.CENTER); 1670 details_panel.validate(); 1671 details_panel.repaint(); 1672 } 1673 1674 if (e.getSource() == reflow_xml) { 1676 request_text.setReflowXML(reflow_xml.isSelected()); 1677 response_text.setReflowXML(reflow_xml.isSelected()); 1678 } 1679 } 1680 } 1681 1682 1685 class SOAPMonitorData { 1686 1687 1690 private Long id; 1691 1692 1695 private String time; 1696 1697 1700 private String target; 1701 1702 1705 private String soap_request; 1706 1707 1710 private String soap_response; 1711 1712 1719 public SOAPMonitorData(Long id, String target, String soap_request) { 1720 this.id = id; 1721 1722 if (id == null) { 1725 this.time = "Most Recent"; 1726 this.target = "---"; 1727 this.soap_request = null; 1728 this.soap_response = null; 1729 } else { 1730 this.time = 1731 DateFormat.getTimeInstance().format(new Date ()); 1732 this.target = target; 1733 this.soap_request = soap_request; 1734 this.soap_response = null; 1735 } 1736 } 1737 1738 1743 public Long getId() { 1744 return id; 1745 } 1746 1747 1752 public String getTime() { 1753 return time; 1754 } 1755 1756 1761 public String getTargetService() { 1762 return target; 1763 } 1764 1765 1770 public String getStatus() { 1771 String status = "---"; 1772 if (id != null) { 1773 status = "Complete"; 1774 if (soap_response == null) { 1775 status = "Active"; 1776 } 1777 } 1778 return status; 1779 } 1780 1781 1786 public String getSOAPRequest() { 1787 return soap_request; 1788 } 1789 1790 1795 public void setSOAPResponse(String response) { 1796 soap_response = response; 1797 } 1798 1799 1804 public String getSOAPResponse() { 1805 return soap_response; 1806 } 1807 } 1808 1809 1815 class SOAPMonitorTableModel extends AbstractTableModel { 1816 1817 1820 private final String [] column_names = {"Time", "Target Service", 1821 "Status"}; 1822 1823 1826 private Vector data; 1827 1828 1831 private Vector filter_include; 1832 1833 1836 private Vector filter_exclude; 1837 1838 1841 private boolean filter_active; 1842 1843 1846 private boolean filter_complete; 1847 1848 1851 private Vector filter_data; 1852 1853 1856 public SOAPMonitorTableModel() { 1857 data = new Vector (); 1858 1859 SOAPMonitorData soap = new SOAPMonitorData(null, null, null); 1861 data.addElement(soap); 1862 filter_include = null; 1863 filter_exclude = null; 1864 filter_active = false; 1865 filter_complete = false; 1866 filter_data = null; 1867 1868 filter_exclude = new Vector (); 1871 filter_exclude.addElement("NotificationService"); 1872 filter_exclude.addElement("EventViewerService"); 1873 filter_data = new Vector (); 1874 filter_data.addElement(soap); 1875 } 1876 1877 1882 public int getColumnCount() { 1883 return column_names.length; 1884 } 1885 1886 1891 public int getRowCount() { 1892 int count = data.size(); 1893 if (filter_data != null) { 1894 count = filter_data.size(); 1895 } 1896 return count; 1897 } 1898 1899 1905 public String getColumnName(int col) { 1906 return column_names[col]; 1907 } 1908 1909 1916 public Object getValueAt(int row, int col) { 1917 SOAPMonitorData soap; 1918 String value = null; 1919 soap = (SOAPMonitorData) data.elementAt(row); 1920 if (filter_data != null) { 1921 soap = (SOAPMonitorData) filter_data.elementAt(row); 1922 } 1923 switch (col) { 1924 case 0: 1925 value = soap.getTime(); 1926 break; 1927 case 1: 1928 value = soap.getTargetService(); 1929 break; 1930 case 2: 1931 value = soap.getStatus(); 1932 break; 1933 } 1934 return value; 1935 } 1936 1937 1943 public boolean filterMatch(SOAPMonitorData soap) { 1944 boolean match = true; 1945 if (filter_include != null) { 1946 Enumeration e = filter_include.elements(); 1948 match = false; 1949 while (e.hasMoreElements() && !match) { 1950 String service = (String ) e.nextElement(); 1951 if (service.equals(soap.getTargetService())) { 1952 match = true; 1953 } 1954 } 1955 } 1956 if (filter_exclude != null) { 1957 Enumeration e = filter_exclude.elements(); 1959 while (e.hasMoreElements() && match) { 1960 String service = (String ) e.nextElement(); 1961 if (service.equals(soap.getTargetService())) { 1962 match = false; 1963 } 1964 } 1965 } 1966 if (filter_active) { 1967 if (soap.getSOAPResponse() != null) { 1969 match = false; 1970 } 1971 } 1972 if (filter_complete) { 1973 if (soap.getSOAPResponse() == null) { 1975 match = false; 1976 } 1977 } 1978 1979 if (soap.getId() == null) { 1981 match = true; 1982 } 1983 return match; 1984 } 1985 1986 1991 public void addData(SOAPMonitorData soap) { 1992 int row = data.size(); 1993 data.addElement(soap); 1994 if (filter_data != null) { 1995 if (filterMatch(soap)) { 1996 row = filter_data.size(); 1997 filter_data.addElement(soap); 1998 fireTableRowsInserted(row, row); 1999 } 2000 } else { 2001 fireTableRowsInserted(row, row); 2002 } 2003 } 2004 2005 2011 public SOAPMonitorData findData(Long id) { 2012 SOAPMonitorData soap = null; 2013 for (int row = data.size(); (row > 0) && (soap == null); row--) { 2014 soap = (SOAPMonitorData) data.elementAt(row - 1); 2015 if (soap.getId().longValue() != id.longValue()) { 2016 soap = null; 2017 } 2018 } 2019 return soap; 2020 } 2021 2022 2028 public int findRow(SOAPMonitorData soap) { 2029 int row = -1; 2030 if (filter_data != null) { 2031 row = filter_data.indexOf(soap); 2032 } else { 2033 row = data.indexOf(soap); 2034 } 2035 return row; 2036 } 2037 2038 2041 public void clearAll() { 2042 int last_row = data.size() - 1; 2043 if (last_row > 0) { 2044 data.removeAllElements(); 2045 SOAPMonitorData soap = new SOAPMonitorData(null, null, null); 2046 data.addElement(soap); 2047 if (filter_data != null) { 2048 filter_data.removeAllElements(); 2049 filter_data.addElement(soap); 2050 } 2051 fireTableDataChanged(); 2052 } 2053 } 2054 2055 2060 public void removeRow(int row) { 2061 SOAPMonitorData soap = null; 2062 if (filter_data == null) { 2063 soap = (SOAPMonitorData) data.elementAt(row); 2064 data.remove(soap); 2065 } else { 2066 soap = (SOAPMonitorData) filter_data.elementAt(row); 2067 filter_data.remove(soap); 2068 data.remove(soap); 2069 } 2070 fireTableRowsDeleted(row, row); 2071 } 2072 2073 2078 public void setFilter(SOAPMonitorFilter filter) { 2079 filter_include = filter.getFilterIncludeList(); 2081 filter_exclude = filter.getFilterExcludeList(); 2082 filter_active = filter.getFilterActive(); 2083 filter_complete = filter.getFilterComplete(); 2084 applyFilter(); 2085 } 2086 2087 2090 public void applyFilter() { 2091 filter_data = null; 2093 if ((filter_include != null) || (filter_exclude != null) 2094 || filter_active || filter_complete) { 2095 filter_data = new Vector (); 2096 Enumeration e = data.elements(); 2097 SOAPMonitorData soap; 2098 while (e.hasMoreElements()) { 2099 soap = (SOAPMonitorData) e.nextElement(); 2100 if (filterMatch(soap)) { 2101 filter_data.addElement(soap); 2102 } 2103 } 2104 } 2105 fireTableDataChanged(); 2106 } 2107 2108 2114 public SOAPMonitorData getData(int row) { 2115 SOAPMonitorData soap = null; 2116 if (filter_data == null) { 2117 soap = (SOAPMonitorData) data.elementAt(row); 2118 } else { 2119 soap = (SOAPMonitorData) filter_data.elementAt(row); 2120 } 2121 return soap; 2122 } 2123 2124 2129 public void updateData(SOAPMonitorData soap) { 2130 int row; 2131 if (filter_data == null) { 2132 row = data.indexOf(soap); 2134 if (row != -1) { 2135 fireTableRowsUpdated(row, row); 2136 } 2137 } else { 2138 row = filter_data.indexOf(soap); 2140 if (row == -1) { 2141 if (filterMatch(soap)) { 2144 int index = -1; 2145 row = data.indexOf(soap) + 1; 2146 while ((row < data.size()) && (index == -1)) { 2147 index = filter_data.indexOf(data.elementAt(row)); 2148 if (index != -1) { 2149 filter_data.add(index, soap); 2151 } 2152 row++; 2153 } 2154 if (index == -1) { 2155 index = filter_data.size(); 2157 filter_data.addElement(soap); 2158 } 2159 fireTableRowsInserted(index, index); 2160 } 2161 } else { 2162 if (filterMatch(soap)) { 2165 fireTableRowsUpdated(row, row); 2166 } else { 2167 filter_data.remove(soap); 2168 fireTableRowsDeleted(row, row); 2169 } 2170 } 2171 } 2172 } 2173 } 2174 2175 2178 class ServiceFilterPanel extends JPanel 2179 implements ActionListener , ListSelectionListener , DocumentListener { 2180 2181 2184 private JCheckBox service_box = null; 2185 2186 2189 private Vector filter_list = null; 2190 2191 2194 private Vector service_data = null; 2195 2196 2199 private JList service_list = null; 2200 2201 2204 private JScrollPane service_scroll = null; 2205 2206 2209 private JButton remove_service_button = null; 2210 2211 2214 private JPanel remove_service_panel = null; 2215 2216 2219 private EmptyBorder indent_border = null; 2220 2221 2224 private EmptyBorder empty_border = null; 2225 2226 2229 private JPanel service_area = null; 2230 2231 2234 private JPanel add_service_area = null; 2235 2236 2239 private JTextField add_service_field = null; 2240 2241 2244 private JButton add_service_button = null; 2245 2246 2249 private JPanel add_service_panel = null; 2250 2251 2257 public ServiceFilterPanel(String text, Vector list) { 2258 empty_border = new EmptyBorder (5, 5, 0, 5); 2259 indent_border = new EmptyBorder (5, 25, 5, 5); 2260 service_box = new JCheckBox (text); 2261 service_box.addActionListener(this); 2262 service_data = new Vector (); 2263 if (list != null) { 2264 service_box.setSelected(true); 2265 service_data = (Vector ) list.clone(); 2266 } 2267 service_list = new JList (service_data); 2268 service_list.setBorder(new EtchedBorder ()); 2269 service_list.setVisibleRowCount(5); 2270 service_list.addListSelectionListener(this); 2271 service_list.setEnabled(service_box.isSelected()); 2272 service_scroll = new JScrollPane (service_list); 2273 service_scroll.setBorder(new EtchedBorder ()); 2274 remove_service_button = new JButton ("Remove"); 2275 remove_service_button.addActionListener(this); 2276 remove_service_button.setEnabled(false); 2277 remove_service_panel = new JPanel (); 2278 remove_service_panel.setLayout(new FlowLayout ()); 2279 remove_service_panel.add(remove_service_button); 2280 service_area = new JPanel (); 2281 service_area.setLayout(new BorderLayout ()); 2282 service_area.add(service_scroll, BorderLayout.CENTER); 2283 service_area.add(remove_service_panel, BorderLayout.EAST); 2284 service_area.setBorder(indent_border); 2285 add_service_field = new JTextField (); 2286 add_service_field.addActionListener(this); 2287 add_service_field.getDocument().addDocumentListener(this); 2288 add_service_field.setEnabled(service_box.isSelected()); 2289 add_service_button = new JButton ("Add"); 2290 add_service_button.addActionListener(this); 2291 add_service_button.setEnabled(false); 2292 add_service_panel = new JPanel (); 2293 add_service_panel.setLayout(new BorderLayout ()); 2294 JPanel dummy = new JPanel (); 2295 dummy.setBorder(empty_border); 2296 add_service_panel.add(dummy, BorderLayout.WEST); 2297 add_service_panel.add(add_service_button, BorderLayout.EAST); 2298 add_service_area = new JPanel (); 2299 add_service_area.setLayout(new BorderLayout ()); 2300 add_service_area.add(add_service_field, BorderLayout.CENTER); 2301 add_service_area.add(add_service_panel, BorderLayout.EAST); 2302 add_service_area.setBorder(indent_border); 2303 setLayout(new BorderLayout ()); 2304 add(service_box, BorderLayout.NORTH); 2305 add(service_area, BorderLayout.CENTER); 2306 add(add_service_area, BorderLayout.SOUTH); 2307 setBorder(empty_border); 2308 } 2309 2310 2315 public Vector getServiceList() { 2316 Vector list = null; 2317 if (service_box.isSelected()) { 2318 list = service_data; 2319 } 2320 return list; 2321 } 2322 2323 2328 public void actionPerformed(ActionEvent e) { 2329 if (e.getSource() == service_box) { 2331 service_list.setEnabled(service_box.isSelected()); 2332 service_list.clearSelection(); 2333 remove_service_button.setEnabled(false); 2334 add_service_field.setEnabled(service_box.isSelected()); 2335 add_service_field.setText(""); 2336 add_service_button.setEnabled(false); 2337 } 2338 2339 if ((e.getSource() == add_service_button) 2341 || (e.getSource() == add_service_field)) { 2342 String text = add_service_field.getText(); 2343 if ((text != null) && (text.length() > 0)) { 2344 service_data.addElement(text); 2345 service_list.setListData(service_data); 2346 } 2347 add_service_field.setText(""); 2348 add_service_field.requestFocus(); 2349 } 2350 2351 if (e.getSource() == remove_service_button) { 2353 Object [] sels = service_list.getSelectedValues(); 2354 for (int i = 0; i < sels.length; i++) { 2355 service_data.removeElement(sels[i]); 2356 } 2357 service_list.setListData(service_data); 2358 service_list.clearSelection(); 2359 } 2360 } 2361 2362 2367 public void changedUpdate(DocumentEvent e) { 2368 String text = add_service_field.getText(); 2369 if ((text != null) && (text.length() > 0)) { 2370 add_service_button.setEnabled(true); 2371 } else { 2372 add_service_button.setEnabled(false); 2373 } 2374 } 2375 2376 2381 public void insertUpdate(DocumentEvent e) { 2382 changedUpdate(e); 2383 } 2384 2385 2390 public void removeUpdate(DocumentEvent e) { 2391 changedUpdate(e); 2392 } 2393 2394 2399 public void valueChanged(ListSelectionEvent e) { 2400 if (service_list.getSelectedIndex() == -1) { 2401 remove_service_button.setEnabled(false); 2402 } else { 2403 remove_service_button.setEnabled(true); 2404 } 2405 } 2406 } 2407 2408 2411 class SOAPMonitorFilter implements ActionListener { 2412 2413 2416 private JDialog dialog = null; 2417 2418 2421 private JPanel panel = null; 2422 2423 2426 private JPanel buttons = null; 2427 2428 2431 private JButton ok_button = null; 2432 2433 2436 private JButton cancel_button = null; 2437 2438 2441 private ServiceFilterPanel include_panel = null; 2442 2443 2446 private ServiceFilterPanel exclude_panel = null; 2447 2448 2451 private JPanel status_panel = null; 2452 2453 2456 private JCheckBox status_box = null; 2457 2458 2461 private EmptyBorder empty_border = null; 2462 2463 2466 private EmptyBorder indent_border = null; 2467 2468 2471 private JPanel status_options = null; 2472 2473 2476 private ButtonGroup status_group = null; 2477 2478 2481 private JRadioButton status_active = null; 2482 2483 2486 private JRadioButton status_complete = null; 2487 2488 2491 private Vector filter_include_list = null; 2492 2493 2496 private Vector filter_exclude_list = null; 2497 2498 2501 private boolean filter_active = false; 2502 2503 2506 private boolean filter_complete = false; 2507 2508 2511 private boolean ok_pressed = false; 2512 2513 2516 public SOAPMonitorFilter() { 2517 filter_exclude_list = new Vector (); 2520 filter_exclude_list.addElement("NotificationService"); 2521 filter_exclude_list.addElement("EventViewerService"); 2522 } 2523 2524 2529 public Vector getFilterIncludeList() { 2530 return filter_include_list; 2531 } 2532 2533 2538 public Vector getFilterExcludeList() { 2539 return filter_exclude_list; 2540 } 2541 2542 2547 public boolean getFilterActive() { 2548 return filter_active; 2549 } 2550 2551 2556 public boolean getFilterComplete() { 2557 return filter_complete; 2558 } 2559 2560 2563 public void showDialog() { 2564 empty_border = new EmptyBorder (5, 5, 0, 5); 2565 indent_border = new EmptyBorder (5, 25, 5, 5); 2566 include_panel = new ServiceFilterPanel( 2567 "Include messages based on target service:", 2568 filter_include_list); 2569 exclude_panel = new ServiceFilterPanel( 2570 "Exclude messages based on target service:", 2571 filter_exclude_list); 2572 status_box = new JCheckBox ("Filter messages based on status:"); 2573 status_box.addActionListener(this); 2574 status_active = new JRadioButton ("Active messages only"); 2575 status_active.setSelected(true); 2576 status_active.setEnabled(false); 2577 status_complete = new JRadioButton ("Complete messages only"); 2578 status_complete.setEnabled(false); 2579 status_group = new ButtonGroup (); 2580 status_group.add(status_active); 2581 status_group.add(status_complete); 2582 if (filter_active || filter_complete) { 2583 status_box.setSelected(true); 2584 status_active.setEnabled(true); 2585 status_complete.setEnabled(true); 2586 if (filter_complete) { 2587 status_complete.setSelected(true); 2588 } 2589 } 2590 status_options = new JPanel (); 2591 status_options.setLayout(new BoxLayout (status_options, 2592 BoxLayout.Y_AXIS)); 2593 status_options.add(status_active); 2594 status_options.add(status_complete); 2595 status_options.setBorder(indent_border); 2596 status_panel = new JPanel (); 2597 status_panel.setLayout(new BorderLayout ()); 2598 status_panel.add(status_box, BorderLayout.NORTH); 2599 status_panel.add(status_options, BorderLayout.CENTER); 2600 status_panel.setBorder(empty_border); 2601 ok_button = new JButton ("Ok"); 2602 ok_button.addActionListener(this); 2603 cancel_button = new JButton ("Cancel"); 2604 cancel_button.addActionListener(this); 2605 buttons = new JPanel (); 2606 buttons.setLayout(new FlowLayout ()); 2607 buttons.add(ok_button); 2608 buttons.add(cancel_button); 2609 panel = new JPanel (); 2610 panel.setLayout(new BoxLayout (panel, BoxLayout.Y_AXIS)); 2611 panel.add(include_panel); 2612 panel.add(exclude_panel); 2613 panel.add(status_panel); 2614 panel.add(buttons); 2615 dialog = new JDialog (); 2616 dialog.setTitle("SOAP Monitor Filter"); 2617 dialog.setContentPane(panel); 2618 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 2619 dialog.setModal(true); 2620 dialog.pack(); 2621 Dimension d = dialog.getToolkit().getScreenSize(); 2622 dialog.setLocation((d.width - dialog.getWidth()) / 2, 2623 (d.height - dialog.getHeight()) / 2); 2624 ok_pressed = false; 2625 dialog.show(); 2626 } 2627 2628 2633 public void actionPerformed(ActionEvent e) { 2634 if (e.getSource() == ok_button) { 2636 filter_include_list = include_panel.getServiceList(); 2637 filter_exclude_list = exclude_panel.getServiceList(); 2638 if (status_box.isSelected()) { 2639 filter_active = status_active.isSelected(); 2640 filter_complete = status_complete.isSelected(); 2641 } else { 2642 filter_active = false; 2643 filter_complete = false; 2644 } 2645 ok_pressed = true; 2646 dialog.dispose(); 2647 } 2648 2649 if (e.getSource() == cancel_button) { 2651 dialog.dispose(); 2652 } 2653 2654 if (e.getSource() == status_box) { 2656 status_active.setEnabled(status_box.isSelected()); 2657 status_complete.setEnabled(status_box.isSelected()); 2658 } 2659 } 2660 2661 2666 public boolean okPressed() { 2667 return ok_pressed; 2668 } 2669 } 2670 2671 2674 class SOAPMonitorTextArea extends JTextArea { 2675 2676 2679 private boolean format = false; 2680 2681 2684 private String original = ""; 2685 2686 2689 private String formatted = null; 2690 2691 2694 public SOAPMonitorTextArea() { 2695 } 2696 2697 2702 public void setText(String text) { 2703 original = text; 2704 formatted = null; 2705 if (format) { 2706 doFormat(); 2707 super.setText(formatted); 2708 } else { 2709 super.setText(original); 2710 } 2711 } 2712 2713 2718 public void setReflowXML(boolean reflow) { 2719 format = reflow; 2720 if (format) { 2721 if (formatted == null) { 2722 doFormat(); 2723 } 2724 super.setText(formatted); 2725 } else { 2726 super.setText(original); 2727 } 2728 } 2729 2730 2733 public void doFormat() { 2734 Vector parts = new Vector (); 2735 char[] chars = original.toCharArray(); 2736 int index = 0; 2737 int first = 0; 2738 String part = null; 2739 while (index < chars.length) { 2740 if (chars[index] == '<') { 2742 if (first < index) { 2744 part = new String (chars, first, index - first); 2745 part = part.trim(); 2746 2747 if (part.length() > 0) { 2749 parts.addElement(part); 2750 } 2751 } 2752 2753 first = index; 2755 } 2756 2757 if (chars[index] == '>') { 2759 part = new String (chars, first, index - first + 1); 2761 parts.addElement(part); 2762 first = index + 1; 2763 } 2764 2765 if ((chars[index] == '\n') || (chars[index] == '\r')) { 2767 if (first < index) { 2769 part = new String (chars, first, index - first); 2770 part = part.trim(); 2771 2772 if (part.length() > 0) { 2774 parts.addElement(part); 2775 } 2776 } 2777 first = index + 1; 2778 } 2779 index++; 2780 } 2781 2782 StringBuffer buf = new StringBuffer (); 2784 Object [] list = parts.toArray(); 2785 int indent = 0; 2786 int pad = 0; 2787 index = 0; 2788 while (index < list.length) { 2789 part = (String ) list[index]; 2790 if (buf.length() == 0) { 2791 buf.append(part); 2793 } else { 2794 buf.append('\n'); 2796 2797 if (part.startsWith("</")) { 2799 indent--; 2800 } 2801 2802 for (pad = 0; pad < indent; pad++) { 2804 buf.append(" "); 2805 } 2806 2807 buf.append(part); 2809 2810 if (part.startsWith("<") && !part.startsWith("</") 2812 && !part.endsWith("/>")) { 2813 indent++; 2814 2815 if ((index + 2) < list.length) { 2817 part = (String ) list[index + 2]; 2818 if (part.startsWith("</")) { 2819 part = (String ) list[index + 1]; 2820 if (!part.startsWith("<")) { 2821 buf.append(part); 2822 part = (String ) list[index + 2]; 2823 buf.append(part); 2824 index = index + 2; 2825 indent--; 2826 } 2827 } 2828 } 2829 } 2830 } 2831 index++; 2832 } 2833 formatted = new String (buf); 2834 } 2835 } 2836 2837 2842 public void actionPerformed(ActionEvent e) { 2843 Object obj = e.getSource(); 2844 if (obj == add_btn) { 2845 int selected[] = list1.getSelectedIndices(); 2846 int len = selected.length - 1; 2847 for (int i = len; i >= 0; i--) { 2848 model2.addElement(model1.getElementAt(selected[i])); 2849 model1.remove(selected[i]); 2850 } 2851 if (model1.size() == 0) { 2852 add_btn.setEnabled(false); 2853 } 2854 if (model2.size() > 0) { 2855 del_btn.setEnabled(true); 2856 } 2857 } else if (obj == del_btn) { 2858 int selected[] = list2.getSelectedIndices(); 2859 int len = selected.length - 1; 2860 for (int i = len; i >= 0; i--) { 2861 model1.addElement(model2.getElementAt(selected[i])); 2862 model2.remove(selected[i]); 2863 } 2864 if (model2.size() == 0) { 2865 del_btn.setEnabled(false); 2866 } 2867 if (model1.size() > 0) { 2868 add_btn.setEnabled(true); 2869 } 2870 } else if (obj == login_btn) { 2871 if (doLogin()) { 2872 delPage(); 2873 addPage(new SOAPMonitorPage(axisHost)); 2874 start(); 2875 } else { 2876 add_btn.setEnabled(false); 2877 del_btn.setEnabled(false); 2878 } 2879 } else if (obj == save_btn) { 2880 String service = null; 2881 Node node = null; 2882 Node impNode = null; 2883 Document wsdd = null; 2884 JOptionPane pane = null; 2885 JDialog dlg = null; 2886 String msg = null; 2887 final String title = "Deployment status"; 2888 final String deploy = "<deployment name=\"SOAPMonitor\"" 2889 + " xmlns=\"http://xml.apache.org/axis/wsdd/\"" 2890 + " xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\">\n" 2891 + " <handler name=\"soapmonitor\"" 2892 + " type=\"java:org.apache.axis.handlers.SOAPMonitorHandler\" />\n" 2893 + " </deployment>"; 2894 2895 try { 2897 wsdd = XMLUtils.newDocument( 2898 new ByteArrayInputStream (deploy.getBytes())); 2899 } catch (Exception ex) { 2900 ex.printStackTrace(); 2901 } 2902 Collection col = serviceMap.keySet(); 2903 Iterator ite = col.iterator(); 2904 2905 while (ite.hasNext()) { 2907 service = (String ) ite.next(); 2908 node = (Node ) serviceMap.get(service); 2909 if (model2.contains(service)) { 2910 if (isMonitored(node)) { impNode = wsdd.importNode(node, true); 2912 } else { impNode = wsdd.importNode(addMonitor(node), true); 2914 } 2915 } else { 2916 if (isMonitored(node)) { impNode = wsdd.importNode(delMonitor(node), true); 2918 } else { impNode = wsdd.importNode(node, true); 2920 } 2921 } 2922 if (service.equals("AdminService")) { 2923 impNode = wsdd.importNode(addAuthenticate(impNode), true); 2926 } 2927 wsdd.getDocumentElement().appendChild(impNode); 2928 } 2929 2930 pane = new JOptionPane (); 2932 if (doDeploy(wsdd)) { 2933 msg = "The deploy was successful."; 2934 pane.setMessageType(JOptionPane.INFORMATION_MESSAGE); 2935 } else { 2936 msg = "The deploy was NOT successful."; 2937 pane.setMessageType(JOptionPane.WARNING_MESSAGE); 2938 } 2939 pane.setOptions(new String []{"OK"}); 2940 pane.setMessage(msg); 2941 dlg = pane.createDialog(null, title); 2942 dlg.setVisible(true); 2943 } 2944 } 2945 2946 2951 public void stateChanged( javax.swing.event.ChangeEvent e ){ 2952 JTabbedPane tab = (JTabbedPane )e.getSource(); 2953 int item = tab.getSelectedIndex(); 2954 if (item==1) { start(); 2956 } else { stop(); 2958 } 2959 } 2960} 2961 | Popular Tags |