| 1 16 17 import java.awt.*; 18 import java.awt.event.*; 19 import java.io.*; 20 import java.net.*; 21 import java.text.*; 22 import java.util.*; 23 import javax.swing.*; 24 import javax.swing.border.*; 25 import javax.swing.event.*; 26 import javax.swing.table.*; 27 28 import org.apache.axis.monitor.SOAPMonitorConstants; 29 30 38 public class SOAPMonitorApplet extends JApplet { 39 40 43 private JPanel main_panel = null; 44 private JTabbedPane tabbed_pane = null; 45 private int port = 0; 46 private Vector pages = null; 47 48 51 public SOAPMonitorApplet() { 52 } 53 54 57 public void init() { 58 String port_str = getParameter("port"); 60 if (port_str != null) { 61 port = Integer.parseInt(port_str); 62 } 63 try { 65 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 66 } catch (Exception e){ 67 } 68 main_panel = new JPanel(); 70 main_panel.setBackground(Color.white); 71 main_panel.setLayout(new BorderLayout()); 72 setContentPane(main_panel); 73 tabbed_pane = new JTabbedPane(JTabbedPane.TOP); 75 main_panel.add(tabbed_pane,BorderLayout.CENTER); 76 pages = new Vector(); 78 addPage(new SOAPMonitorPage(getCodeBase().getHost())); 79 } 80 81 84 private void addPage(SOAPMonitorPage pg) { 85 tabbed_pane.addTab(" "+pg.getHost()+" ", pg); 86 pages.addElement(pg); 87 } 88 89 92 public void start() { 93 Enumeration e = pages.elements(); 95 while (e.hasMoreElements()) { 96 SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement(); 97 if (pg != null) { 98 pg.start(); 99 } 100 } 101 } 102 103 106 public void stop() { 107 Enumeration e = pages.elements(); 109 while (e.hasMoreElements()) { 110 SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement(); 111 if (pg != null) { 112 pg.stop(); 113 } 114 } 115 } 116 117 120 public void destroy() { 121 tabbed_pane = null; 122 main_panel = null; 123 } 124 125 129 class SOAPMonitorPage extends JPanel 130 implements Runnable , 131 ListSelectionListener, 132 ActionListener { 133 134 137 private final String STATUS_ACTIVE = "The SOAP Monitor is started."; 138 private final String STATUS_STOPPED = "The SOAP Monitor is stopped."; 139 private final String STATUS_CLOSED = "The server communication has been terminated."; 140 private final String STATUS_NOCONNECT = "The SOAP Monitor is unable to communcate with the server."; 141 142 145 private String host = null; 146 private Socket socket = null; 147 private ObjectInputStream in = null; 148 private ObjectOutputStream out = null; 149 private SOAPMonitorTableModel model = null; 150 private JTable table = null; 151 private JScrollPane scroll = null; 152 private JPanel list_panel = null; 153 private JPanel list_buttons = null; 154 private JButton remove_button = null; 155 private JButton remove_all_button = null; 156 private JButton filter_button = null; 157 private JPanel details_panel = null; 158 private JPanel details_header = null; 159 private JSplitPane details_soap = null; 160 private JPanel details_buttons = null; 161 private JLabel details_time = null; 162 private JLabel details_target = null; 163 private JLabel details_status = null; 164 private JLabel details_time_value = null; 165 private JLabel details_target_value = null; 166 private JLabel details_status_value = null; 167 private EmptyBorder empty_border = null; 168 private EtchedBorder etched_border = null; 169 private JPanel request_panel = null; 170 private JPanel response_panel = null; 171 private JLabel request_label = null; 172 private JLabel response_label = null; 173 private SOAPMonitorTextArea request_text = null; 174 private SOAPMonitorTextArea response_text = null; 175 private JScrollPane request_scroll = null; 176 private JScrollPane response_scroll = null; 177 private JButton layout_button = null; 178 private JSplitPane split = null; 179 private JPanel status_area = null; 180 private JPanel status_buttons = null; 181 private JButton start_button = null; 182 private JButton stop_button = null; 183 private JLabel status_text = null; 184 private JPanel status_text_panel = null; 185 private SOAPMonitorFilter filter = null; 186 private GridBagLayout details_header_layout = null; 187 private GridBagConstraints details_header_constraints = null; 188 private JCheckBox reflow_xml = null; 189 190 193 public SOAPMonitorPage(String host_name) { 194 host = host_name; 195 filter = new SOAPMonitorFilter(); 197 etched_border = new EtchedBorder(); 199 model = new SOAPMonitorTableModel(); 201 table = new JTable(model); 202 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 203 table.setRowSelectionInterval(0,0); 204 table.setPreferredScrollableViewportSize(new Dimension(600, 96)); 205 table.getSelectionModel().addListSelectionListener(this); 206 scroll = new JScrollPane(table); 207 remove_button = new JButton("Remove"); 208 remove_button.addActionListener(this); 209 remove_button.setEnabled(false); 210 remove_all_button = new JButton("Remove All"); 211 remove_all_button.addActionListener(this); 212 filter_button = new JButton("Filter ..."); 213 filter_button.addActionListener(this); 214 list_buttons = new JPanel(); 215 list_buttons.setLayout(new FlowLayout()); 216 list_buttons.add(remove_button); 217 list_buttons.add(remove_all_button); 218 list_buttons.add(filter_button); 219 list_panel = new JPanel(); 220 list_panel.setLayout(new BorderLayout()); 221 list_panel.add(scroll,BorderLayout.CENTER); 222 list_panel.add(list_buttons, BorderLayout.SOUTH); 223 list_panel.setBorder(empty_border); 224 details_time = new JLabel("Time: ", SwingConstants.RIGHT); 226 details_target = new JLabel("Target Service: ", SwingConstants.RIGHT); 227 details_status = new JLabel("Status: ", SwingConstants.RIGHT); 228 details_time_value = new JLabel(); 229 details_target_value = new JLabel(); 230 details_status_value = new JLabel(); 231 Dimension preferred_size = details_time.getPreferredSize(); 232 preferred_size.width = 1; 233 details_time.setPreferredSize(preferred_size); 234 details_target.setPreferredSize(preferred_size); 235 details_status.setPreferredSize(preferred_size); 236 details_time_value.setPreferredSize(preferred_size); 237 details_target_value.setPreferredSize(preferred_size); 238 details_status_value.setPreferredSize(preferred_size); 239 details_header = new JPanel(); 240 details_header_layout = new GridBagLayout(); 241 details_header.setLayout(details_header_layout); 242 details_header_constraints = new GridBagConstraints(); 243 details_header_constraints.fill=GridBagConstraints.BOTH; 244 details_header_constraints.weightx=0.5; 245 details_header_layout.setConstraints(details_time,details_header_constraints); 246 details_header.add(details_time); 247 details_header_layout.setConstraints(details_time_value,details_header_constraints); 248 details_header.add(details_time_value); 249 details_header_layout.setConstraints(details_target,details_header_constraints); 250 details_header.add(details_target); 251 details_header_constraints.weightx=1.0; 252 details_header_layout.setConstraints(details_target_value,details_header_constraints); 253 details_header.add(details_target_value); 254 details_header_constraints.weightx=.5; 255 details_header_layout.setConstraints(details_status,details_header_constraints); 256 details_header.add(details_status); 257 details_header_layout.setConstraints(details_status_value,details_header_constraints); 258 details_header.add(details_status_value); 259 details_header.setBorder(etched_border); 260 request_label = new JLabel("SOAP Request", SwingConstants.CENTER); 261 request_text = new SOAPMonitorTextArea(); 262 request_text.setEditable(false); 263 request_scroll = new JScrollPane(request_text); 264 request_panel = new JPanel(); 265 request_panel.setLayout(new BorderLayout()); 266 request_panel.add(request_label, BorderLayout.NORTH); 267 request_panel.add(request_scroll, BorderLayout.CENTER); 268 response_label = new JLabel("SOAP Response", SwingConstants.CENTER); 269 response_text = new SOAPMonitorTextArea(); 270 response_text.setEditable(false); 271 response_scroll = new JScrollPane(response_text); 272 response_panel = new JPanel(); 273 response_panel.setLayout(new BorderLayout()); 274 response_panel.add(response_label, BorderLayout.NORTH); 275 response_panel.add(response_scroll, BorderLayout.CENTER); 276 details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); 277 details_soap.setTopComponent(request_panel); 278 details_soap.setRightComponent(response_panel); 279 details_soap.setResizeWeight(.5); 280 details_panel = new JPanel(); 281 layout_button = new JButton("Switch Layout"); 282 layout_button.addActionListener(this); 283 reflow_xml = new JCheckBox("Reflow XML text"); 284 reflow_xml.addActionListener(this); 285 details_buttons = new JPanel(); 286 details_buttons.setLayout(new FlowLayout()); 287 details_buttons.add(reflow_xml); 288 details_buttons.add(layout_button); 289 details_panel.setLayout(new BorderLayout()); 290 details_panel.add(details_header,BorderLayout.NORTH); 291 details_panel.add(details_soap,BorderLayout.CENTER); 292 details_panel.add(details_buttons,BorderLayout.SOUTH); 293 details_panel.setBorder(empty_border); 294 split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); 296 split.setTopComponent(list_panel); 297 split.setRightComponent(details_panel); 298 start_button = new JButton("Start"); 300 start_button.addActionListener(this); 301 stop_button = new JButton("Stop"); 302 stop_button.addActionListener(this); 303 status_buttons = new JPanel(); 304 status_buttons.setLayout(new FlowLayout()); 305 status_buttons.add(start_button); 306 status_buttons.add(stop_button); 307 status_text = new JLabel(); 308 status_text.setBorder(new BevelBorder(BevelBorder.LOWERED)); 309 status_text_panel = new JPanel(); 310 status_text_panel.setLayout(new BorderLayout()); 311 status_text_panel.add(status_text, BorderLayout.CENTER); 312 status_text_panel.setBorder(empty_border); 313 status_area = new JPanel(); 314 status_area.setLayout(new BorderLayout()); 315 status_area.add(status_buttons, BorderLayout.WEST); 316 status_area.add(status_text_panel, BorderLayout.CENTER); 317 status_area.setBorder(etched_border); 318 setLayout(new BorderLayout()); 320 add(split, BorderLayout.CENTER); 321 add(status_area, BorderLayout.SOUTH); 322 } 323 324 327 public String getHost() { 328 return host; 329 } 330 331 334 public void setStatus(String txt) { 335 status_text.setForeground(Color.black); 336 status_text.setText(" "+txt); 337 } 338 339 342 public void setErrorStatus(String txt) { 343 status_text.setForeground(Color.red); 344 status_text.setText(" "+txt); 345 } 346 347 350 public void start() { 351 String codehost = getCodeBase().getHost(); 352 if (socket == null) { 353 try { 354 socket = new Socket(codehost, port); 356 out = new ObjectOutputStream(socket.getOutputStream()); 358 out.flush(); 359 in = new ObjectInputStream(socket.getInputStream()); 362 new Thread (this).start(); 363 } catch (Exception e) { 364 System.out.println("Exception! "+e.toString()); 368 e.printStackTrace(); 369 setErrorStatus(STATUS_NOCONNECT); 370 socket = null; 371 } 372 } else { 373 } 375 if (socket != null) { 376 start_button.setEnabled(false); 378 stop_button.setEnabled(true); 379 setStatus(STATUS_ACTIVE); 380 } 381 } 382 383 386 public void stop() { 387 if (socket != null) { 388 if (out != null) { 390 try { 391 out.close(); 392 } catch (IOException ioe) { 393 } 394 out = null; 395 } 396 if (in != null) { 397 try { 398 in.close(); 399 } catch (IOException ioe) { 400 } 401 in = null; 402 } 403 if (socket != null) { 404 try { 405 socket.close(); 406 } catch (IOException ioe) { 407 } 408 socket = null; 409 } 410 } else { 411 } 413 start_button.setEnabled(true); 415 stop_button.setEnabled(false); 416 setStatus(STATUS_STOPPED); 417 } 418 419 423 public void run() { 424 Long id; 425 Integer message_type; 426 String target; 427 String soap; 428 SOAPMonitorData data; 429 int selected; 430 int row; 431 boolean update_needed; 432 while (socket != null) { 433 try { 434 message_type = (Integer ) in.readObject(); 436 switch (message_type.intValue()) { 438 case SOAPMonitorConstants.SOAP_MONITOR_REQUEST: 439 id = (Long ) in.readObject(); 441 target = (String ) in.readObject(); 442 soap = (String ) in.readObject(); 443 data = new SOAPMonitorData(id,target,soap); 445 model.addData(data); 446 selected = table.getSelectedRow(); 449 if ((selected == 0) && model.filterMatch(data)) { 450 valueChanged(null); 451 } 452 break; 453 case SOAPMonitorConstants.SOAP_MONITOR_RESPONSE: 454 id = (Long ) in.readObject(); 456 soap = (String ) in.readObject(); 457 data = model.findData(id); 458 if (data != null) { 459 update_needed = false; 460 selected = table.getSelectedRow(); 462 if (selected == 0) { 465 update_needed = true; 466 } 467 row = model.findRow(data); 470 if ((row != -1) && (row == selected)) { 471 update_needed = true; 472 } 473 data.setSOAPResponse(soap); 475 model.updateData(data); 476 if (update_needed) { 478 valueChanged(null); 479 } 480 } 481 break; 482 } 483 484 } catch (Exception e) { 485 if (stop_button.isEnabled()) { 488 stop(); 489 setErrorStatus(STATUS_CLOSED); 490 } 491 } 492 } 493 } 494 495 498 public void valueChanged(ListSelectionEvent e) { 499 int row = table.getSelectedRow(); 500 if (row > 0) { 502 remove_button.setEnabled(true); 503 } else { 504 remove_button.setEnabled(false); 505 } 506 if (row == 0) { 508 row = model.getRowCount() - 1; 509 if (row == 0) { 510 row = -1; 511 } 512 } 513 if (row == -1) { 514 details_time_value.setText(""); 516 details_target_value.setText(""); 517 details_status_value.setText(""); 518 request_text.setText(""); 519 response_text.setText(""); 520 } else { 521 SOAPMonitorData soap = model.getData(row); 523 details_time_value.setText(soap.getTime()); 524 details_target_value.setText(soap.getTargetService()); 525 details_status_value.setText(soap.getStatus()); 526 if (soap.getSOAPRequest() == null) { 527 request_text.setText(""); 528 } else { 529 request_text.setText(soap.getSOAPRequest()); 530 request_text.setCaretPosition(0); 531 } 532 if (soap.getSOAPResponse() == null) { 533 response_text.setText(""); 534 } else { 535 response_text.setText(soap.getSOAPResponse()); 536 response_text.setCaretPosition(0); 537 } 538 } 539 } 540 541 544 public void actionPerformed(ActionEvent e) { 545 if (e.getSource() == remove_button) { 547 int row = table.getSelectedRow(); 548 model.removeRow(row); 549 table.clearSelection(); 550 table.repaint(); 551 valueChanged(null); 552 } 553 if (e.getSource() == remove_all_button) { 555 model.clearAll(); 556 table.setRowSelectionInterval(0,0); 557 table.repaint(); 558 valueChanged(null); 559 } 560 if (e.getSource() == filter_button) { 562 filter.showDialog(); 563 if (filter.okPressed()) { 564 model.setFilter(filter); 566 table.repaint(); 567 } 568 } 569 if (e.getSource() == start_button) { 571 start(); 572 } 573 if (e.getSource() == stop_button) { 575 stop(); 576 } 577 if (e.getSource() == layout_button) { 579 details_panel.remove(details_soap); 580 details_soap.removeAll(); 581 if (details_soap.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { 582 details_soap = new JSplitPane(JSplitPane.VERTICAL_SPLIT); 583 } else { 584 details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); 585 } 586 details_soap.setTopComponent(request_panel); 587 details_soap.setRightComponent(response_panel); 588 details_soap.setResizeWeight(.5); 589 details_panel.add(details_soap, BorderLayout.CENTER); 590 details_panel.validate(); 591 details_panel.repaint(); 592 } 593 if (e.getSource() == reflow_xml) { 595 request_text.setReflowXML(reflow_xml.isSelected()); 596 response_text.setReflowXML(reflow_xml.isSelected()); 597 } 598 } 599 } 600 601 604 class SOAPMonitorData { 605 606 609 private Long id; 610 private String time; 611 private String target; 612 private String soap_request; 613 private String soap_response; 614 615 618 public SOAPMonitorData(Long id, String target, String soap_request) { 619 this.id = id; 620 if (id == null) { 623 this.time = "Most Recent"; 624 this.target = "---"; 625 this.soap_request = null; 626 this.soap_response = null; 627 } else { 628 this.time = DateFormat.getTimeInstance().format(new Date()); 629 this.target = target; 630 this.soap_request = soap_request; 631 this.soap_response = null; 632 } 633 } 634 635 638 public Long getId() { 639 return id; 640 } 641 642 645 public String getTime() { 646 return time; 647 } 648 649 652 public String getTargetService() { 653 return target; 654 } 655 656 659 public String getStatus() { 660 String status = "---"; 661 if (id != null) { 662 status = "Complete"; 663 if (soap_response == null) { 664 status = "Active"; 665 } 666 } 667 return status; 668 } 669 670 673 public String getSOAPRequest() { 674 return soap_request; 675 } 676 677 680 public void setSOAPResponse(String response) { 681 soap_response = response; 682 } 683 684 687 public String getSOAPResponse() { 688 return soap_response; 689 } 690 } 691 692 698 class SOAPMonitorTableModel extends AbstractTableModel { 699 700 703 private final String [] column_names = { "Time", 704 "Target Service", 705 "Status" }; 706 709 private Vector data; 710 private Vector filter_include; 711 private Vector filter_exclude; 712 private boolean filter_active; 713 private boolean filter_complete; 714 private Vector filter_data; 715 716 719 public SOAPMonitorTableModel() { 720 data = new Vector(); 721 SOAPMonitorData soap = new SOAPMonitorData(null,null,null); 723 data.addElement(soap); 724 filter_include = null; 725 filter_exclude = null; 726 filter_active = false; 727 filter_complete = false; 728 filter_data = null; 729 filter_exclude = new Vector(); 732 filter_exclude.addElement("NotificationService"); 733 filter_exclude.addElement("EventViewerService"); 734 filter_data = new Vector(); 735 filter_data.addElement(soap); 736 } 737 738 741 public int getColumnCount() { 742 return column_names.length; 743 } 744 745 748 public int getRowCount() { 749 int count = data.size(); 750 if (filter_data != null) { 751 count = filter_data.size(); 752 } 753 return count; 754 } 755 756 759 public String getColumnName(int col) { 760 return column_names[col]; 761 } 762 763 766 public Object getValueAt(int row, int col) { 767 SOAPMonitorData soap; 768 String value = null; 769 soap = (SOAPMonitorData) data.elementAt(row); 770 if (filter_data != null) { 771 soap = (SOAPMonitorData) filter_data.elementAt(row); 772 } 773 switch (col) { 774 case 0: 775 value = soap.getTime(); 776 break; 777 case 1: 778 &n
|