You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by ja...@apache.org on 2003/12/18 03:39:18 UTC

cvs commit: ws-fx/sandesha/src/apache/sandesha WSRMMonitor.java

jaliya      2003/12/17 18:39:18

  Added:       sandesha/src/apache/sandesha WSRMMonitor.java
  Log:
  
  
  Revision  Changes    Path
  1.1                  ws-fx/sandesha/src/apache/sandesha/WSRMMonitor.java
  
  Index: WSRMMonitor.java
  ===================================================================
  package org.apache.sandesha;
  
  
  import org.apache.axis.Message;
  import org.apache.axis.message.SOAPEnvelope;
  import org.apache.axis.message.SOAPHeaderElement;
  
  import javax.swing.*;
  import javax.xml.soap.Name;
  import javax.xml.soap.SOAPElement;
  import java.io.*;
  import java.net.ServerSocket;
  import java.net.Socket;
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.awt.*;
  import java.awt.event.ActionEvent;
  
  /**
   * WSRMMonitor Catches the SOAP messages sent to the ServerEndPoninManager by the ClientEndPointManager.
   * If the user needs he can modify, block, change the order of invokation, etc. using the WSRMMonitor class
   */
  public class WSRMMonitor extends JFrame implements java.awt.event.ActionListener {
      // private static BufferedWriter logFile;
      private static final String NAME_OF_PROJECT = "Sandesha WS-RM MONITOR";
      private static final int MONITORPORT = 8080;
      private static final int maxMessages = 10;
      private static final int maxRetarnsmission=10;
  
      private static int simpleLastMessageNo;
      private static JTabbedPane tabbedPane = new JTabbedPane();
      private static JPanel statusPanel = new JPanel();
  
      private static JPanel simplePanel = new JPanel(null);
      private static JPanel advancedPanel = new JPanel(null);
      private static JTabbedPane messageTabbedPane = new JTabbedPane();
  
      private void tabbedPaneinitiate() {
          tabbedPane.removeAll();
          tabbedPane.addTab("Simple", simplePanel);
          tabbedPane.addTab("Advanced", advancedPanel);
          tabbedPane.addTab("Message", messageTabbedPane);
      }
  
      private static JLabel[] simplePanelLables = new JLabel[maxMessages];
      private static JTextField[] simplePanelTextFields = new JTextField[maxMessages];
      private static JLabel[] simplePanelMessageLables = new JLabel[maxMessages];
  
      private void simplePanelInitiate() {
          simplePanel.removeAll();
          for (int i = 0; i < maxMessages; i++) {
              simplePanelLables[i] = new JLabel("Message No:" + (i + 1));
              simplePanelTextFields[i] = new JTextField();
              simplePanelMessageLables[i] = new JLabel();
  
              simplePanelLables[i].setBounds(10, 10 + i * 30, 100, 20);
              simplePanelTextFields[i].setBounds(120, 10 + i * 30, 40, 20);
              simplePanelMessageLables[i].setBounds(170, 10 + i * 30, 50, 20);
  
              simplePanel.add(simplePanelLables[i]);
              simplePanel.add(simplePanelTextFields[i]);
              simplePanel.add(simplePanelMessageLables[i]);
          }
      }
  
      private static JLabel[] advancedPanelLables = new JLabel[maxMessages];
      private static JCheckBox[][] advancedPanelCheckBoxes = new JCheckBox[maxRetarnsmission][maxMessages];
  
      private void advancedPanelInitiate() {
          advancedPanel.removeAll();
          for (int i = 0; i < maxMessages; i++) {
              advancedPanelLables[i] = new JLabel("Msg#:" + (i + 1));
              advancedPanelLables[i].setBounds(10, 10 + i * 30, 60, 20);
              advancedPanel.add(advancedPanelLables[i]);
  
              for (int j = 0; j < maxRetarnsmission; j++) {
                  advancedPanelCheckBoxes[j][i] = new JCheckBox("Re#:" + (j + 1));
                  advancedPanelCheckBoxes[j][i].setBounds(70 + j * 70, 10 + i * 30, 70, 20);
                  advancedPanelCheckBoxes[j][i].setSelected(true);
                  advancedPanel.add(advancedPanelCheckBoxes[j][i]);
              }
          }
      }
  
      private static JTabbedPane[] messageTabbedPanels = new JTabbedPane[maxMessages];
  
      private void messageTabbedPanelInitiate() {
          messageTabbedPane.removeAll();
          for (int i = 0; i < maxMessages; i++) {
              messageTabbedPanels[i] = new JTabbedPane();
              messageTabbedPane.addTab("No::" + (i + 1), messageTabbedPanels[i]);
          }
      }
  
      private void menuInitiate() {
          JMenuBar menuBar = new JMenuBar();
  
          JMenu fileMenu = new JMenu("File");
          JMenuItem fileNewMenuItem = new JMenuItem("New");
          fileMenu.add(fileNewMenuItem);
          JMenuItem fileExitMenuItem = new JMenuItem("Exit");
          fileMenu.add(fileExitMenuItem);
          menuBar.add(fileMenu);
  
          JMenu configMenu = new JMenu("Config");
          menuBar.add(configMenu);
  
          this.setJMenuBar(menuBar);
      }
  
      private static JButton resetButton = new JButton("Reset");
      private static JLabel lastOrderLabel = new JLabel();
  
      private static JCheckBox considerOrderForRetrasmissionCheckBox = new JCheckBox("Consider Order For Retrasmission");
  
      private void statusPanelInitiate() {
          lastOrderLabel.setText("Last Order:" + simpleLastMessageNo);
          resetButton.addActionListener(this);
  
          statusPanel.add(considerOrderForRetrasmissionCheckBox);
          statusPanel.add(resetButton);
          statusPanel.add(lastOrderLabel);
      }
  
      public void actionPerformed(ActionEvent e) {
          //System.out.println(e.getActionCommand());
          if (e.getActionCommand().equals("Reset")) {
              simpleLastMessageNo = 0;
              simplePanelInitiate();
              advancedPanelInitiate();
              messageTabbedPanelInitiate();
              tabbedPaneinitiate();
              statusPanelInitiate();
              messageNo = new LinkedList();
              lastRetransmession = new LinkedList();
          }
      }
  
      public WSRMMonitor() {
          super(NAME_OF_PROJECT);
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          simpleLastMessageNo = 0;
          advancedPanelInitiate();
          simplePanelInitiate();
          messageTabbedPanelInitiate();
          tabbedPaneinitiate();
          menuInitiate();
          statusPanelInitiate();
          this.getContentPane().add(statusPanel, BorderLayout.SOUTH);
          this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
          this.setSize(800, 700);
          this.show();
  
          ConnectionListner cl = new ConnectionListner();
          cl.start();
  
          // File logFile=new File("monitor.log");
      }
  
      class ConnectionListner extends Thread {
          public void run() {
              try {
                  ServerSocket serverSocket = new ServerSocket(MONITORPORT);
                  Socket socket = new Socket();
                  while (true) {
                      socket = serverSocket.accept();
                      Connections c = new Connections(socket);
                      c.start();
                  }
              } catch (IOException e) {
                  e.printStackTrace();  //To change body of catch statement use Options | File Templates.
              }
          }
      }
  
      private static synchronized void doActionInList(SOAPElement soapElement) {
          int index = messageNo.indexOf(soapElement.getValue());
          if (index >= 0) {
              Integer i = (Integer) lastRetransmession.get(index);
              Integer newInt = new Integer((i.intValue() + 1));
              lastRetransmession.set(index, newInt);
  //            //System.out.println("MessageNo::" + messageNo.get(index) + " Retransmission::" + lastRetransmession.get(index));
          } else {
              messageNo.add(soapElement.getValue());
              int newIndex = messageNo.indexOf(soapElement.getValue());
              Integer i = new Integer(1);
              lastRetransmession.add(newIndex, (Object) i);
  //            //System.out.println("MessageNo::" + messageNo.get(newIndex) + " Retransmission::" + lastRetransmession.get(newIndex));
          }
      }
  
      public static java.util.LinkedList messageNo = new LinkedList();
      public static java.util.LinkedList lastRetransmession = new LinkedList();
  
      static class Connections extends Thread {
          private Socket socket;
  
          public Connections(Socket socket) {
              this.socket = socket;
          }
  
          public void run() {
              InputStream is = null;
              OutputStream os = null;
              OutputStream nextOS = null;
              InputStream nextIS = null;
              JPanel panel = null;// = new JPanel(null);
  
              try {
                  is = socket.getInputStream();
                  while (is.available() <= 0) {
                      try {
                          Thread.sleep(200L);
                      } catch (InterruptedException e) {
                          e.printStackTrace();  //To change body of catch statement use Options | File Templates.
                      }
                  }
                  byte[] b = new byte[is.available()];
                  is.read(b);
                  String str = new String(b);
                  int start = str.indexOf("<");
                  int end = str.length();
                  char[] charEnvelope = new char[end - start];
                  str.getChars(start, end, charEnvelope, 0);
                  String stringEnvelope = new String(charEnvelope);
                  Message message = new Message(stringEnvelope);
                  SOAPEnvelope soapEnvelope = message.getSOAPEnvelope();
                  SOAPHeaderElement seqHeader = soapEnvelope.getHeaderByName("http://schemas.xmlsoap.org/ws/2003/03/rm", "Sequence");
                  SOAPHeaderElement ackHeader = soapEnvelope.getHeaderByName("http://schemas.xmlsoap.org/ws/2003/03/rm", "AckRequested");
                  //
  
  
                  //
                  if (seqHeader != null) {
                      Iterator iterator = seqHeader.getChildElements();
                      SOAPElement messageNoSOAPElement = null;
                      SOAPElement IDSOAPElement = null;
                      while (iterator.hasNext()) {
                          SOAPElement soapElement = (SOAPElement) iterator.next();
                          Name name = soapElement.getElementName();
                          if (name.getLocalName().equals("MessageNumber")) {
                              //System.out.println("Message:::" + soapElement.getValue());
                              messageNoSOAPElement = soapElement;
                          }
                          if (name.getLocalName().equals("Identifier")) {
                              //System.out.println("Identifier::" + soapElement.getValue());
                              IDSOAPElement = soapElement;
                          }
                      }
                      if (ackHeader != null) {
                          doActionInList(messageNoSOAPElement);
                          int index = messageNo.indexOf(messageNoSOAPElement.getValue());
                          String txt = "MessageNo::" + messageNo.get(index) + " Retransmission::" + lastRetransmession.get(index);
                          //System.out.println(txt);
  
  
                          int intMessageNo = (new Integer(messageNo.get(index).toString())).intValue() - 1;
                          int intRetransmissionNo = (new Integer(lastRetransmession.get(index).toString())).intValue() - 1;
                          if (intMessageNo < maxMessages) {
                              //
                              panel = new JPanel(null);
                              messageTabbedPanels[intMessageNo].addTab("Re:" + (intRetransmissionNo + 1), panel);
                              JTextArea textArea = new JTextArea();
                              textArea.setLineWrap(true);
                              textArea.setText(str);
                              JScrollPane scrollPane = new JScrollPane(textArea);
                              scrollPane.setBounds(10, 35, 550, 205);
                              panel.add(scrollPane);
                              JLabel label = new JLabel("Request Message:");
                              label.setBounds(10, 10, 200, 20);
                              panel.add(label);
                              //
                              Integer order;
                              while (true) {
  
                                  if (considerOrderForRetrasmissionCheckBox.isSelected()) {
                                      String stringOrder = simplePanelTextFields[intMessageNo].getText().trim();
                                      try {
                                          order = new Integer(stringOrder);
                                      } catch (Exception e) {
                                          order = new Integer(-1);
                                      }
                                      if (simpleLastMessageNo == (order.intValue() - 1) && (advancedPanelCheckBoxes[intRetransmissionNo][intMessageNo].isSelected())) {
  
                                          simpleLastMessageNo++;
                                          lastOrderLabel.setText("Last Order:" + simpleLastMessageNo);
                                          break;
                                      }
                                  } else {
                                      if (intRetransmissionNo < maxRetarnsmission) {
                                          if (advancedPanelCheckBoxes[intRetransmissionNo][intMessageNo].isSelected()) {
  
                                              break;
                                          }
                                      } else{
                                          break;
                                      }
  
                                  }
  
                              }
  
                              try {
                                  Thread.sleep(20L);
                              } catch (InterruptedException e) {
                                  e.printStackTrace();  //To change body of catch statement use Options | File Templates.
                              }
                              if (intRetransmissionNo < maxRetarnsmission) {
                                  advancedPanelCheckBoxes[intRetransmissionNo][intMessageNo].setForeground(new Color(002222)); //; ;// Foreground(new Color(22, 33, 44));
                              }
  
  
  
  
                              /*if (intRetransmissionNo < 3) {
                                  while (!advancedPanelCheckBoxes[intRetransmissionNo][intMessageNo].isSelected()) {
                                      try {
                                          Thread.sleep(20L);
                                      } catch (InterruptedException e) {
                                          e.printStackTrace();  //To change body of catch statement use Options | File Templates.
                                      }
                                  }
                                  advancedPanelCheckBoxes[intRetransmissionNo][intMessageNo].setForeground(new Color(002222)); //; ;// Foreground(new Color(22, 33, 44));
                              } */
                          }
  
  
                      } else {
  
                          Integer index = new Integer(messageNoSOAPElement.getValue());
                          //System.out.println(simplePanelTextFields[index.intValue() - 1].getText());
                          if (index.intValue() <= maxMessages) {
                              //
                              panel = new JPanel(null);
                              messageTabbedPanels[index.intValue() - 1].addTab("First", panel);
                              JTextArea textArea = new JTextArea();
                              textArea.setLineWrap(true);
                              textArea.setText(str);
                              JScrollPane scrollPane = new JScrollPane(textArea);
                              scrollPane.setBounds(10, 35, 550, 205);
                              panel.add(scrollPane);
                              JLabel label = new JLabel("Request Message:");
                              label.setBounds(10, 10, 200, 20);
                              panel.add(label);
                              //
                              Integer order;
                              do {
                                  String stringOrder = simplePanelTextFields[index.intValue() - 1].getText().trim();
                                  try {
                                      order = new Integer(stringOrder);
                                  } catch (Exception e) {
                                      order = new Integer(-1);
                                  }
  
  
                                  try {
                                      Thread.sleep(20L);
                                  } catch (InterruptedException e) {
                                      e.printStackTrace();  //To change body of catch statement use Options | File Templates.
                                  }
                              } while (!(simpleLastMessageNo == (order.intValue() - 1)));
  
                              simpleLastMessageNo++;
                              lastOrderLabel.setText("Last Order:" + simpleLastMessageNo);
                              simplePanelMessageLables[index.intValue() - 1].setText("sent..");
                              //System.out.println(index + "sent..");
  
  
                          }
                      }
                      try {
                          BufferedWriter logFile = new BufferedWriter(new FileWriter("monitor.log", true));
                          logFile.write("<Sequence>");
                          logFile.newLine();
                          logFile.write("  <Identifier>" + IDSOAPElement.getValue() + "</Identifier>");
                          logFile.newLine();
                          logFile.write("  <Message Number>" + messageNoSOAPElement.getValue() + "</Mesage Number>");
                          logFile.newLine();
                          logFile.write("  <Time>" + (new java.util.GregorianCalendar()).getTime().getTime() + "</Time>");
                          logFile.newLine();
                          logFile.write("</Sequence>");
                          logFile.newLine();
                          logFile.close();
                      } catch (IOException e) {
                      }
  
  
                  }
  
                  Socket nextSocket = new Socket("127.0.0.1", 8070);
                  nextOS = nextSocket.getOutputStream();
                  nextOS.write(b);
                  nextIS = nextSocket.getInputStream();
                  os = socket.getOutputStream();
                  while (nextIS.available() <= 0) {
                      try {
                          Thread.sleep(20L);
                      } catch (InterruptedException e) {
                          e.printStackTrace();  //To change body of catch statement use Options | File Templates.
                      }
                  }
  
                  if (nextIS.available() > 0) {
                      byte[] nextByte = new byte[nextIS.available()];
                      nextIS.read(nextByte);
  
                      if (panel != null) {
                          String responceMessage = new String(nextByte);
                          JTextArea textArea = new JTextArea();
                          textArea.setLineWrap(true);
                          textArea.setText(responceMessage);
                          JScrollPane scrollPane = new JScrollPane(textArea);
                          scrollPane.setBounds(10, 275, 550, 205);
                          panel.add(scrollPane);
                          JLabel label = new JLabel("Responce Message:");
                          label.setBounds(10, 250, 200, 20);
                          panel.add(label);
                      }
                      os.write(nextByte);
                      socket.close();
                  }
              } catch (IOException e) {
                  e.printStackTrace();  //To change body of catch statement use Options | File Templates.
              }
  
          }
      }
  
      public static void main(String[] arg) {
          WSRMMonitor mon = new WSRMMonitor();
  
      }
  }