| 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  |